DirectorObjectForm: use new DbObjectStore

This commit is contained in:
Thomas Gelf 2021-10-05 23:04:50 +02:00
parent 098f620802
commit 09c9a9db72
1 changed files with 15 additions and 30 deletions

View File

@ -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)) {