]> git.sur5r.net Git - bacula/bacula/commitdiff
baculum: Add new volumes required api endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 27 Nov 2017 20:00:50 +0000 (21:00 +0100)
committerKern Sibbald <kern@sibbald.com>
Sat, 9 Dec 2017 11:00:28 +0000 (12:00 +0100)
gui/baculum/protected/API/Class/VolumeManager.php
gui/baculum/protected/API/Pages/API/VolumesRequired.php [new file with mode: 0644]
gui/baculum/protected/API/endpoints.xml

index 4456328279fa9dcb5d4eb6193a80e185a16ab19f..35265beb9776b83129d0634c10f67d75ef8d02d8 100644 (file)
@@ -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 (file)
index 0000000..2716f8c
--- /dev/null
@@ -0,0 +1,33 @@
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum   - Bacula web interface
+ *
+ * Copyright (C) 2013-2017 Kern Sibbald
+ *
+ * The main author of Baculum is Marcin Haba.
+ * The original author of Bacula is Kern Sibbald, with contributions
+ * from many others, a complete list can be found in the file AUTHORS.
+ *
+ * You may use this file and others of this release according to the
+ * license defined in the LICENSE file, which includes the Affero General
+ * Public License, v3.0 ("AGPLv3") and some additional permissions and
+ * terms pursuant to its AGPLv3 Section 7.
+ *
+ * This notice must be preserved when any source code is
+ * conveyed and/or propagated.
+ *
+ * Bacula(R) is a registered trademark of Kern Sibbald.
+ */
+class VolumesRequired extends BaculumAPIServer {
+
+       public function get() {
+               $jobid = $this->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;
+       }
+}
+?>
index 6a9146e75fc1a862d7b30b95bbfec50c99fbe498..81bcfed0edc3c1531e8514e4e96be08ea8d2cfb2 100644 (file)
@@ -40,6 +40,7 @@
        <url ServiceParameter="API.Volume" pattern="api/volumes/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.VolumePrune" pattern="api/volumes/prune/{id}/" parameters.id="\d+" />
        <url ServiceParameter="API.VolumePurge" pattern="api/volumes/purge/{id}/" parameters.id="\d+" />
+       <url ServiceParameter="API.VolumesRequired" pattern="api/volumes/required/{jobid}/{fileid}/" parameters.jobid="\d+" parameters.fileid="\d+" />
        <url ServiceParameter="API.JobsOnVolume" pattern="api/volumes/jobs/{id}/" parameters.id="\d+" />
        <!-- pools endpoints -->
        <url ServiceParameter="API.Pools" pattern="api/pools/" />