]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add endtime property and filters to source list endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 12 Jan 2023 14:15:10 +0000 (15:15 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Sun, 5 Mar 2023 06:06:30 +0000 (07:06 +0100)
gui/baculum/protected/API/Modules/SourceManager.php
gui/baculum/protected/API/Pages/API/Sources.php
gui/baculum/protected/API/openapi_baculum.json

index 7cb0b20b49fe3d6f3cf3be4a68bb169148d558ae..3647e1e8c0fc499923378e0bbb91c04ce8537cbd 100644 (file)
@@ -38,7 +38,7 @@ class SourceManager extends APIModule {
                }
                $where = Database::getWhere($criteria, true);
                $sql = 'SELECT DISTINCT 
-       sres.fileset, sres.client, sres.job, ores.starttime, ores.jobid, jres.jobstatus
+       sres.fileset, sres.client, sres.job, jres.starttime, jres.endtime, ores.jobid, jres.jobstatus
        FROM Job AS jres,
        (
                SELECT DISTINCT
@@ -50,7 +50,6 @@ class SourceManager extends APIModule {
                JOIN Client USING (ClientId)
        ) AS sres, (
                SELECT
-                       MAX(StartTime) AS starttime,
                        MAX(JobId) AS jobid,
                        FileSet.FileSet AS fileset,
                        Client.Name AS client,
@@ -68,7 +67,7 @@ class SourceManager extends APIModule {
                AND sres.fileset = ores.fileset
                AND jres.Type = \'B\'
                ' . (!empty($where['where']) ? ' AND ' .  $where['where']  : '') . '
-       ORDER BY sres.fileset ASC, sres.client ASC, sres.job ASC, ores.starttime ASC ' . $limit;
+       ORDER BY sres.fileset ASC, sres.client ASC, sres.job ASC, jres.starttime ASC ' . $limit;
 
                $connection = SourceRecord::finder()->getDbConnection();
                $connection->setActive(true);
index 450469838867c44ee71d626589f973f1bd438cf2..81c6c503d8cbcb6993eb5f3780a6ae54b868d2b7 100644 (file)
@@ -40,6 +40,8 @@ class Sources extends BaculumAPIServer {
                $fileset = $this->Request->contains('fileset') && $misc->isValidName($this->Request['fileset']) ? $this->Request['fileset'] : '';
                $starttime_from = $this->Request->contains('starttime_from') && $misc->isValidInteger($this->Request['starttime_from']) ? (int)$this->Request['starttime_from'] : null;
                $starttime_to = $this->Request->contains('starttime_to') && $misc->isValidInteger($this->Request['starttime_to']) ? (int)$this->Request['starttime_to'] : null;
+               $endtime_from = $this->Request->contains('endtime_from') && $misc->isValidInteger($this->Request['endtime_from']) ? (int)$this->Request['endtime_from'] : null;
+               $endtime_to = $this->Request->contains('endtime_to') && $misc->isValidInteger($this->Request['endtime_to']) ? (int)$this->Request['endtime_to'] : null;
                $jobstatus = $this->Request->contains('jobstatus') && $misc->isValidState($this->Request['jobstatus']) ? $this->Request['jobstatus'] : '';
                $hasobject = $this->Request->contains('hasobject') && $misc->isValidBoolean($this->Request['hasobject']) ? $this->Request['hasobject'] : null;
 
@@ -81,21 +83,38 @@ class Sources extends BaculumAPIServer {
 
                // Start time range
                if (!empty($starttime_from) || !empty($starttime_to)) {
-                       $params['ores.starttime'] = [];
+                       $params['jres.starttime'] = [];
                        if (!empty($starttime_from)) {
-                               $params['ores.starttime'][] = [
+                               $params['jres.starttime'][] = [
                                        'operator' => '>=',
                                        'vals' => date('Y-m-d H:i:s', $starttime_from)
                                ];
                        }
                        if (!empty($starttime_to)) {
-                               $params['ores.starttime'][] = [
+                               $params['jres.starttime'][] = [
                                        'operator' => '<=',
                                        'vals' => date('Y-m-d H:i:s', $starttime_to)
                                ];
                        }
                }
 
+               // End time range
+               if (!empty($endtime_from) || !empty($endtime_to)) {
+                       $params['jres.endtime'] = [];
+                       if (!empty($endtime_from)) {
+                               $params['jres.endtime'][] = [
+                                       'operator' => '>=',
+                                       'vals' => date('Y-m-d H:i:s', $endtime_from)
+                               ];
+                       }
+                       if (!empty($endtime_to)) {
+                               $params['jres.endtime'][] = [
+                                       'operator' => '<=',
+                                       'vals' => date('Y-m-d H:i:s', $endtime_to)
+                               ];
+                       }
+               }
+
                $sources = $this->getModule('source')->getSources($params, $limit);
                $this->output = $sources;
                $this->error = SourceError::ERROR_NO_ERRORS;
index 275a9eca1655d6533775b40f00c1f1a50dbfbc18..b0d38f5a45e2b8570977aaaab5c9c3c6055ea76d 100644 (file)
                                                        "type": "integer"
                                                }
                                        },
+                                       {
+                                               "name": "endtime_from",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "End time from (UNIX timestamp format, seconds)",
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       },
+                                       {
+                                               "name": "endtime_to",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "End time to (UNIX timestamp format, seconds)",
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       },
                                        {
                                                "name": "jobstatus",
                                                "in": "query",
                                        "description": "Start time latest job using this source",
                                        "type": "string"
                                },
+                               "endtime": {
+                                       "description": "End time latest job using this source",
+                                       "type": "string"
+                               },
                                "jobid": {
                                        "description": "Latest jobid",
                                        "type": "integer"