]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add offset parameter to sources endpoint
authorMarcin Haba <marcin.haba@bacula.pl>
Tue, 4 Apr 2023 08:25:37 +0000 (10:25 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Thu, 20 Apr 2023 10:00:26 +0000 (12:00 +0200)
gui/baculum/protected/API/Modules/SourceManager.php
gui/baculum/protected/API/Pages/API/Sources.php

index 3647e1e8c0fc499923378e0bbb91c04ce8537cbd..c370e5b9afe7e879fbaaaa7f2c4668377573e239 100644 (file)
@@ -31,11 +31,15 @@ namespace Baculum\API\Modules;
  */
 class SourceManager extends APIModule {
 
-       public function getSources($criteria = [], $limit_val = null) {
+       public function getSources($criteria = [], $limit_val = null, $offset_val = 0) {
                $limit = '';
                if(is_int($limit_val) && $limit_val > 0) {
                        $limit = ' LIMIT ' . $limit_val;
                }
+               $offset = '';
+               if (is_int($offset_val) && $offset_val > 0) {
+                       $offset = ' OFFSET ' . $offset_val;
+               }
                $where = Database::getWhere($criteria, true);
                $sql = 'SELECT DISTINCT 
        sres.fileset, sres.client, sres.job, jres.starttime, jres.endtime, ores.jobid, jres.jobstatus
@@ -67,7 +71,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, jres.starttime ASC ' . $limit;
+       ORDER BY sres.fileset ASC, sres.client ASC, sres.job ASC, jres.starttime ASC ' . $limit . $offset;
 
                $connection = SourceRecord::finder()->getDbConnection();
                $connection->setActive(true);
index 81c6c503d8cbcb6993eb5f3780a6ae54b868d2b7..9b1c56f05fdc081a27b34ad953a9d48806ae1552 100644 (file)
@@ -34,7 +34,8 @@ class Sources extends BaculumAPIServer {
 
        public function get() {
                $misc = $this->getModule('misc');
-               $limit = $this->Request->contains('limit') ? (int)$this->Request['limit'] : 0;
+               $limit = $this->Request->contains('limit') && $misc->isValidInteger($this->Request['limit']) ? (int)$this->Request['limit'] : 0;
+               $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
                $job = $this->Request->contains('job') && $misc->isValidName($this->Request['job']) ? $this->Request['job'] : '';
                $client = $this->Request->contains('client') && $misc->isValidName($this->Request['client']) ? $this->Request['client'] : '';
                $fileset = $this->Request->contains('fileset') && $misc->isValidName($this->Request['fileset']) ? $this->Request['fileset'] : '';
@@ -115,7 +116,7 @@ class Sources extends BaculumAPIServer {
                        }
                }
 
-               $sources = $this->getModule('source')->getSources($params, $limit);
+               $sources = $this->getModule('source')->getSources($params, $limit, $offset);
                $this->output = $sources;
                $this->error = SourceError::ERROR_NO_ERRORS;
        }