Sync: fix sync & purge for datalistEntry objects

This commit is contained in:
Thomas Gelf 2016-10-05 17:45:25 +00:00
parent c859055221
commit e9a570e96d
5 changed files with 47 additions and 7 deletions

View File

@ -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) {

View File

@ -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;

View File

@ -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)) {

View File

@ -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)
{

View File

@ -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}';
}
}
}