From 3c4d4de633b7497996e5e92b841cf6ec28b6fb60 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Sun, 20 Aug 2017 15:14:37 +0200 Subject: [PATCH] ImportRowModifier: also use PriorityColumn helper --- .../Director/Objects/ImportRowModifier.php | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/library/Director/Objects/ImportRowModifier.php b/library/Director/Objects/ImportRowModifier.php index e2a7604a..862968dd 100644 --- a/library/Director/Objects/ImportRowModifier.php +++ b/library/Director/Objects/ImportRowModifier.php @@ -3,16 +3,20 @@ namespace Icinga\Module\Director\Objects; use Icinga\Module\Director\Data\Db\DbObjectWithSettings; +use Icinga\Module\Director\Hook\PropertyModifierHook; +use Icinga\Module\Director\Objects\Extension\PriorityColumn; class ImportRowModifier extends DbObjectWithSettings { + use PriorityColumn; + protected $table = 'import_row_modifier'; protected $keyName = 'id'; protected $autoincKeyName = 'id'; - protected $defaultProperties = array( + protected $defaultProperties = [ 'id' => null, 'source_id' => null, 'property_name' => null, @@ -20,7 +24,7 @@ class ImportRowModifier extends DbObjectWithSettings 'target_property' => null, 'priority' => null, 'description' => null, - ); + ]; protected $settingsTable = 'import_row_modifier_setting'; @@ -31,13 +35,26 @@ class ImportRowModifier extends DbObjectWithSettings public function getInstance() { if ($this->hookInstance === null) { - $obj = new $this->provider_class; + /** @var PropertyModifierHook $obj */ + $obj = new $this->get('provider_class'); $obj->setSettings($this->getSettings()); - $obj->setTargetProperty($this->target_property); + $obj->setTargetProperty($this->get('target_property')); $obj->setDb($this->connection); $this->hookInstance = $obj; } return $this->hookInstance; } + + protected function beforeStore() + { + if (! $this->hasBeenLoadedFromDb()) { + $this->setNextPriority('source_id'); + } + } + + protected function onInsert() + { + $this->refreshPriortyProperty(); + } }