From: Marcin Haba Date: Wed, 16 Nov 2022 14:50:31 +0000 (+0100) Subject: baculum: Add time range parameters to objects endpoint X-Git-Tag: Release-13.0.2~50 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b6fdc3fefd7db9a3808a0d144f96632a771d464e;p=thirdparty%2Fbacula.git baculum: Add time range parameters to objects endpoint --- diff --git a/gui/baculum/protected/API/Pages/API/Objects.php b/gui/baculum/protected/API/Pages/API/Objects.php index 736fd2e17..bf59293d3 100644 --- a/gui/baculum/protected/API/Pages/API/Objects.php +++ b/gui/baculum/protected/API/Pages/API/Objects.php @@ -44,6 +44,14 @@ class Objects extends BaculumAPIServer { $jobname = $this->Request->contains('jobname') && $misc->isValidName($this->Request['jobname']) ? $this->Request['jobname'] : null; $jobids = $this->Request->contains('jobids') && $misc->isValidIdsList($this->Request['jobids']) ? explode(',', $this->Request['jobids']) : []; $groupby = $this->Request->contains('groupby') && $misc->isValidColumn($this->Request['groupby']) ? strtolower($this->Request['groupby']) : null; + $schedtime_from = $this->Request->contains('schedtime_from') && $misc->isValidInteger($this->Request['schedtime_from']) ? (int)$this->Request['schedtime_from'] : null; + $schedtime_to = $this->Request->contains('schedtime_to') && $misc->isValidInteger($this->Request['schedtime_to']) ? (int)$this->Request['schedtime_to'] : null; + $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; + $realendtime_from = $this->Request->contains('realendtime_from') && $misc->isValidInteger($this->Request['realendtime_from']) ? (int)$this->Request['realendtime_from'] : null; + $realendtime_to = $this->Request->contains('realendtime_to') && $misc->isValidInteger($this->Request['realendtime_to']) ? (int)$this->Request['realendtime_to'] : null; if (is_string($groupby)) { $or = new \ReflectionClass('Baculum\API\Modules\ObjectRecord'); @@ -118,6 +126,74 @@ class Objects extends BaculumAPIServer { ]; } + // Scheduled time range + if (!empty($schedtime_from) || !empty($schedtime_to)) { + $params['Job.SchedTime'] = []; + if (!empty($schedtime_from)) { + $params['Job.SchedTime'][] = [ + 'operator' => '>=', + 'vals' => date('Y-m-d H:m:s', $schedtime_from) + ]; + } + if (!empty($schedtime_to)) { + $params['Job.SchedTime'][] = [ + 'operator' => '<=', + 'vals' => date('Y-m-d H:m:s', $schedtime_to) + ]; + } + } + + // Start time range + if (!empty($starttime_from) || !empty($starttime_to)) { + $params['Job.StartTime'] = []; + if (!empty($starttime_from)) { + $params['Job.StartTime'][] = [ + 'operator' => '>=', + 'vals' => date('Y-m-d H:m:s', $starttime_from) + ]; + } + if (!empty($starttime_to)) { + $params['Job.StartTime'][] = [ + 'operator' => '<=', + 'vals' => date('Y-m-d H:m:s', $starttime_to) + ]; + } + } + + // End time range + if (!empty($endtime_from) || !empty($endtime_to)) { + $params['Job.EndTime'] = []; + if (!empty($endtime_from)) { + $params['Job.EndTime'][] = [ + 'operator' => '>=', + 'vals' => date('Y-m-d H:m:s', $endtime_from) + ]; + } + if (!empty($endtime_to)) { + $params['Job.EndTime'][] = [ + 'operator' => '<=', + 'vals' => date('Y-m-d H:m:s', $endtime_to) + ]; + } + } + + // Real end time range + if (!empty($realendtime_from) || !empty($realendtime_to)) { + $params['Job.RealEndTime'] = []; + if (!empty($realendtime_from)) { + $params['Job.RealEndTime'][] = [ + 'operator' => '>=', + 'vals' => date('Y-m-d H:m:s', $realendtime_from) + ]; + } + if (!empty($realendtime_to)) { + $params['Job.RealEndTime'][] = [ + 'operator' => '<=', + 'vals' => date('Y-m-d H:m:s', $realendtime_to) + ]; + } + } + $objects = $this->getModule('object')->getObjects($params, $limit, $groupby); $this->output = $objects; $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 e64883c81..e31e84ec7 100644 --- a/gui/baculum/protected/API/openapi_baculum.json +++ b/gui/baculum/protected/API/openapi_baculum.json @@ -6375,6 +6375,78 @@ "schema": { "type": "string" } + }, + { + "name": "schedtime_from", + "in": "query", + "required": false, + "description": "Scheduled time from (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, + { + "name": "schedtime_to", + "in": "query", + "required": false, + "description": "Scheduled time to (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, + { + "name": "starttime_from", + "in": "query", + "required": false, + "description": "Start time from (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, + { + "name": "starttime_to", + "in": "query", + "required": false, + "description": "Start time to (UNIX timestamp format, seconds)", + "schema": { + "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": "realendtime_from", + "in": "query", + "required": false, + "description": "Real end time from (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } + }, + { + "name": "realendtime_to", + "in": "query", + "required": false, + "description": "Real end time to (UNIX timestamp format, seconds)", + "schema": { + "type": "integer" + } } ] }