]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add sorting by endtime and add endtime property to objects overview endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Wed, 21 Jun 2023 06:32:41 +0000 (08:32 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 3 Jul 2023 08:46:57 +0000 (10:46 +0200)
gui/baculum/protected/API/Modules/ObjectManager.php
gui/baculum/protected/API/Pages/API/ObjectsOverview.php
gui/baculum/protected/API/openapi_baculum.json

index f035a452ca7c0af948bee74abd0115aa24b34284..fea93c81a5e9696955291da7a8c41936c17f7a2b 100644 (file)
@@ -34,6 +34,15 @@ use PDO;
  */
 class ObjectManager extends APIModule
 {
+
+       /**
+        * Allowed order columns for object overview.
+        */
+       public static $overview_order_columns = [
+               'object' => ['objectname', 'endtime'],
+               'general' => ['client', 'jobstatus', 'endtime']
+       ];
+
        /**
         * Object result in job and object endpoint can be displayed in on of the two views:
         *  - basic - display only base job and object properties
@@ -167,9 +176,10 @@ LEFT JOIN Client USING (ClientId) '
 
                $limit = is_int($limit_val) && $limit_val > 0 ? ' LIMIT ' . $limit_val : '';
                $offset = is_int($offset_val) && $offset_val > 0 ? ' OFFSET ' . $offset_val : '';
+               $sort_col_i = strtolower($sort_col);
                $db_params = $this->getModule('api_config')->getConfig('db');
                if ($db_params['type'] === Database::PGSQL_TYPE) {
-                   $sort_col = strtolower($sort_col);
+                   $sort_col = $sort_col_i;
                }
 
                // default sorting for objects
@@ -186,6 +196,10 @@ LEFT JOIN Client USING (ClientId) '
 
                if (empty($sort_col)) {
                        $sort_col = 'JobTDate';
+               } elseif (in_array($sort_col_i, ObjectManager::$overview_order_columns['object'])) {
+                       $obj_order .= sprintf(',%s %s', $sort_col, $sort_order);
+               } elseif (in_array($sort_col_i, ObjectManager::$overview_order_columns['general'])) {
+                       $file_order .= sprintf(',%s %s', $sort_col, $sort_order);
                }
                $order = sprintf(
                        'ORDER BY %s %s ',
@@ -233,6 +247,7 @@ LEFT JOIN Client USING (ClientId) '
                                        Object.JobId    AS jobid,
                                        JobTDate        AS jobtdate,
                                        Job.StartTime   AS starttime,
+                                       Job.EndTime     AS endtime,
                                        ObjectCategory  AS objectcategory,
                                        ObjectStatus    AS objectstatus,
                                        ObjectSource    AS objectsource,
@@ -258,6 +273,7 @@ LEFT JOIN Client USING (ClientId) '
                                                        Job.Level       AS level,
                                                        JobTDate        AS jobtdate,
                                                        StartTime       AS starttime,
+                                                       EndTime         AS endtime,
                                                        JobStatus       AS jobstatus,
                                                        JobBytes        AS jobbytes,
                                                        JobFiles        AS jobfiles
@@ -293,6 +309,7 @@ LEFT JOIN Client USING (ClientId) '
                                                Object.JobId    AS jobid,
                                                JobTDate        AS jobtdate,
                                                StartTime       AS starttime,
+                                               EndTime         AS endtime,
                                                ObjectCategory  AS objectcategory,
                                                ObjectStatus    AS objectstatus,
                                                ObjectSource    AS objectsource,
@@ -317,6 +334,7 @@ LEFT JOIN Client USING (ClientId) '
                                                jobid,
                                                AAA.jobtdate,
                                                starttime,
+                                               endtime,
                                                objectcategory,
                                                objectstatus,
                                                objectsource,
@@ -347,6 +365,7 @@ LEFT JOIN Client USING (ClientId) '
                                                Job.Level       AS level,
                                                JobTDate        AS jobtdate,
                                                StartTime       AS starttime,
+                                               EndTime         AS endtime,
                                                JobStatus       AS jobstatus,
                                                JobBytes        AS jobbytes,
                                                JobFiles        AS jobfiles
@@ -370,6 +389,7 @@ LEFT JOIN Client USING (ClientId) '
                                                level,
                                                AAA.jobtdate,
                                                starttime,
+                                               endtime,
                                                jobstatus,
                                                jobbytes,
                                                jobfiles
index 4ec51f34e9a37a7ac2e2f4d1d8d95aaeb5a7c1b0..5bb32df13c1d31eeb8452129e1d01287fc943879 100644 (file)
@@ -33,15 +33,6 @@ use Baculum\API\Modules\ObjectManager;
  */
 class ObjectsOverview extends BaculumAPIServer {
 
-       /**
-        * Allowed order columns for object overview.
-        */
-       private $overview_order_columns = [
-               'objectname',
-               'client',
-               'jobstatus'
-       ];
-
        public function get() {
                $misc = $this->getModule('misc');
                $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
@@ -91,7 +82,7 @@ class ObjectsOverview extends BaculumAPIServer {
 
                if (!empty($order_by)) {
                        $order_by_lc = strtolower($order_by);
-                       if (!in_array($order_by_lc, $this->overview_order_columns)) {
+                       if (!in_array($order_by_lc, ObjectManager::$overview_order_columns['object']) && !in_array($order_by_lc, ObjectManager::$overview_order_columns['general'])) {
                                $this->output = ObjectError::MSG_ERROR_INVALID_PROPERTY;
                                $this->error = ObjectError::ERROR_INVALID_PROPERTY;
                                return;
index cff09ffee1c26c54d8563db64159191ad4bbf7ea..3bdbee74733af3df825d7144b5429dd0e9a6b0c2 100644 (file)
                                                                                                                                                                "type": "string",
                                                                                                                                                                "description": "Job start time"
                                                                                                                                                        },
+                                                                                                                                                       "endtime": {
+                                                                                                                                                               "type": "string",
+                                                                                                                                                               "description": "Job end time"
+                                                                                                                                                       },
                                                                                                                                                        "objectcategory": {
                                                                                                                                                                "type": "string",
                                                                                                                                                                "description": "Object category"
                                                                                                                                                                "type": "string",
                                                                                                                                                                "description": "Job start time"
                                                                                                                                                        },
+                                                                                                                                                       "endtime": {
+                                                                                                                                                               "type": "string",
+                                                                                                                                                               "description": "Job end time"
+                                                                                                                                                       },
                                                                                                                                                        "jobstatus": {
                                                                                                                                                                "type": "string",
                                                                                                                                                                "description": "Job status"
                                                "name": "order_by",
                                                "in": "query",
                                                "required": false,
-                                               "description": "Sort by selected object property (default jobtdate). There can be one from the following properties: objectname, client, jobstatus.",
+                                               "description": "Sort by selected object property (default jobtdate). There can be one from the following properties: objectname, client, jobstatus, endtime.",
                                                "schema": {
                                                        "type": "string"
                                                }