]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/API/JobRun.php
Add Baculum
[bacula/bacula] / gui / baculum / protected / Pages / API / JobRun.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 JobRun extends BaculumAPI {
21
22         public function get() {}
23
24         public function create($params) {
25                 $jobid = property_exists($params, 'id') ? intval($params->id) : 0;
26                 $job = $jobid > 0 ? $this->getModule('job')->getJobById($jobid)->name : (property_exists($params, 'name') ? $params->name : null);
27                 $level = $params->level;
28                 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
29                 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
30                 $client = $this->getModule('client')->getClientById($clientid);
31                 $storageid = property_exists($params, 'storageid') ? intval($params->storageid) : null;
32                 $storage = $this->getModule('storage')->getStorageById($storageid);
33                 $poolid = property_exists($params, 'poolid') ? intval($params->poolid) : null;
34                 $pool = $this->getModule('pool')->getPoolById($poolid);
35                 $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
36                 
37                 if(!is_null($job)) {
38                         $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
39                         if($isValidLevel === true) {
40                                 if(!is_null($fileset)) {
41                                         if(!is_null($client)) {
42                                                 if(!is_null($storage)) {
43                                                         if(!is_null($pool)) {
44                                                                 $joblevels  = $this->getModule('misc')->getJobLevels();
45                                                                 $run = $this->getModule('bconsole')->bconsoleCommand($this->director, array('run', 'job="' . $job . '"', 'level="' . $joblevels[$level] . '"', 'fileset="' . $fileset . '"', 'client="' . $client->name . '"', 'storage="' . $storage->name . '"', 'pool="' . $pool->name . '"' , 'priority="' . $priority . '"', 'yes'));
46                                                                 $this->output = $run->output;
47                                                                 $this->error = (integer)$run->exitcode;
48                                                         } else {
49                                                                 $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
50                                                                 $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
51                                                         }
52                                                 } else {
53                                                         $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
54                                                         $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
55                                                 }
56                                         } else {
57                                                 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
58                                                 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
59                                         }
60                                 } else {
61                                         $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
62                                         $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
63                                 }
64                         } else {
65                                 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
66                                 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
67                         }
68                 } else {
69                         $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
70                         $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
71                 }
72         }
73 }
74
75 ?>