]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add object categories endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 29 Jun 2023 14:25:47 +0000 (16:25 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 3 Jul 2023 08:46:58 +0000 (10:46 +0200)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/ObjectCategories.php [new file with mode: 0644]
gui/baculum/protected/API/Pages/API/endpoints.xml
gui/baculum/protected/API/openapi_baculum.json

index 1b0146fb028d86eea4b860a9be30c5d2c757c5c0..9b7b884ffbd885e7d672f2d4fa9a33d15a60d367 100644 (file)
@@ -478,23 +478,6 @@ LEFT JOIN Client USING (ClientId) '
                return $result;
        }
 
-       /**
-        * Get object categories based on criterias.
-        *
-        * @param array $criteria SQL criteria to get job list
-        * @return array category list or empty list if no category found
-        */
-       public function getObjectCategories($criteria = []) {
-               $where = Database::getWhere($criteria);
-
-               $sql = 'SELECT DISTINCT ObjectCategory as objectcategory
-FROM Object 
-JOIN Job USING (JobId) '
-. $where['where'];
-               $statement = Database::runQuery($sql, $where['params']);
-               return $statement->fetchAll(\PDO::FETCH_ASSOC);
-       }
-
        public function getObjectById($objectid) {
                $params = [
                        'Object.ObjectId' => [[
@@ -754,4 +737,26 @@ JOIN Job USING (JobId) '
                $values = array_keys($result);
                return $values;
        }
+
+       /**
+        * Get existing object categories.
+        *
+        * @param integer $limit_val maximum number of elements to return
+        * @return array object names
+        */
+       public function getObjectCategories($limit_val = null) {
+               $limit = '';
+               if(is_int($limit_val) && $limit_val > 0) {
+                       $limit = sprintf(
+                               ' LIMIT %d',
+                               $limit_val
+                       );
+               }
+               $sql = 'SELECT DISTINCT ObjectCategory as objectcategory
+                       FROM Object
+                       ORDER BY ObjectCategory ' . $limit;
+               $statement = Database::runQuery($sql);
+               $result = $statement->fetchAll(PDO::FETCH_COLUMN);
+               return $result;
+       }
 }
diff --git a/gui/baculum/protected/API/Pages/API/ObjectCategories.php b/gui/baculum/protected/API/Pages/API/ObjectCategories.php
new file mode 100644 (file)
index 0000000..acaa6ef
--- /dev/null
@@ -0,0 +1,43 @@
+<?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\ObjectError;
+
+/**
+ * Available object categories endpoint.
+ *
+ * @author Marcin Haba <marcin.haba@bacula.pl>
+ * @category API
+ * @package Baculum API
+ */
+class ObjectCategories extends BaculumAPIServer {
+
+       public function get() {
+               $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null;
+
+               $this->output = $this->getModule('object')->getObjectCategories(
+                       $limit
+               );
+               $this->error = ObjectError::ERROR_NO_ERRORS;
+       }
+}
index a1dabdde054535dc5316a176a51c1d831a355c9a..e1e4248bdd13152cd4402337d2aab2db46b46e0f 100644 (file)
        <url ServiceParameter="ObjectVersions" pattern="api/v2/objects/versions/{uuid}" parameters.uuid="[a-zA-Z0-9:.\-_ ]+" />
        <url ServiceParameter="ObjectTypes" pattern="api/v2/objects/types/" />
        <url ServiceParameter="ObjectNames" pattern="api/v2/objects/names/" />
+       <url ServiceParameter="ObjectCategories" pattern="api/v2/objects/categories/" />
        <url ServiceParameter="ObjectStatsCategorySum" pattern="api/v2/objects/stats/category-sum/" />
        <url ServiceParameter="ObjectStatsCategoryStatus" pattern="api/v2/objects/stats/category-status/" />
        <url ServiceParameter="ObjectStatsSizeSum" pattern="api/v2/objects/stats/size-sum/" />
index d3ed43572aad046691253e672c91146bd14650cb..7832d679fd4686dc3561ae23028768b1f4482fbc 100644 (file)
                                ]
                        }
                },
+               "/api/v2/objects/categories": {
+                       "get": {
+                               "tags": ["objects"],
+                               "summary": "Object categories",
+                               "description": "Get object categories.",
+                               "responses": {
+                                       "200": {
+                                               "description": "Object categories.",
+                                               "content": {
+                                                       "application/json": {
+                                                               "schema": {
+                                                                       "type": "object",
+                                                                       "properties": {
+                                                                               "output": {
+                                                                                       "type": "array",
+                                                                                       "items": {
+                                                                                               "type": "string",
+                                                                                               "description": "Object category"
+                                                                                       }
+                                                                               },
+                                                                               "error": {
+                                                                                       "type": "integer",
+                                                                                       "description": "Error code",
+                                                                                       "enum": [0, 1, 2, 3, 6, 7, 1000]
+                                                                               }
+                                                                       }
+                                                               }
+                                                       }
+                                               }
+                                       }
+                               },
+                               "parameters": [
+                                       {
+                                               "$ref": "#/components/parameters/Limit"
+                                       }
+                               ]
+                       }
+               },
                "/api/v2/objects/types": {
                        "get": {
                                "tags": ["objects"],