IcingaServiceSet: Check if object_name is unique for templates

refs #13309
This commit is contained in:
Markus Frosch 2016-11-24 17:39:51 +01:00
parent ab169e4b78
commit 3a8cad2486

View File

@ -4,6 +4,7 @@ namespace Icinga\Module\Director\Objects;
use Icinga\Data\Filter\Filter;
use Icinga\Exception\IcingaException;
use Icinga\Module\Director\Exception\DuplicateKeyException;
use Icinga\Module\Director\IcingaConfig\IcingaConfig;
@ -249,4 +250,17 @@ class IcingaServiceSet extends IcingaObject
return $host->getRenderingZone($config);
}
}
protected function beforeStore()
{
parent::beforeStore();
$name = $this->getObjectName();
// checking if template object_name is unique
// TODO: Move to IcingaObject
if (! $this->hasBeenLoadedFromDb() && $this->isTemplate() && static::exists($name, $this->connection)) {
throw new DuplicateKeyException('%s template "%s" already existing in database!', $this->getType(), $name);
}
}
}