3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2014 Marcin Haba
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.
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 * Bacula® is a registered trademark of Kern Sibbald.
20 class JobRun extends BaculumAPI {
22 public function get() {}
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 $jobid = property_exists($params, 'jobid') ? 'jobid="' . intval($params->jobid) . '"' : '';
37 // @TODO: Move Job name pattern in more appropriate place
38 $verifyjob = property_exists($params, 'verifyjob') && preg_match('/^[\w\d\.\-\s]+$/', $params->verifyjob) === 1 ? 'verifyjob="' . ($params->verifyjob) . '"' : '';
41 $isValidLevel = $this->getModule('misc')->isValidJobLevel($params->level);
42 if($isValidLevel === true) {
43 if(!is_null($fileset)) {
44 if(!is_null($client)) {
45 if(!is_null($storage)) {
47 $joblevels = $this->getModule('misc')->getJobLevels();
48 $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 . '"', $jobid , $verifyjob, 'yes'), $this->user);
49 $this->output = $run->output;
50 $this->error = (integer)$run->exitcode;
52 $this->output = JobError::MSG_ERROR_POOLID_DOES_NOT_EXISTS;
53 $this->error = JobError::ERROR_POOLID_DOES_NOT_EXISTS;
56 $this->output = JobError::MSG_ERROR_STORAGEID_DOES_NOT_EXISTS;
57 $this->error = JobError::ERROR_STORAGEID_DOES_NOT_EXISTS;
60 $this->output = JobError::MSG_ERROR_CLIENTID_DOES_NOT_EXISTS;
61 $this->error = JobError::ERROR_CLIENTID_DOES_NOT_EXISTS;
64 $this->output = JobError::MSG_ERROR_FILESETID_DOES_NOT_EXISTS;
65 $this->error = JobError::ERROR_FILESETID_DOES_NOT_EXISTS;
68 $this->output = JobError::MSG_ERROR_INVALID_JOBLEVEL;
69 $this->error = JobError::ERROR_INVALID_JOBLEVEL;
72 $this->output = JobError::MSG_ERROR_JOB_DOES_NOT_EXISTS;
73 $this->error = JobError::ERROR_JOB_DOES_NOT_EXISTS;