]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Portlets/VolumeConfiguration.php
Add more debug to recycle-test
[bacula/bacula] / gui / baculum / protected / Portlets / VolumeConfiguration.php
1 <?php
2 /*
3  * Bacula(R) - The Network Backup Solution
4  * Baculum   - Bacula web interface
5  *
6  * Copyright (C) 2013-2015 Marcin Haba
7  *
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.
11  *
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.
16  *
17  * This notice must be preserved when any source code is
18  * conveyed and/or propagated.
19  *
20  * Bacula(R) is a registered trademark of Kern Sibbald.
21  */
22
23 Prado::using('System.Web.UI.ActiveControls.TActiveDropDownList');
24 Prado::using('System.Web.UI.ActiveControls.TActiveLabel');
25 Prado::using('System.Web.UI.ActiveControls.TActiveTextBox');
26 Prado::using('System.Web.UI.ActiveControls.TActiveCheckBox');
27 Prado::using('System.Web.UI.ActiveControls.TCallback');
28 Prado::using('Application.Portlets.Portlets');
29
30 class VolumeConfiguration extends Portlets {
31
32         private $volumeStatesByDirectorOnly = array('Recycle', 'Purged', 'Error', 'Busy');
33
34         private $volumeStatesForSet = array('Append', 'Archive', 'Disabled', 'Full', 'Used', 'Cleaning', 'Read-Only');
35
36         public function configure($mediaId) {
37                 $voldata = $this->Application->getModule('api')->get(array('volumes', $mediaId))->output;
38                 $this->VolumeID->Text = $voldata->mediaid;
39                 $this->VolumeName->Text = $voldata->volumename;
40                 $volstates = $this->getVolumeStates(true);
41                 if (!in_array($voldata->volstatus, $volstates)) {
42                         array_push($volstates, $voldata->volstatus);
43                 }
44                 $volstatesSelect = array();
45                 for($i = 0; $i < count($volstates); $i++) {
46                         $volstatesSelect[$volstates[$i]] = $volstates[$i];
47                 }
48                 $this->VolumeStatus->DataSource = $volstatesSelect;
49                 $this->VolumeStatus->SelectedValue = $voldata->volstatus;
50                 $this->VolumeStatus->dataBind();
51                 $this->RetentionPeriod->Text = intval($voldata->volretention / 3600); // conversion to hours
52                 $this->UseDuration->Text = intval($voldata->voluseduration / 3600);  // conversion to hours
53                 $this->MaxVolJobs->Text = $voldata->maxvoljobs;
54                 $this->MaxVolFiles->Text = $voldata->maxvolfiles;
55                 $this->MaxVolBytes->Text = $voldata->maxvolbytes;
56                 $this->Slot->Text = $voldata->slot;
57                 $this->Recycle->Checked = ($voldata->recycle == 1);
58                 $this->Enabled->Checked = ($voldata->enabled == 1);
59                 $this->InChanger->Checked = ($voldata->inchanger == 1);
60                 $pools = $this->Application->getModule('api')->get(array('pools'))->output;
61                 $poolList = array();
62                 foreach($pools as $pool) {
63                         $poolList[$pool->poolid] = $pool->name;
64                 }
65                 $this->Pool->dataSource = $poolList;
66                 $this->Pool->SelectedValue = $voldata->poolid;
67                 $this->Pool->dataBind();
68         }
69
70         public function prune($sender, $param) {
71                 $this->Application->getModule('api')->get(array('volumes', 'prune', $this->VolumeID->Text));
72         }
73
74         public function purge($sender, $param) {
75                 $this->Application->getModule('api')->get(array('volumes', 'purge', $this->VolumeID->Text));
76         }
77
78         public function apply($sender, $param) {
79                 $isInvalid = $this->RetentionPeriodValidator->IsValid === false || $this->UseDurationValidator->IsValid === false || $this->MaxVolJobsValidator->IsValid === false || $this->MaxVolFilesValidator->IsValid === false || $this->MaxVolBytesValidator->IsValid === false || $this->SlotValidator->IsValid === false;
80                 if($isInvalid) {
81                         return false;
82                 }
83                 $voldata = array();
84                 $voldata['mediaid'] = $this->VolumeID->Text;
85                 $voldata['volstatus'] = $this->VolumeStatus->SelectedValue;
86                 $voldata['poolid'] = $this->Pool->SelectedValue;
87                 $voldata['volretention'] = $this->RetentionPeriod->Text * 3600; // conversion to seconds
88                 $voldata['voluseduration'] = $this->UseDuration->Text * 3600;  // conversion to seconds
89                 $voldata['maxvoljobs'] = $this->MaxVolJobs->Text;
90                 $voldata['maxvolfiles'] = $this->MaxVolFiles->Text;
91                 $voldata['maxvolbytes'] = $this->MaxVolBytes->Text;
92                 $voldata['slot'] = $this->Slot->Text;
93                 $voldata['recycle'] = (integer)$this->Recycle->Checked;
94                 $voldata['enabled'] = (integer)$this->Enabled->Checked;
95                 $voldata['inchanger'] = (integer)$this->InChanger->Checked;
96                 $this->Application->getModule('api')->set(array('volumes', $voldata['mediaid']), $voldata);
97         }
98
99         public function getVolumeStates($forSetOnly = false) {
100                 $states = ($forSetOnly === true ) ? $this->volumeStatesForSet : array_merge($this->volumeStatesByDirectorOnly, $this->volumeStatesForSet);
101                 return $states;
102         }
103
104         public function retentionPeriodValidator($sender, $param) {
105                 $isValid = preg_match('/^\d+$/', $this->RetentionPeriod->Text) && $this->RetentionPeriod->Text >= 0;
106                 $param->setIsValid($isValid);
107         }
108
109         public function useDurationValidator($sender, $param) {
110                 $isValid = preg_match('/^\d+$/', $this->UseDuration->Text) && $this->UseDuration->Text >= 0;
111                 $param->setIsValid($isValid);
112         }
113
114         public function maxVolJobsValidator($sender, $param) {
115                 $isValid = preg_match('/^\d+$/', $this->MaxVolJobs->Text) && $this->MaxVolJobs->Text >= 0;
116                 $param->setIsValid($isValid);
117         }
118
119         public function maxVolFilesValidator($sender, $param) {
120                 $isValid = preg_match('/^\d+$/', $this->MaxVolFiles->Text) && $this->MaxVolFiles->Text >= 0;
121                 $param->setIsValid($isValid);
122         }
123
124         public function maxVolBytesValidator($sender, $param) {
125                 $isValid = preg_match('/^\d+$/', $this->MaxVolBytes->Text) && $this->MaxVolBytes->Text >= 0;
126                 $param->setIsValid($isValid);
127         }
128
129         public function slotValidator($sender, $param) {
130                 $isValid = preg_match('/^\d+$/', $this->Slot->Text) && $this->Slot->Text >= 0;
131                 $param->setIsValid($isValid);
132         }
133 }
134 ?>