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 JobRunConfiguration extends Portlets {
25 const DEFAULT_JOB_PRIORITY = 10;
27 public $jobToVerify = array('C', 'O', 'd');
29 public $verifyOptions = array('jobname' => 'Verify by Job Name', 'jobid' => 'Verify by JobId');
31 public function configure($jobname) {
32 $this->JobName->Text = $jobname;
33 $this->Estimation->Text = '';
35 $this->Level->dataSource = $this->Application->getModule('misc')->getJobLevels();
36 $this->Level->dataBind();
38 $this->JobToVerifyOptionsLine->Display = 'None';
39 $this->JobToVerifyJobNameLine->Display = 'None';
40 $this->JobToVerifyJobIdLine->Display = 'None';
41 $this->AccurateLine->Display = 'Dynamic';
42 $this->EstimateLine->Display = 'Dynamic';
44 $verifyValues = array();
46 foreach($this->verifyOptions as $value => $text) {
47 $verifyValues[$value] = Prado::localize($text);
50 $this->JobToVerifyOptions->dataSource = $verifyValues;
51 $this->JobToVerifyOptions->dataBind();
53 $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
55 $jobsAllDirs = array();
56 foreach($jobTasks as $director => $tasks) {
57 $jobsAllDirs = array_merge($jobsAllDirs, $tasks);
60 $this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
61 $this->JobToVerifyJobName->dataBind();
63 $clients = $this->Application->getModule('api')->get(array('clients'))->output;
64 $clientsList = array();
65 foreach($clients as $client) {
66 $clientsList[$client->clientid] = $client->name;
68 $this->Client->dataSource = $clientsList;
69 $this->Client->dataBind();
71 $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
72 $filesetsList = array();
73 foreach($filesetsAll as $director => $filesets) {
74 $filesetsList = array_merge($filesets, $filesetsList);
76 $this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
77 $this->FileSet->dataBind();
79 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
81 foreach($pools as $pool) {
82 $poolList[$pool->poolid] = $pool->name;
84 $this->Pool->dataSource = $poolList;
85 $this->Pool->dataBind();
87 $storages = $this->Application->getModule('api')->get(array('storages'))->output;
88 $storagesList = array();
89 foreach($storages as $storage) {
90 $storagesList[$storage->storageid] = $storage->name;
92 $this->Storage->dataSource = $storagesList;
93 $this->Storage->dataBind();
95 $this->Priority->Text = self::DEFAULT_JOB_PRIORITY;
98 public function run_job($sender, $param) {
99 if($this->PriorityValidator->IsValid === false) {
103 $params['name'] = $this->JobName->Text;
104 $params['level'] = $this->Level->SelectedValue;
105 $params['fileset'] = $this->FileSet->SelectedValue;
106 $params['clientid'] = $this->Client->SelectedValue;
107 $params['storageid'] = $this->Storage->SelectedValue;
108 $params['poolid'] = $this->Pool->SelectedValue;
109 $params['priority'] = $this->Priority->Text;
111 if (in_array($this->Level->SelectedItem->Value, $this->jobToVerify)) {
112 $verifyVals = $this->getVerifyVals();
113 if ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobname']) {
114 $params['verifyjob'] = $this->JobToVerifyJobName->SelectedValue;
115 } elseif ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
116 $params['jobid'] = $this->JobToVerifyJobId->Text;
120 $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output;
121 $this->Estimation->Text = implode(PHP_EOL, $result);
124 public function estimate($sender, $param) {
126 $params['name'] = $this->JobName->Text;
127 $params['level'] = $this->Level->SelectedValue;
128 $params['fileset'] = $this->FileSet->SelectedValue;
129 $params['clientid'] = $this->Client->SelectedValue;
130 $params['accurate'] = (integer)$this->Accurate->Checked;
131 $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output;
132 $this->Estimation->Text = implode(PHP_EOL, $result);
135 public function priorityValidator($sender, $param) {
136 $isValid = preg_match('/^[0-9]+$/', $this->Priority->Text) === 1 && $this->Priority->Text > 0;
137 $param->setIsValid($isValid);
140 public function jobIdToVerifyValidator($sender, $param) {
141 $verifyVals = $this->getVerifyVals();
142 if(in_array($this->Level->SelectedValue, $this->jobToVerify) && $this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
143 $isValid = preg_match('/^[0-9]+$/',$this->JobToVerifyJobId->Text) === 1 && $this->JobToVerifyJobId->Text > 0;
147 $param->setIsValid($isValid);
151 private function getVerifyVals() {
152 $verifyOpt = array_keys($this->verifyOptions);
153 $verifyVals = array_combine($verifyOpt, $verifyOpt);