3 * Bacula® - The Network Backup Solution
4 * Baculum - Bacula web interface
6 * Copyright (C) 2013-2015 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 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
21 Prado::using('Application.Portlets.Portlets');
23 class JobConfiguration extends Portlets {
25 const DEFAULT_JOB_PRIORITY = 10;
28 public $jobToVerify = array('C', 'O', 'd');
30 public $verifyOptions = array('jobname' => 'Verify by Job Name', 'jobid' => 'Verify by JobId');
32 public function configure($jobId) {
33 $jobdata = $this->Application->getModule('api')->get(array('jobs', $jobId))->output;
34 $this->JobName->Text = $jobdata->job;
35 $this->JobID->Text = $jobdata->jobid;
36 $joblog = $this->Application->getModule('api')->get(array('joblog', $jobdata->jobid))->output;
37 $this->Estimation->Text = is_array($joblog) ? implode(PHP_EOL, $joblog) : Prado::localize("Output for selected job is not available yet or you do not have enabled logging job logs to catalog database. For watching job log there is need to add to the job Messages resource next directive: console = all, !skipped, !saved");
39 $this->Level->dataSource = $this->Application->getModule('misc')->getJobLevels();
40 $this->Level->SelectedValue = $jobdata->level;
41 $this->Level->dataBind();
43 $isVerifyOption = in_array($jobdata->level, $this->jobToVerify);
44 $this->JobToVerifyOptionsLine->Display = ($isVerifyOption === true) ? 'Dynamic' : 'None';
45 $this->JobToVerifyJobNameLine->Display = ($isVerifyOption === true) ? 'Dynamic' : 'None';
46 $this->JobToVerifyJobIdLine->Display = 'None';
47 $this->AccurateLine->Display = ($isVerifyOption === true) ? 'None' : 'Dynamic';
48 $this->EstimateLine->Display = ($isVerifyOption === true) ? 'None' : 'Dynamic';
50 $verifyValues = array();
52 foreach($this->verifyOptions as $value => $text) {
53 $verifyValues[$value] = Prado::localize($text);
56 $this->JobToVerifyOptions->dataSource = $verifyValues;
57 $this->JobToVerifyOptions->dataBind();
59 $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
61 $jobsAllDirs = array();
62 foreach($jobTasks as $director => $tasks) {
63 $jobsAllDirs = array_merge($jobsAllDirs, $tasks);
66 $this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
67 $this->JobToVerifyJobName->dataBind();
69 $clients = $this->Application->getModule('api')->get(array('clients'))->output;
70 $clientsList = array();
71 foreach($clients as $client) {
72 $clientsList[$client->clientid] = $client->name;
74 $this->Client->dataSource = $clientsList;
75 $this->Client->SelectedValue = $jobdata->clientid;
76 $this->Client->dataBind();
78 $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
79 $filesetsList = array();
80 foreach($filesetsAll as $director => $filesets) {
81 $filesetsList = array_merge($filesets, $filesetsList);
83 if($jobdata->filesetid != 0) {
84 $selectedFileset = $this->Application->getModule('api')->get(array('filesets', $jobdata->filesetid))->output;
86 $this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
87 $this->FileSet->SelectedValue = @$selectedFileset->fileset;
88 $this->FileSet->dataBind();
90 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
92 foreach($pools as $pool) {
93 $poolList[$pool->poolid] = $pool->name;
95 $this->Pool->dataSource = $poolList;
96 $this->Pool->SelectedValue = $jobdata->poolid;
97 $this->Pool->dataBind();
99 $storages = $this->Application->getModule('api')->get(array('storages'))->output;
100 $storagesList = array();
101 foreach($storages as $storage) {
102 $storagesList[$storage->storageid] = $storage->name;
104 $this->Storage->dataSource = $storagesList;
105 $this->Storage->dataBind();
107 $runningJobStates = $this->Application->getModule('misc')->getRunningJobStates();
109 $this->Priority->Text = ($jobdata->priorjobid == 0) ? self::DEFAULT_JOB_PRIORITY : $jobdata->priorjobid;
110 $this->DeleteButton->Visible = true;
111 $this->CancelButton->Visible = in_array($jobdata->jobstatus, $runningJobStates);
114 public function status($sender, $param) {
115 $joblog = $this->Application->getModule('api')->get(array('joblog', $this->JobID->Text))->output;
116 $this->Estimation->Text = is_array($joblog) ? implode(PHP_EOL, $joblog) : Prado::localize("Output for selected job is not available yet or you do not have enabled logging job logs to catalog database. For watching job log there is need to add to the job Messages resource next directive: console = all, !skipped, !saved");
119 public function delete($sender, $param) {
120 $this->Application->getModule('api')->remove(array('jobs', $this->JobID->Text));
121 $this->DeleteButton->Visible = false;
124 public function cancel($sender, $param) {
125 $this->Application->getModule('api')->set(array('jobs', 'cancel', $this->JobID->Text), array('a' => 'b'));
126 $this->CancelButton->Visible = false;
129 public function run_again($sender, $param) {
130 if($this->PriorityValidator->IsValid === false) {
134 $params['id'] = $this->JobID->Text;
135 $params['level'] = $this->Level->SelectedValue;
136 $params['fileset'] = $this->FileSet->SelectedValue;
137 $params['clientid'] = $this->Client->SelectedValue;
138 $params['storageid'] = $this->Storage->SelectedValue;
139 $params['poolid'] = $this->Pool->SelectedValue;
140 $params['priority'] = $this->Priority->Text;
142 if (in_array($this->Level->SelectedItem->Value, $this->jobToVerify)) {
143 $verifyVals = $this->getVerifyVals();
144 if ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobname']) {
145 $params['verifyjob'] = $this->JobToVerifyJobName->SelectedValue;
146 } elseif ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
147 $params['jobid'] = $this->JobToVerifyJobId->Text;
151 $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output;
152 $this->Estimation->Text = implode(PHP_EOL, $result);
155 public function estimate($sender, $param) {
157 $params['id'] = $this->JobID->Text;
158 $params['level'] = $this->Level->SelectedValue;
159 $params['fileset'] = $this->FileSet->SelectedValue;
160 $params['clientid'] = $this->Client->SelectedValue;
161 $params['accurate'] = (integer)$this->Accurate->Checked;
162 $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output;
163 $this->Estimation->Text = implode(PHP_EOL, $result);
166 public function priorityValidator($sender, $param) {
167 $isValid = preg_match('/^[0-9]+$/',$this->Priority->Text) === 1 && $this->Priority->Text > 0;
168 $param->setIsValid($isValid);
171 public function jobIdToVerifyValidator($sender, $param) {
172 $verifyVals = $this->getVerifyVals();
173 if(in_array($this->Level->SelectedValue, $this->jobToVerify) && $this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
174 $isValid = preg_match('/^[0-9]+$/',$this->JobToVerifyJobId->Text) === 1 && $this->JobToVerifyJobId->Text > 0;
178 $param->setIsValid($isValid);
182 private function getVerifyVals() {
183 $verifyOpt = array_keys($this->verifyOptions);
184 $verifyVals = array_combine($verifyOpt, $verifyOpt);