]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Pages/API/JobEstimate.php
4f18570dd521ed1bbc407899d10cb2022a8a553a
[bacula/bacula] / gui / baculum / protected / Pages / API / JobEstimate.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 JobEstimate 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 : $params->name;
27                 $level = $params->level;
28                 $fileset = $params->fileset;
29                 $clientid = intval($params->clientid);
30                 $client = $this->getModule('client')->getClientById($clientid);
31                 $accurateJob = intval($params->accurate);
32                 $accurate = $accurateJob === 1 ? 'yes' : 'no';
33
34                 if(!is_null($job)) {
35                         $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
36                         if($isValidLevel === true) {
37                                 if(!is_null($fileset)) {
38                                         if(!is_null($client)) {
39                                                 $joblevels  = $this->getModule('misc')->getJobLevels();
40                                                 $estimation = $this->getModule('bconsole')->bconsoleCommand($this->director, array('estimate', 'job="' . $job . '"', 'level="' . $joblevels[$level] . '"', 'fileset="' . $fileset. '"', 'client="' . $client->name . '"', 'accurate="' . $accurate . '"'), $this->user);
41                                                 $this->output = $estimation->output;
42                                                 $this->error = (integer)$estimation->exitcode;
43                                         } else {
44                                                 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
45                                                 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
46                                         }
47                                 } else {
48                                         $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
49                                         $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
50                                 }
51                         } else {
52                                 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
53                                 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
54                         }
55                 } else {
56                         $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
57                         $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;
58                 }
59         }
60 }
61
62 ?>