]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Class/JobManager.php
701122e7aa350f9513394b3ea1099a83edfa1eae
[bacula/bacula] / gui / baculum / protected / Class / JobManager.php
1 <?php
2 /**
3  * Bacula® - The Network Backup Solution
4  * Baculum - Bacula web interface
5  *
6  * Copyright (C) 2013-2014 Marcin Haba
7  *
8  * The main author of Baculum is Marcin Haba.
9  * The main author of Bacula is Kern Sibbald, with contributions from many
10  * others, a complete list can be found in the file AUTHORS.
11  *
12  * You may use this file and others of this release according to the
13  * license defined in the LICENSE file, which includes the Affero General
14  * Public License, v3.0 ("AGPLv3") and some additional permissions and
15  * terms pursuant to its AGPLv3 Section 7.
16  *
17  * Bacula® is a registered trademark of Kern Sibbald.
18  */
19  
20 class JobManager extends TModule {
21
22         public function getJobs($limit) {
23                 $criteria = new TActiveRecordCriteria;
24                 $order = 'JobId';
25                 $cfg = $this->Application->getModule('configuration');
26                 $appCfg = $cfg->getApplicationConfig();
27                 if($cfg->isPostgreSQLType($appCfg['db']['type'])) {
28                     $order = strtolower($order);
29                 }
30                 $criteria->OrdersBy[$order] = 'desc';
31                 if(is_int($limit) && $limit > 0) {
32                         $criteria->Limit = $limit;
33                 }
34                 return JobRecord::finder()->findAll($criteria);
35         }
36
37         public function getJobById($id) {
38                 return JobRecord::finder()->findByjobid($id);
39         }
40
41         public function getJobByName($name) {
42                 return JobRecord::finder()->findByname($name);
43         }
44
45         public function deleteJobById($id) {
46                 return JobRecord::finder()->deleteByjobid($id);
47         }
48
49         public function getRecentJobids($jobname, $clientid) {
50                 $sql = "name='$jobname' AND clientid='$clientid' AND jobstatus IN ('T', 'W') AND level IN ('F', 'I', 'D') ORDER BY endtime DESC";
51                 $finder = JobRecord::finder();
52                 $jobs = $finder->findAll($sql);
53
54                 $jobids = array();
55                 $waitForFull = false;
56                 if(!is_null($jobs)) {
57                         foreach($jobs as $job) {
58                                 if($job->level == 'F') {
59                                         $jobids[] = $job->jobid;
60                                         break;
61                                 } elseif($job->level == 'D' && $waitForFull === false) {
62                                         $jobids[] = $job->jobid;
63                                         $waitForFull = true;
64                                 } elseif($job->level == 'I' && $waitForFull === false) {
65                                         $jobids[] = $job->jobid;
66                                 }
67                         }
68                 }
69                 return $jobids;
70         }
71 }
72 ?>