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 class VolumeManager extends TModule {
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);
33 $criteria->OrdersBy[$orderPool] = 'asc';
34 $criteria->OrdersBy[$orderVolume] = 'asc';
35 if(is_int($limit) && $limit > 0) {
36 $criteria->Limit = $limit;
38 $volumes = VolumeRecord::finder()->findAll($criteria);
40 $this->setExtraVariables($volumes);
45 public function getVolumesByPoolId($poolid) {
46 return VolumeRecord::finder()->findBypoolid($poolid);
49 public function getVolumeByName($volumeName) {
50 return VolumeRecord::finder()->findByvolumename($volumeName);
53 public function getVolumeById($volumeId) {
54 return VolumeRecord::finder()->findBymediaid($volumeId);
57 public function setVolume($mediaid, $volumeOptions) {
58 $volume = $this->getVolumeById($mediaid);
59 if(property_exists($volumeOptions, 'volstatus')) {
60 $volume->volstatus = $volumeOptions->volstatus;
62 if(property_exists($volumeOptions, 'poolid')) {
63 $volume->poolid = $volumeOptions->poolid;
65 if(property_exists($volumeOptions, 'volretention')) {
66 $volume->volretention = $volumeOptions->volretention;
68 if(property_exists($volumeOptions, 'voluseduration')) {
69 $volume->voluseduration = $volumeOptions->voluseduration;
71 if(property_exists($volumeOptions, 'maxvoljobs')) {
72 $volume->maxvoljobs = $volumeOptions->maxvoljobs;
74 if(property_exists($volumeOptions, 'maxvolfiles')) {
75 $volume->maxvolfiles = $volumeOptions->maxvolfiles;
77 if(property_exists($volumeOptions, 'maxvolbytes')) {
78 $volume->maxvolbytes = $volumeOptions->maxvolbytes;
80 if(property_exists($volumeOptions, 'slot')) {
81 $volume->slot = $volumeOptions->slot;
83 if(property_exists($volumeOptions, 'recycle')) {
84 $volume->recycle = $volumeOptions->recycle;
86 if(property_exists($volumeOptions, 'enabled')) {
87 $volume->enabled = $volumeOptions->enabled;
89 if(property_exists($volumeOptions, 'inchanger')) {
90 $volume->inchanger = $volumeOptions->inchanger;
92 return $volume->save();
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;