From 09c9a9db72a853756159d84300dbd994741de714 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Tue, 5 Oct 2021 23:04:50 +0200 Subject: [PATCH] DirectorObjectForm: use new DbObjectStore --- .../Director/Web/Form/DirectorObjectForm.php | 45 +++++++------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/library/Director/Web/Form/DirectorObjectForm.php b/library/Director/Web/Form/DirectorObjectForm.php index d1884f84..4f94f6e1 100644 --- a/library/Director/Web/Form/DirectorObjectForm.php +++ b/library/Director/Web/Form/DirectorObjectForm.php @@ -5,12 +5,11 @@ namespace Icinga\Module\Director\Web\Form; use Exception; use gipfl\IcingaWeb2\Url; use Icinga\Authentication\Auth; +use Icinga\Module\Director\Data\Db\DbObjectStore; use Icinga\Module\Director\Db; use Icinga\Module\Director\Data\Db\DbObject; use Icinga\Module\Director\Data\Db\DbObjectWithSettings; use Icinga\Module\Director\Db\Branch\Branch; -use Icinga\Module\Director\Db\Branch\BranchModificationStore; -use Icinga\Module\Director\Db\Branch\IcingaObjectModification; use Icinga\Module\Director\Exception\NestingError; use Icinga\Module\Director\Hook\IcingaObjectFormHook; use Icinga\Module\Director\IcingaConfig\StateFilterSet; @@ -677,23 +676,7 @@ abstract class DirectorObjectForm extends DirectorForm : $this->translate('A new %s has successfully been created'), $this->translate($this->getObjectShortClassName()) ); - if ($this->branch && $this->branch->isBranch()) { - if ($object->shouldBeRenamed()) { - $this->getElement('object_name')->addError( - $this->translate('Renaming objects in branches is not (yet) supported') - ); - return; - } - $store = new BranchModificationStore($this->getDb(), $object->getShortTableName()); - - $store->store( - IcingaObjectModification::getModification($object), - $object->get('id'), - $this->branch->getUuid() - ); - } else { - $object->store($this->db); - } + $this->getDbObjectStore()->store($object); } else { if ($this->isApiRequest()) { $this->setHttpResponseCode(304); @@ -933,22 +916,21 @@ abstract class DirectorObjectForm extends DirectorForm ); } - if ($this->branch && $this->branch->isBranch()) { - $store = new BranchModificationStore($this->getDb(), $object->getShortTableName()); - $store->store( - IcingaObjectModification::delete($object), - $object->get('id'), - $this->branch->getUuid() - ); - - $this->setSuccessUrl($url); - } elseif ($object->delete()) { + if ($this->getDbObjectStore()->delete($object)) { $this->setSuccessUrl($url); } - // TODO: show object name and so $this->redirectOnSuccess($msg); } + /** + * @return DbObjectStore + */ + protected function getDbObjectStore() + { + $store = new DbObjectStore($this->getDb(), $this->branch); + return $store; + } + protected function addDeleteButton($label = null) { $object = $this->object; @@ -1076,6 +1058,9 @@ abstract class DirectorObjectForm extends DirectorForm public function loadObject($id) { + if ($this->branch && $this->branch->isBranch()) { + throw new \RuntimeException('Calling loadObject from form in a branch'); + } /** @var DbObject $class */ $class = $this->getObjectClassname(); if (is_int($id)) {