From: Marcin Haba Date: Mon, 27 Nov 2017 20:00:50 +0000 (+0100) Subject: baculum: Add new volumes required api endpoint X-Git-Tag: Release-9.0.7~29 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=257270171c6060edfd493ef4c7cb95716aa0fc1e;p=bacula%2Fbacula baculum: Add new volumes required api endpoint --- diff --git a/gui/baculum/protected/API/Class/VolumeManager.php b/gui/baculum/protected/API/Class/VolumeManager.php index 4456328279..35265beb97 100644 --- a/gui/baculum/protected/API/Class/VolumeManager.php +++ b/gui/baculum/protected/API/Class/VolumeManager.php @@ -3,7 +3,7 @@ * Bacula(R) - The Network Backup Solution * Baculum - Bacula web interface * - * Copyright (C) 2013-2016 Kern Sibbald + * Copyright (C) 2013-2017 Kern Sibbald * * The main author of Baculum is Marcin Haba. * The original author of Bacula is Kern Sibbald, with contributions @@ -71,5 +71,41 @@ class VolumeManager extends APIModule { } } } + + /** + * Get volumes for specific jobid and fileid. + * + * @param integer $jobid job identifier + * @param integer $fileid file identifier + * @return array volumes list + */ + public function getVolumesForJob($jobid, $fileid) { + $connection = VolumeRecord::finder()->getDbConnection(); + $connection->setActive(true); + $sql = sprintf('SELECT first_index, last_index, VolumeName AS volname, InChanger AS inchanger FROM ( + SELECT VolumeName, InChanger, MIN(FirstIndex) as first_index, MAX(LastIndex) as last_index + FROM JobMedia JOIN Media ON (JobMedia.MediaId = Media.MediaId) + WHERE JobId = %d GROUP BY (VolumeName, InChanger) + ) AS gv, File + WHERE FileIndex >= first_index + AND FileIndex <= last_index + AND File.FileId = %d', $jobid, $fileid); + $pdo = $connection->getPdoInstance(); + $result = $pdo->query($sql); + $ret = $result->fetchAll(); + $pdo = null; + $volumes = array(); + if (is_array($ret)) { + for ($i = 0; $i < count($ret); $i++) { + $volumes[] = array( + 'first_index' => $ret[$i]['first_index'], + 'last_index' => $ret[$i]['last_index'], + 'volume' => $ret[$i]['volname'], + 'inchanger' => $ret[$i]['inchanger'] + ); + } + } + return $volumes; + } } ?> diff --git a/gui/baculum/protected/API/Pages/API/VolumesRequired.php b/gui/baculum/protected/API/Pages/API/VolumesRequired.php new file mode 100644 index 0000000000..2716f8cb53 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/VolumesRequired.php @@ -0,0 +1,33 @@ +Request->contains('jobid') ? intval($this->Request['jobid']) : 0; + $fileid = $this->Request->contains('fileid') ? intval($this->Request['fileid']) : 0; + $volumes = $this->getModule('volume')->getVolumesForJob($jobid, $fileid); + $this->output = $volumes; + $this->error = VolumeError::ERROR_NO_ERRORS; + } +} +?> diff --git a/gui/baculum/protected/API/endpoints.xml b/gui/baculum/protected/API/endpoints.xml index 6a9146e75f..81bcfed0ed 100644 --- a/gui/baculum/protected/API/endpoints.xml +++ b/gui/baculum/protected/API/endpoints.xml @@ -40,6 +40,7 @@ +