]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add objecttype parameter to object categories endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 10 Jul 2023 13:00:16 +0000 (15:00 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 10 Jul 2023 13:00:16 +0000 (15:00 +0200)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/ObjectCategories.php
gui/baculum/protected/API/openapi_baculum.json

index ed9b0f5fd8f615301525f8f8228b91015dfa879e..80ba20740292cb653b997ef1b495283ea0f00c71 100644 (file)
@@ -712,9 +712,8 @@ LEFT JOIN Client USING (ClientId) '
                        FROM Object
                        ORDER BY ObjectType';
                $statement = Database::runQuery($sql);
-               $result = $statement->fetchAll(\PDO::FETCH_GROUP);
-               $values = array_keys($result);
-               return $values;
+               $result = $statement->fetchAll(PDO::FETCH_COLUMN);
+               return $result;
        }
 
        /**
@@ -738,18 +737,18 @@ LEFT JOIN Client USING (ClientId) '
                        ' . $where['where'] . ' 
                        ORDER BY ObjectName ' . $limit;
                $statement = Database::runQuery($sql, $where['params']);
-               $result = $statement->fetchAll(\PDO::FETCH_GROUP);
-               $values = array_keys($result);
-               return $values;
+               $result = $statement->fetchAll(PDO::FETCH_COLUMN);
+               return $result;
        }
 
        /**
         * Get existing object categories.
         *
+        * @param array $criteria SQL criteria in nested array format (@see  Databaes::getWhere)
         * @param integer $limit_val maximum number of elements to return
         * @return array object names
         */
-       public function getObjectCategories($limit_val = null) {
+       public function getObjectCategories($criteria = [], $limit_val = null) {
                $limit = '';
                if(is_int($limit_val) && $limit_val > 0) {
                        $limit = sprintf(
@@ -757,10 +756,12 @@ LEFT JOIN Client USING (ClientId) '
                                $limit_val
                        );
                }
+               $where = Database::getWhere($criteria);
                $sql = 'SELECT DISTINCT ObjectCategory as objectcategory
                        FROM Object
+                       ' . $where['where'] . ' 
                        ORDER BY ObjectCategory ' . $limit;
-               $statement = Database::runQuery($sql);
+               $statement = Database::runQuery($sql, $where['params']);
                $result = $statement->fetchAll(PDO::FETCH_COLUMN);
                return $result;
        }
index acaa6ef9cd37b2bc845fbba450f944b6496f13e8..11c91e91a10f8ddb625d8bf9c9939beff039196d 100644 (file)
@@ -33,9 +33,20 @@ use Baculum\Common\Modules\Errors\ObjectError;
 class ObjectCategories extends BaculumAPIServer {
 
        public function get() {
+               $misc = $this->getModule('misc');
                $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : null;
+               $objecttype = $this->Request->contains('objecttype') && $misc->isValidName($this->Request['objecttype']) ? $this->Request['objecttype'] : null;
+
+               $params = [];
+               if (!empty($objecttype)) {
+                       $params['Object.ObjectType'] = [];
+                       $params['Object.ObjectType'][] = [
+                               'vals' => $objecttype
+                       ];
+               }
 
                $this->output = $this->getModule('object')->getObjectCategories(
+                       $params,
                        $limit
                );
                $this->error = ObjectError::ERROR_NO_ERRORS;
index 1cdd0fc5a15b903a3fdc0ea7fd3e6d9d00fd6640..5640619240392118ce183c91ef2ddf7ada3bfaeb 100644 (file)
                                "parameters": [
                                        {
                                                "$ref": "#/components/parameters/Limit"
+                                       },
+                                       {
+                                               "name": "objecttype",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "Object type, ex. 'm365' or 'PostgreSQL'",
+                                               "schema": {
+                                                       "type": "string"
+                                               }
                                        }
                                ]
                        }
                                                "name": "order_by",
                                                "in": "query",
                                                "required": false,
-                                               "description": "Sort by selected object property (default endtime). There can be one from the following properties: objectname, client, jobstatus, endtime.",
+                                               "description": "Sort by selected object property (default endtime). There can be one from the following properties: objectname, objectcategory, client, fileset, jobstatus, endtime.",
                                                "schema": {
                                                        "type": "string"
                                                }