diff options
Diffstat (limited to 'library/Director/Objects/IcingaObjectGroup.php')
-rw-r--r-- | library/Director/Objects/IcingaObjectGroup.php | 64 |
1 files changed, 30 insertions, 34 deletions
diff --git a/library/Director/Objects/IcingaObjectGroup.php b/library/Director/Objects/IcingaObjectGroup.php index c0bec54..c076f52 100644 --- a/library/Director/Objects/IcingaObjectGroup.php +++ b/library/Director/Objects/IcingaObjectGroup.php @@ -2,9 +2,7 @@ namespace Icinga\Module\Director\Objects; -use Icinga\Module\Director\Db; use Icinga\Module\Director\DirectorObject\Automation\ExportInterface; -use Icinga\Module\Director\Exception\DuplicateKeyException; abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface { @@ -24,53 +22,51 @@ abstract class IcingaObjectGroup extends IcingaObject implements ExportInterface 'assign_filter' => null, ]; + protected $memberShipShouldBeRefreshed = false; + public function getUniqueIdentifier() { return $this->getObjectName(); } - /** - * @return object - * @deprecated please use \Icinga\Module\Director\Data\Exporter - * @throws \Icinga\Exception\NotFoundError - */ - public function export() + protected function prefersGlobalZone() { - return $this->toPlainObject(); + return true; } - /** - * @param $plain - * @param Db $db - * @param bool $replace - * @return IcingaObjectGroup - * @throws DuplicateKeyException - * @throws \Icinga\Exception\NotFoundError - */ - public static function import($plain, Db $db, $replace = false) + protected function beforeStore() { - $properties = (array) $plain; - $name = $properties['object_name']; - $key = $name; - - if ($replace && static::exists($key, $db)) { - $object = static::load($key, $db); - } elseif (static::exists($key, $db)) { - throw new DuplicateKeyException( - 'Group "%s" already exists', - $name - ); + parent::beforeStore(); + if ($this->hasBeenLoadedFromDb()) { + if (!array_key_exists('assign_filter', $this->getModifiedProperties())) { + $this->memberShipShouldBeRefreshed = false; + return; + } } else { - $object = static::create([], $db); + if ($this->hasProperty('assign_filter') && $this->get('assign_filter') === null) { + $this->memberShipShouldBeRefreshed = false; + return; + } } - $object->setProperties($properties); + if ($this->hasProperty('assign_filter')) { + $this->memberShipShouldBeRefreshed = true; + } + } - return $object; + protected function notifyResolvers() + { + if ($this->memberShipShouldBeRefreshed) { + $resolver = $this->getMemberShipResolver(); + $resolver->addGroup($this); + $resolver->refreshDb(); + } + + return $this; } - protected function prefersGlobalZone() + protected function getMemberShipResolver() { - return true; + return null; } } |