From: Marcin Haba Date: Wed, 10 Aug 2022 12:52:00 +0000 (+0200) Subject: baculum: Add single object record endpoint X-Git-Tag: Release-13.0.2~75 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f2bc3f5b99de6e7bf8b59e7c2bfd4bd2e89ccfb2;p=thirdparty%2Fbacula.git baculum: Add single object record endpoint --- diff --git a/gui/baculum/protected/API/Modules/ObjectManager.php b/gui/baculum/protected/API/Modules/ObjectManager.php index 26154e4f6..5a6cd22b0 100644 --- a/gui/baculum/protected/API/Modules/ObjectManager.php +++ b/gui/baculum/protected/API/Modules/ObjectManager.php @@ -53,4 +53,18 @@ LEFT JOIN Job USING (JobId) ' return ObjectRecord::finder()->findAllBySql($sql, $where['params']); } + + public function getObjectById($objectid) { + $params = [ + 'Object.ObjectId' => [ + 'vals' => $objectid, + 'operator' => '' + ] + ]; + $obj = $this->getObjects($params, 1); + if (is_array($obj) && count($obj) > 0) { + $obj = array_shift($obj); + } + return $obj; + } } diff --git a/gui/baculum/protected/API/Pages/API/ObjectClass.php b/gui/baculum/protected/API/Pages/API/ObjectClass.php new file mode 100644 index 000000000..d198e6544 --- /dev/null +++ b/gui/baculum/protected/API/Pages/API/ObjectClass.php @@ -0,0 +1,46 @@ + + * @category API + * @package Baculum API + */ +class ObjectClass extends BaculumAPIServer { + + public function get() { + $objectid = $this->Request->contains('id') ? (int)$this->Request['id'] : 0; + + $object = $this->getModule('object')->getObjectById($objectid); + if (is_object($object)) { + $this->output = $object; + $this->error = ObjectError::ERROR_NO_ERRORS; + } else { + $this->output = ObjectError::MSG_ERROR_OBJECT_DOES_NOT_EXISTS; + $this->error = ObjectError::ERROR_OBJECT_DOES_NOT_EXISTS; + } + } +} diff --git a/gui/baculum/protected/API/Pages/API/endpoints.xml b/gui/baculum/protected/API/Pages/API/endpoints.xml index d60165b90..a64b3a912 100644 --- a/gui/baculum/protected/API/Pages/API/endpoints.xml +++ b/gui/baculum/protected/API/Pages/API/endpoints.xml @@ -89,6 +89,7 @@ +