From: Marcin Haba Date: Mon, 5 Jun 2023 09:48:02 +0000 (+0200) Subject: baculum: Improve using unique_objects parameter in object endpoint X-Git-Tag: Release-13.0.4~74 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=73eb02501fd76f339096567b213a542aa9a09df6;p=thirdparty%2Fbacula.git baculum: Improve using unique_objects parameter in object endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index 12e27bac3..b97f0b1e1 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -60,7 +60,6 @@ class ObjectManager extends APIModule */ const OBJECT_RESULT_MODE_NORMAL = 'normal'; const OBJECT_RESULT_MODE_OVERVIEW = 'overview'; - const OBJECT_RESULT_MODE_OVERVIEW_UNIQUE = 'overview_unique'; /** * Object result record view. @@ -74,7 +73,8 @@ class ObjectManager extends APIModule /** * Get objects. * - * @param array $criteria criteria in nested array format (@see Databaes::getWhere) + * @param array $criteria SQL criteria in nested array format (@see Databaes::getWhere) + * @param array $opts object options * @param integer $limit_val maximum number of elements to return * @param integer $offset_val query offset number * @param string $sort_col column to sort @@ -84,7 +84,7 @@ class ObjectManager extends APIModule * @param string $view job records view (basic, full) * @return array object list */ - public function getObjects($criteria = array(), $limit_val = null, $offset_val = 0, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0, $group_offset = 0, $view = self::OBJ_RESULT_VIEW_FULL, $mode = self::OBJECT_RESULT_MODE_NORMAL) { + public function getObjects($criteria = [], $opts = [], $limit_val = null, $offset_val = 0, $sort_col = 'ObjectId', $sort_order = 'DESC', $group_by = null, $group_limit = 0, $group_offset = 0, $view = self::OBJ_RESULT_VIEW_FULL, $mode = self::OBJECT_RESULT_MODE_NORMAL) { $db_params = $this->getModule('api_config')->getConfig('db'); if ($db_params['type'] === Database::PGSQL_TYPE) { $sort_col = strtolower($sort_col); @@ -122,7 +122,7 @@ LEFT JOIN Client USING (ClientId) ' . $where['where'] . $order . $limit . $offset; $statement = Database::runQuery($sql, $where['params']); $result = $statement->fetchAll(\PDO::FETCH_OBJ); - if ($mode == self::OBJECT_RESULT_MODE_OVERVIEW_UNIQUE) { + if (key_exists('unique_objects', $opts) && $opts['unique_objects']) { Database::groupBy('objectname', $result, 1, 0, 'objecttype'); $func = function ($item) { return ((object)$item[0]); @@ -131,7 +131,7 @@ LEFT JOIN Client USING (ClientId) ' $result = array_map($func, $result); } $overview = Database::groupBy($group_by, $result, $group_limit, $group_offset, 'objecttype'); - if ($mode == self::OBJECT_RESULT_MODE_OVERVIEW || $mode == self::OBJECT_RESULT_MODE_OVERVIEW_UNIQUE) { + if ($mode == self::OBJECT_RESULT_MODE_OVERVIEW) { // Overview mode. $result = [ 'objects' => $result, @@ -456,7 +456,7 @@ JOIN Job USING (JobId) ' 'vals' => $objectid ]] ]; - $obj = $this->getObjects($params, 1); + $obj = $this->getObjects($params, [], 1); if (is_array($obj) && count($obj) > 0) { $obj = array_shift($obj); } diff --git a/gui/baculum/protected/API/Pages/API/Objects.php b/gui/baculum/protected/API/Pages/API/Objects.php index c236ab75e..47a6e2da8 100644 --- a/gui/baculum/protected/API/Pages/API/Objects.php +++ b/gui/baculum/protected/API/Pages/API/Objects.php @@ -84,9 +84,9 @@ class Objects extends BaculumAPIServer { $order_direction = $this->Request->contains('order_direction') && $misc->isValidOrderDirection($this->Request['order_direction']) ? $this->Request['order_direction']: 'DESC'; $mode = ($this->Request->contains('overview') && $misc->isValidBooleanTrue($this->Request['overview'])) ? ObjectManager::OBJECT_RESULT_MODE_OVERVIEW : ObjectManager::OBJECT_RESULT_MODE_NORMAL; $unique_objects = ($this->Request->contains('unique_objects') && $misc->isValidBooleanTrue($this->Request['unique_objects'])) ? true : false; - if ($mode === ObjectManager::OBJECT_RESULT_MODE_OVERVIEW && $unique_objects) { - $mode = ObjectManager::OBJECT_RESULT_MODE_OVERVIEW_UNIQUE; - } + $opts = [ + 'unique_objects' => $unique_objects + ]; $or = new \ReflectionClass('Baculum\API\Modules\ObjectRecord'); $prop_cols = $or->getProperties(); @@ -377,6 +377,7 @@ class Objects extends BaculumAPIServer { $objects = $this->getModule('object')->getObjects( $params, + $opts, $limit, $offset, $order_by_lc,