diff options
Diffstat (limited to 'library/Director/DirectorObject/Automation/Basket.php')
-rw-r--r-- | library/Director/DirectorObject/Automation/Basket.php | 70 |
1 files changed, 10 insertions, 60 deletions
diff --git a/library/Director/DirectorObject/Automation/Basket.php b/library/Director/DirectorObject/Automation/Basket.php index f7eb8e5..81ae107 100644 --- a/library/Director/DirectorObject/Automation/Basket.php +++ b/library/Director/DirectorObject/Automation/Basket.php @@ -4,8 +4,6 @@ namespace Icinga\Module\Director\DirectorObject\Automation; use Icinga\Module\Director\Core\Json; use Icinga\Module\Director\Data\Db\DbObject; -use Icinga\Module\Director\Db; -use Icinga\Module\Director\Exception\DuplicateKeyException; /** * Class Basket @@ -15,16 +13,17 @@ use Icinga\Module\Director\Exception\DuplicateKeyException; */ class Basket extends DbObject implements ExportInterface { - const SELECTION_ALL = true; - const SELECTION_NONE = false; + const SELECTION_ALL = 'ALL'; + const SELECTION_NONE = 'IGNORE'; + const SELECTION_CUSTOM = '[]'; protected $table = 'director_basket'; protected $keyName = 'basket_name'; - protected $chosenObjects = []; + protected $uuidColumn = 'uuid'; - protected $protectedFormerChosenObjects; + protected $chosenObjects = []; protected $defaultProperties = [ 'uuid' => null, @@ -69,44 +68,6 @@ class Basket extends DbObject implements ExportInterface return $this->get('basket_name'); } - public function export() - { - $result = $this->getProperties(); - unset($result['uuid']); - $result['objects'] = Json::decode($result['objects']); - ksort($result); - - return (object) $result; - } - - /** - * @param $plain - * @param Db $db - * @param bool $replace - * @return static - * @throws DuplicateKeyException - * @throws \Icinga\Exception\NotFoundError - */ - public static function import($plain, Db $db, $replace = false) - { - $properties = (array) $plain; - $name = $properties['basket_name']; - - if ($replace && static::exists($name, $db)) { - $object = static::load($name, $db); - } elseif (static::exists($name, $db)) { - throw new DuplicateKeyException( - 'Basket "%s" already exists', - $name - ); - } else { - $object = static::create([], $db); - } - $object->setProperties($properties); - - return $object; - } - public function supportsCustomSelectionFor($type) { if (! array_key_exists($type, $this->chosenObjects)) { @@ -121,7 +82,6 @@ class Basket extends DbObject implements ExportInterface if (empty($objects)) { $this->chosenObjects = []; } else { - $this->protectedFormerChosenObjects = $this->chosenObjects; $this->chosenObjects = []; foreach ((array) $objects as $type => $object) { $this->addObjects($type, $object); @@ -141,32 +101,22 @@ class Basket extends DbObject implements ExportInterface { BasketSnapshot::assertValidType($type); // '1' -> from Form! - if ($objects === 'ALL') { + if ($objects === self::SELECTION_ALL) { $objects = true; - } elseif ($objects === null || $objects === 'IGNORE') { + } elseif ($objects === null || $objects === self::SELECTION_NONE) { return; - } elseif ($objects === '[]' || is_array($objects)) { + } elseif ($objects === self::SELECTION_CUSTOM || is_array($objects)) { if (! isset($this->chosenObjects[$type]) || ! is_array($this->chosenObjects[$type])) { $this->chosenObjects[$type] = []; } - if (isset($this->protectedFormerChosenObjects[$type])) { - if (is_array($this->protectedFormerChosenObjects[$type])) { - $this->chosenObjects[$type] = $this->protectedFormerChosenObjects[$type]; - } else { - $this->chosenObjects[$type] = []; - } - } - - if ($objects === '[]') { + if ($objects === self::SELECTION_CUSTOM) { $objects = []; } } if ($objects === true) { $this->chosenObjects[$type] = true; - } elseif ($objects === '0') { - // nothing - } else { + } elseif ($objects !== '0') { // TODO: what would generate '0'? foreach ($objects as $object) { $this->addObject($type, $object); } |