3 * Bacula(R) - 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 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 Prado::using('System.Web.UI.ActiveControls.TActivePanel');
24 Prado::using('Application.Portlets.Portlets');
26 class JobRunConfiguration extends Portlets {
28 const DEFAULT_JOB_PRIORITY = 10;
30 public $jobToVerify = array('C', 'O', 'd');
32 public $verifyOptions = array('jobname' => 'Verify by Job Name', 'jobid' => 'Verify by JobId');
34 public function configure($jobname) {
35 $this->JobName->Text = $jobname;
36 $this->Estimation->Text = '';
38 $this->Level->dataSource = $this->Application->getModule('misc')->getJobLevels();
39 $this->Level->dataBind();
41 $this->JobToVerifyOptionsLine->Display = 'None';
42 $this->JobToVerifyJobNameLine->Display = 'None';
43 $this->JobToVerifyJobIdLine->Display = 'None';
44 $this->AccurateLine->Display = 'Dynamic';
45 $this->EstimateLine->Display = 'Dynamic';
47 $verifyValues = array();
49 foreach($this->verifyOptions as $value => $text) {
50 $verifyValues[$value] = Prado::localize($text);
53 $this->JobToVerifyOptions->dataSource = $verifyValues;
54 $this->JobToVerifyOptions->dataBind();
56 $jobTasks = $this->Application->getModule('api')->get(array('jobs', 'tasks'))->output;
58 $jobsAllDirs = array();
59 foreach($jobTasks as $director => $tasks) {
60 $jobsAllDirs = array_merge($jobsAllDirs, $tasks);
63 $this->JobToVerifyJobName->dataSource = array_combine($jobsAllDirs, $jobsAllDirs);
64 $this->JobToVerifyJobName->dataBind();
66 $clients = $this->Application->getModule('api')->get(array('clients'))->output;
67 $clientsList = array();
68 foreach($clients as $client) {
69 $clientsList[$client->clientid] = $client->name;
71 $this->Client->dataSource = $clientsList;
72 $this->Client->dataBind();
74 $filesetsAll = $this->Application->getModule('api')->get(array('filesets'))->output;
75 $filesetsList = array();
76 foreach($filesetsAll as $director => $filesets) {
77 $filesetsList = array_merge($filesets, $filesetsList);
79 $this->FileSet->dataSource = array_combine($filesetsList, $filesetsList);
80 $this->FileSet->dataBind();
82 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
84 foreach($pools as $pool) {
85 $poolList[$pool->poolid] = $pool->name;
87 $this->Pool->dataSource = $poolList;
88 $this->Pool->dataBind();
90 $storages = $this->Application->getModule('api')->get(array('storages'))->output;
91 $storagesList = array();
92 foreach($storages as $storage) {
93 $storagesList[$storage->storageid] = $storage->name;
95 $this->Storage->dataSource = $storagesList;
96 $this->Storage->dataBind();
98 $this->Priority->Text = self::DEFAULT_JOB_PRIORITY;
101 public function run_job($sender, $param) {
102 if($this->PriorityValidator->IsValid === false) {
106 $params['name'] = $this->JobName->Text;
107 $params['level'] = $this->Level->SelectedValue;
108 $params['fileset'] = $this->FileSet->SelectedValue;
109 $params['clientid'] = $this->Client->SelectedValue;
110 $params['storageid'] = $this->Storage->SelectedValue;
111 $params['poolid'] = $this->Pool->SelectedValue;
112 $params['priority'] = $this->Priority->Text;
114 if (in_array($this->Level->SelectedItem->Value, $this->jobToVerify)) {
115 $verifyVals = $this->getVerifyVals();
116 if ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobname']) {
117 $params['verifyjob'] = $this->JobToVerifyJobName->SelectedValue;
118 } elseif ($this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
119 $params['jobid'] = $this->JobToVerifyJobId->Text;
123 $result = $this->Application->getModule('api')->create(array('jobs', 'run'), $params)->output;
124 $this->Estimation->Text = implode(PHP_EOL, $result);
127 public function estimate($sender, $param) {
129 $params['name'] = $this->JobName->Text;
130 $params['level'] = $this->Level->SelectedValue;
131 $params['fileset'] = $this->FileSet->SelectedValue;
132 $params['clientid'] = $this->Client->SelectedValue;
133 $params['accurate'] = (integer)$this->Accurate->Checked;
134 $result = $this->Application->getModule('api')->create(array('jobs', 'estimate'), $params)->output;
135 $this->Estimation->Text = implode(PHP_EOL, $result);
138 public function priorityValidator($sender, $param) {
139 $isValid = preg_match('/^[0-9]+$/', $this->Priority->Text) === 1 && $this->Priority->Text > 0;
140 $param->setIsValid($isValid);
143 public function jobIdToVerifyValidator($sender, $param) {
144 $verifyVals = $this->getVerifyVals();
145 if(in_array($this->Level->SelectedValue, $this->jobToVerify) && $this->JobToVerifyOptions->SelectedItem->Value == $verifyVals['jobid']) {
146 $isValid = preg_match('/^[0-9]+$/',$this->JobToVerifyJobId->Text) === 1 && $this->JobToVerifyJobId->Text > 0;
150 $param->setIsValid($isValid);
154 private function getVerifyVals() {
155 $verifyOpt = array_keys($this->verifyOptions);
156 $verifyVals = array_combine($verifyOpt, $verifyOpt);