]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Fix offset and limit parameters for case when storage in catalog is inconsis...
authorMarcin Haba <marcin.haba@bacula.pl>
Thu, 27 Apr 2023 12:13:06 +0000 (14:13 +0200)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 1 May 2023 11:18:25 +0000 (13:18 +0200)
gui/baculum/protected/API/Pages/API/Storages.php

index cb4b059e0ba3d69f870fd92e7622b9eb28448ddf..2c3dc427693f014585b8d9c23f516158e7c7be69 100644 (file)
@@ -34,9 +34,9 @@ class Storages extends BaculumAPIServer {
 
        public function get() {
                $misc = $this->getModule('misc');
-               $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : 0;
-               $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : 0;
-               $storages = $this->getModule('storage')->getStorages($limit, $offset);
+               $limit = $this->Request->contains('limit') ? intval($this->Request['limit']) : null;
+               $offset = $this->Request->contains('offset') && $misc->isValidInteger($this->Request['offset']) ? (int)$this->Request['offset'] : null;
+               $storages = $this->getModule('storage')->getStorages();
                $result = $this->getModule('bconsole')->bconsoleCommand(
                        $this->director,
                        array('.storage')
@@ -49,6 +49,17 @@ class Storages extends BaculumAPIServer {
                                        $storages_output[] = $storage;
                                }
                        }
+                       if (!is_int($offset) || $offset < 0) {
+                               $offset = 0;
+                       }
+                       if ($limit < 0) {
+                               $limit = 0;
+                       }
+                       /**
+                        * Slice needs to be done here instead in the db because in the catalog can be storages
+                        * that do not longer exist in the configuration.
+                        */
+                       $storages_output = array_slice($storages_output, $offset, $limit);
                        $this->output = $storages_output;
                        $this->error = StorageError::ERROR_NO_ERRORS;
                } else {