*/
public function getVolumesKeys($criteria = array(), $limit_val = 0) {
$volumes = [];
- $vols = $this->getVolumes($criteria, $limit_val);
+ $vols = $this->getVolumes($criteria, [], $limit_val);
for ($i = 0; $i < count($vols); $i++) {
$volumes[$vols[$i]->volumename] = $vols[$i];
}
return $volumes;
}
+
+ /**
+ * Get volumes names.
+ *
+ * @param integer $limit_val limit results value
+ * @return array volume name list
+ */
+ public function getVolumeNames($limit_val = null) {
+ $limit = '';
+ if(is_int($limit_val) && $limit_val > 0) {
+ $limit = sprintf(
+ ' LIMIT %d',
+ $limit_val
+ );
+ }
+ $sql = 'SELECT VolumeName as volumename
+ FROM Media
+ ORDER BY VolumeName ' . $limit;
+ $statement = Database::runQuery($sql);
+ $result = $statement->fetchAll(\PDO::FETCH_GROUP);
+ $volumes = array_keys($result);
+ return $volumes;
+ }
}
?>
--- /dev/null
+<?php
+/*
+ * Bacula(R) - The Network Backup Solution
+ * Baculum - Bacula web interface
+ *
+ * Copyright (C) 2013-2023 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.
+ */
+
+use Baculum\API\Modules\BaculumAPIServer;
+use Baculum\Common\Modules\Errors\VolumeError;
+
+/**
+ * Volume names endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class VolumeNames extends BaculumAPIServer {
+
+ public function get() {
+ $misc = $this->getModule('misc');
+ $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
+ $volumes = $this->getModule('volume')->getVolumeNames($limit);
+ $this->output = $volumes;
+ $this->error = VolumeError::ERROR_NO_ERRORS;
+ }
+}
<url ServiceParameter="VolumeLabelBarcodes" pattern="api/v2/volumes/label/barcodes/" />
<url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/" />
<url ServiceParameter="SlotsUpdate" pattern="api/v2/volumes/update/{barcodes}/" parameters.barcodes="barcodes" />
+ <url ServiceParameter="VolumeNames" pattern="api/v2/volumes/names/" />
<!-- pools endpoints -->
<url ServiceParameter="Pools" pattern="api/v2/pools/" />
<url ServiceParameter="Pool" pattern="api/v2/pools/{id}/" parameters.id="\d+" />
]
}
},
+ "/api/v2/volumes/names": {
+ "get": {
+ "tags": ["volumes"],
+ "summary": "Volume names",
+ "description": "Get volume names.",
+ "responses": {
+ "200": {
+ "description": "Volume names.",
+ "content": {
+ "application/json": {
+ "schema": {
+ "type": "object",
+ "properties": {
+ "output": {
+ "type": "array",
+ "items": {
+ "type": "string",
+ "description": "Volume name"
+ }
+ },
+ "error": {
+ "type": "integer",
+ "description": "Error code",
+ "enum": [0, 1, 2, 3, 6, 7, 1000]
+ }
+ }
+ }
+ }
+ }
+ }
+ },
+ "parameters": [
+ {
+ "$ref": "#/components/parameters/Limit"
+ }
+ ]
+ }
+ },
"/api/v2/filesets": {
"get": {
"tags": ["filesets"],