From 3a8cad248612f2eb499e5b4880acfc04bb5e30c3 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Thu, 24 Nov 2016 17:39:51 +0100 Subject: [PATCH] IcingaServiceSet: Check if object_name is unique for templates refs #13309 --- library/Director/Objects/IcingaServiceSet.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/library/Director/Objects/IcingaServiceSet.php b/library/Director/Objects/IcingaServiceSet.php index 4251a260..214de131 100644 --- a/library/Director/Objects/IcingaServiceSet.php +++ b/library/Director/Objects/IcingaServiceSet.php @@ -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); + } + } }