]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/protected/Class/VolumeManager.php
baculum: Update copyright dates
[bacula/bacula] / gui / baculum / protected / Class / VolumeManager.php
1 <?php
2 /**
3  * Bacula® - 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 main author of Bacula is Kern Sibbald, with contributions from many
10  * 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  * Bacula® is a registered trademark of Kern Sibbald.
18  */
19  
20 class VolumeManager extends TModule {
21
22
23         public function getVolumes($limit, $withPools = false) {
24                 $criteria = new TActiveRecordCriteria;
25                 $orderPool = 'PoolId';
26                 $orderVolume = 'VolumeName';
27                 $cfg = $this->Application->getModule('configuration');
28                 $appCfg = $cfg->getApplicationConfig();
29                 if($cfg->isPostgreSQLType($appCfg['db']['type'])) {
30                     $orderPool = strtolower($orderPool);
31                     $orderVolume = strtolower($orderVolume);
32                 }
33                 $criteria->OrdersBy[$orderPool] = 'asc';
34                 $criteria->OrdersBy[$orderVolume] = 'asc';
35                 if(is_int($limit) && $limit > 0) {
36                         $criteria->Limit = $limit;
37                 }
38                 $volumes = VolumeRecord::finder()->findAll($criteria);
39                 if($withPools) {
40                         $this->setExtraVariables($volumes);
41                 }
42                 return $volumes;
43         }
44
45         public function getVolumesByPoolId($poolid) {
46                 return VolumeRecord::finder()->findBypoolid($poolid);
47         }
48
49         public function getVolumeByName($volumeName) {
50                 return VolumeRecord::finder()->findByvolumename($volumeName);
51         }
52
53         public function getVolumeById($volumeId) {
54                 return VolumeRecord::finder()->findBymediaid($volumeId);
55         }
56
57         public function setVolume($mediaid, $volumeOptions) {
58                 $volume = $this->getVolumeById($mediaid);
59                 if(property_exists($volumeOptions, 'volstatus')) {
60                         $volume->volstatus = $volumeOptions->volstatus;
61                 }
62                 if(property_exists($volumeOptions, 'poolid')) {
63                         $volume->poolid = $volumeOptions->poolid;
64                 }
65                 if(property_exists($volumeOptions, 'volretention')) {
66                         $volume->volretention = $volumeOptions->volretention;
67                 }
68                 if(property_exists($volumeOptions, 'voluseduration')) {
69                         $volume->voluseduration = $volumeOptions->voluseduration;
70                 }
71                 if(property_exists($volumeOptions, 'maxvoljobs')) {
72                         $volume->maxvoljobs = $volumeOptions->maxvoljobs;
73                 }
74                 if(property_exists($volumeOptions, 'maxvolfiles')) {
75                         $volume->maxvolfiles = $volumeOptions->maxvolfiles;
76                 }
77                 if(property_exists($volumeOptions, 'maxvolbytes')) {
78                         $volume->maxvolbytes = $volumeOptions->maxvolbytes;
79                 }
80                 if(property_exists($volumeOptions, 'slot')) {
81                         $volume->slot = $volumeOptions->slot;
82                 }
83                 if(property_exists($volumeOptions, 'recycle')) {
84                         $volume->recycle = $volumeOptions->recycle;
85                 }
86                 if(property_exists($volumeOptions, 'enabled')) {
87                         $volume->enabled = $volumeOptions->enabled;
88                 }
89                 if(property_exists($volumeOptions, 'inchanger')) {
90                         $volume->inchanger = $volumeOptions->inchanger;
91                 }
92                 return $volume->save();
93         }
94
95         private function setExtraVariables(&$volumes) {
96                 $pools = $this->Application->getModule('pool')->getPools(false);
97                 foreach($volumes as $volume) {
98                         $volstatus = strtolower($volume->volstatus);
99                         $volume->whenexpire = ($volstatus == 'full' || $volstatus == 'used') ? date( 'Y-m-d H:i:s', (strtotime($volume->lastwritten) + $volume->volretention)) : 'no date';
100                         foreach($pools as $pool) {
101                                 if($volume->poolid == $pool->poolid) {
102                                         $volume->pool = $pool;
103                                 }
104                         }
105                 }
106         }
107 }
108 ?>