diff --git a/library/Director/Hook/PropertyModifierHook.php b/library/Director/Hook/PropertyModifierHook.php index 7c93f160..a05a9368 100644 --- a/library/Director/Hook/PropertyModifierHook.php +++ b/library/Director/Hook/PropertyModifierHook.php @@ -178,7 +178,7 @@ abstract class PropertyModifierHook return $this->db; } - public function setSettings($settings) + public function setSettings(array $settings) { $this->settings = $settings; return $this; @@ -204,6 +204,11 @@ abstract class PropertyModifierHook return (object) $this->settings; } + public function getSettings() + { + return $this->settings; + } + /** * Override this method if you want to extend the settings form * diff --git a/library/Director/Objects/ImportRowModifier.php b/library/Director/Objects/ImportRowModifier.php index 36688ee4..2b0d8cc9 100644 --- a/library/Director/Objects/ImportRowModifier.php +++ b/library/Director/Objects/ImportRowModifier.php @@ -68,6 +68,13 @@ class ImportRowModifier extends DbObjectWithSettings return (object) $properties; } + public function setSettings($settings) + { + $settings = $this->getInstance()->setSettings((array) $settings)->getSettings(); + + return parent::setSettings($settings); // TODO: Change the autogenerated stub + } + protected function beforeStore() { if (! $this->hasBeenLoadedFromDb() && $this->get('priority') === null) { diff --git a/library/Director/Objects/ImportSource.php b/library/Director/Objects/ImportSource.php index 8f6bcb29..2a7fdbea 100644 --- a/library/Director/Objects/ImportSource.php +++ b/library/Director/Objects/ImportSource.php @@ -47,6 +47,8 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface private $rowModifiers; + private $loadedRowModifiers; + private $newRowModifiers; /** @@ -101,16 +103,45 @@ class ImportSource extends DbObjectWithSettings implements ExportInterface $object = static::create([], $db); } - $object->newRowModifiers = $properties['modifiers']; - unset($properties['modifiers']); $object->setProperties($properties); if ($id !== null) { + // TODO: really? $object->reallySet('id', $id); } return $object; } + public function setModifiers(array $modifiers) + { + if ($this->loadedRowModifiers === null) { + $this->loadedRowModifiers = $this->fetchRowModifiers(); + } + $current = $this->loadedRowModifiers; + if (count($current) !== count($modifiers)) { + $this->newRowModifiers = $modifiers; + } else { + $i = 0; + $modified = false; + foreach ($modifiers as $props) { + $this->loadedRowModifiers[$i]->setProperties((array) $props); + if ($this->loadedRowModifiers[$i]->hasBeenModified()) { + $modified = true; + } + } + if ($modified) { + // TOOD: no newRowModifiers, directly store loaded ones if diff + $this->newRowModifiers = $modifiers; + } + } + } + + public function hasBeenModified() + { + return $this->newRowModifiers !== null + || parent::hasBeenModified(); + } + public function getUniqueIdentifier() { return $this->get('source_name'); diff --git a/library/Director/PropertyModifier/PropertyModifierGetPropertyFromOtherImportSource.php b/library/Director/PropertyModifier/PropertyModifierGetPropertyFromOtherImportSource.php index c3166651..d57b427e 100644 --- a/library/Director/PropertyModifier/PropertyModifierGetPropertyFromOtherImportSource.php +++ b/library/Director/PropertyModifier/PropertyModifierGetPropertyFromOtherImportSource.php @@ -2,7 +2,6 @@ namespace Icinga\Module\Director\PropertyModifier; -use Icinga\Module\Director\Forms\ImportRowModifierForm; use Icinga\Module\Director\Hook\PropertyModifierHook; use Icinga\Module\Director\Objects\ImportRowModifier; use Icinga\Module\Director\Objects\ImportSource; @@ -67,6 +66,24 @@ class PropertyModifierGetPropertyFromOtherImportSource extends PropertyModifierH ] + $extra); } + /** + * @param $settings + * @return PropertyModifierHook + * @throws \Icinga\Exception\NotFoundError + */ + public function setSettings(array $settings) + { + if (isset($settings['import_source'])) { + $settings['import_source_id'] = ImportSource::load( + $settings['import_source'], + $this->getDb() + )->get('id'); + unset($settings['import_source']); + } + + return parent::setSettings($settings); + } + public function transform($value) { $data = $this->getImportedData();