From: Marcin Haba Date: Mon, 10 Jul 2023 13:00:16 +0000 (+0200) Subject: baculum: Add objecttype parameter to object categories endpoint X-Git-Tag: Release-13.0.4~39 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=791f0806c4c0de9dad0a43f74752f8efd7a26960;p=thirdparty%2Fbacula.git baculum: Add objecttype parameter to object categories endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index ed9b0f5fd..80ba20740 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -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; } diff --git a/gui/baculum/protected/API/Pages/API/ObjectCategories.php b/gui/baculum/protected/API/Pages/API/ObjectCategories.php index acaa6ef9c..11c91e91a 100644 --- a/gui/baculum/protected/API/Pages/API/ObjectCategories.php +++ b/gui/baculum/protected/API/Pages/API/ObjectCategories.php @@ -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; diff --git a/gui/baculum/protected/API/openapi_baculum.json b/gui/baculum/protected/API/openapi_baculum.json index 1cdd0fc5a..564061924 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -8609,6 +8609,15 @@ "parameters": [ { "$ref": "#/components/parameters/Limit" + }, + { + "name": "objecttype", + "in": "query", + "required": false, + "description": "Object type, ex. 'm365' or 'PostgreSQL'", + "schema": { + "type": "string" + } } ] } @@ -8960,7 +8969,7 @@ "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" }