diff --git a/library/Director/Import/PurgeStrategy/ImportRunBasedPurgeStrategy.php b/library/Director/Import/PurgeStrategy/ImportRunBasedPurgeStrategy.php index 4e37b8bb..c48acedf 100644 --- a/library/Director/Import/PurgeStrategy/ImportRunBasedPurgeStrategy.php +++ b/library/Director/Import/PurgeStrategy/ImportRunBasedPurgeStrategy.php @@ -70,11 +70,12 @@ class ImportRunBasedPurgeStrategy extends PurgeStrategy return array(); } - if ($rule->object_type === 'service') { + if ($rule->hasCombinedKey()) { $pattern = $rule->getSourceKeyPattern(); $columns = SyncUtils::getRootVariables( SyncUtils::extractVariableNames($pattern) ); + $rows = $runA->fetchRows($columns, null, $result); $result = array(); foreach ($rows as $row) { diff --git a/library/Director/Import/Sync.php b/library/Director/Import/Sync.php index b8eaafcf..28fc4828 100644 --- a/library/Director/Import/Sync.php +++ b/library/Director/Import/Sync.php @@ -101,7 +101,7 @@ class Sync foreach ($objects as $object) { if ($object->hasBeenModified()) { $modified[] = $object; - } elseif ($object instanceof IcingaObject && $object->shouldBeRemoved()) { + } elseif ($object->shouldBeRemoved()) { $modified[] = $object; } } @@ -313,7 +313,7 @@ class Sync $no = array(); foreach ($this->objects as $k => $o) { - if ($o->list_id !== $listId) { + if ((int) $o->list_id !== (int) $listId) { $no[] = $k; } } @@ -557,13 +557,13 @@ class Sync if ($object->hasBeenModified()) { throw new IcingaException( 'Sync is not allowed to modify template "%s"', - $object->$objectKey + $object->object_name ); } continue; } - if ($object instanceof IcingaObject && $object->shouldBeRemoved()) { + if ($object->shouldBeRemoved()) { $object->delete($db); $deleted++; continue; diff --git a/library/Director/Import/SyncUtils.php b/library/Director/Import/SyncUtils.php index 386f8d9d..6a48ef7b 100644 --- a/library/Director/Import/SyncUtils.php +++ b/library/Director/Import/SyncUtils.php @@ -3,7 +3,7 @@ namespace Icinga\Module\Director\Import; use Icinga\Exception\IcingaException; -use Icinga\Module\Director\Objects\IcingaObject; +use Icinga\Module\Director\Data\Db\DbObject; class SyncUtils { @@ -65,7 +65,7 @@ class SyncUtils public static function getSpecificValue($row, $var) { if (strpos($var, '.') === false) { - if ($row instanceof IcingaObject) { + if ($row instanceof DbObject) { return $row->$var; } if (! property_exists($row, $var)) { diff --git a/library/Director/Objects/DirectorDatalistEntry.php b/library/Director/Objects/DirectorDatalistEntry.php index 339fb376..de07b060 100644 --- a/library/Director/Objects/DirectorDatalistEntry.php +++ b/library/Director/Objects/DirectorDatalistEntry.php @@ -19,6 +19,20 @@ class DirectorDatalistEntry extends DbObject 'format' => null, ); + public function replaceWith(DirectorDatalistEntry $object) + { + $this->entry_value = $object->entry_value; + if ($object->format) { + $this->format = $object->format; + } + + return $this; + } + + public function merge(DirectorDatalistEntry $object) + { + return $this->replaceWith($object); + } public function markForRemoval($remove = true) { diff --git a/library/Director/Objects/SyncRule.php b/library/Director/Objects/SyncRule.php index 7193d801..210edac4 100644 --- a/library/Director/Objects/SyncRule.php +++ b/library/Director/Objects/SyncRule.php @@ -253,6 +253,7 @@ class SyncRule extends DbObject $this->hasCombinedKey = false; + // TODO: Move to Objects if ($this->object_type === 'service') { $hasHost = false; $hasObjectName = false; @@ -276,6 +277,30 @@ class SyncRule extends DbObject $this->destinationKeyPattern = '${host}!${object_name}'; } + } elseif ($this->object_type === 'datalistEntry') { + $hasList = false; + $hasName = false; + + foreach ($this->getSyncProperties() as $key => $property) { + if ($property->destination_field === 'list_id') { + $hasList = $property->source_expression; + } + if ($property->destination_field === 'entry_name') { + $hasName = $property->source_expression; + } + } + + if ($hasList !== false && $hasName !== false) { + $this->hasCombinedKey = true; + $this->sourceKeyPattern = sprintf( + '%s!%s', + $hasList, + $hasName + ); + + $this->destinationKeyPattern = '${list_id}!${entry_name}'; + } + } }