3 * Bacula(R) - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2016 Kern Sibbald
8 * The main author of Baculum is Marcin Haba.
9 * The original author of Bacula is Kern Sibbald, with contributions
10 * from many others, a complete list can be found in the file AUTHORS.
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.
17 * This notice must be preserved when any source code is
18 * conveyed and/or propagated.
20 * Bacula(R) is a registered trademark of Kern Sibbald.
23 class JobRun extends BaculumAPI {
25 public function get() {}
27 public function create($params) {
28 $jobid = property_exists($params, 'id') ? intval($params->id) : 0;
29 $job = $jobid > 0 ? $this->getModule('job')->getJobById($jobid)->name : (property_exists($params, 'name') ? $params->name : null);
30 $level = $params->level;
31 $fileset = property_exists($params, 'fileset') ? $params->fileset : null;
32 $clientid = property_exists($params, 'clientid') ? intval($params->clientid) : null;
33 $client = $this->getModule('client')->getClientById($clientid);
34 $storageid = property_exists($params, 'storageid') ? intval($params->storageid) : null;
35 $storage = $this->getModule('storage')->getStorageById($storageid);
36 $poolid = property_exists($params, 'poolid') ? intval($params->poolid) : null;
37 $pool = $this->getModule('pool')->getPoolById($poolid);
38 $priority = property_exists($params, 'priority') ? intval($params->priority) : 10; // default priority is set to 10
39 $jobid = property_exists($params, 'jobid') ? 'jobid="' . intval($params->jobid) . '"' : '';
40 // @TODO: Move Job name pattern in more appropriate place
41 $verifyjob = property_exists($params, 'verifyjob') && preg_match('/^[\w\d\.\-\s]+$/', $params->verifyjob) === 1 ? 'verifyjob="' . ($params->verifyjob) . '"' : '';
44 $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
45 if($isValidLevel === true) {
46 if(!is_null($fileset)) {
47 if(!is_null($client)) {
48 if(!is_null($storage)) {
50 $joblevels = $this->getModule('misc')->getJobLevels();
54 'level="' . $joblevels[$level] . '"',
55 'fileset="' . $fileset . '"',
56 'client="' . $client->name . '"',
57 'storage="' . $storage->name . '"',
58 'pool="' . $pool->name . '"' ,
59 'priority="' . $priority . '"',
64 $run = $this->getModule('bconsole')->bconsoleCommand($this->director, $command, $this->user);
65 $this->output = $run->output;
66 $this->error = (integer)$run->exitcode;
68 $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
69 $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
72 $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
73 $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
76 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
77 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
80 $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
81 $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
84 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
85 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
88 $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
89 $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;