Sync: start to work with multiple datasources...
...working, but still unfinished
This commit is contained in:
parent
87c1f8c121
commit
68e359cbc0
|
@ -60,8 +60,10 @@ class Sync
|
|||
$imported = array();
|
||||
foreach ($sources as $source) {
|
||||
$sourceId = $source->id;
|
||||
$rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
||||
$key = $source->key_column;
|
||||
$sourceColumns[$sourceId][$key] = $key;
|
||||
$rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
||||
|
||||
$imported[$sourceId] = array();
|
||||
foreach ($rows as $row) {
|
||||
if (! property_exists($row, $key)) {
|
||||
|
@ -78,7 +80,9 @@ class Sync
|
|||
// TODO: Filter auf object, nicht template
|
||||
$objects = IcingaHost::loadAll($db, null, 'object_name');
|
||||
|
||||
// TODO: "hardcoded" single sourceId, fix this!
|
||||
foreach ($sources as $source) {
|
||||
$sourceId = $source->id;
|
||||
|
||||
foreach ($imported[$sourceId] as $key => $row) {
|
||||
$newProps = array(
|
||||
'object_type' => 'object',
|
||||
|
@ -88,6 +92,8 @@ class Sync
|
|||
$newVars = array();
|
||||
|
||||
foreach ($properties as $p) {
|
||||
if ($p->source_id !== $sourceId) continue;
|
||||
|
||||
$prop = $p->destination_field;
|
||||
$val = $this->fillVariables($p->source_expression, $row);
|
||||
|
||||
|
@ -106,6 +112,7 @@ class Sync
|
|||
$objects[$key]->vars()->$prop = $var;
|
||||
}
|
||||
break;
|
||||
|
||||
case 'merge':
|
||||
$object = $objects[$key];
|
||||
foreach ($newProps as $prop => $value) {
|
||||
|
@ -117,6 +124,7 @@ class Sync
|
|||
$object->vars()->$prop = $var;
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
// policy 'ignore', no action
|
||||
}
|
||||
|
@ -126,6 +134,9 @@ class Sync
|
|||
$objects[$key]->vars()->$prop = $var;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
$dba = $db->getDbAdapter();
|
||||
$dba->beginTransaction();
|
||||
|
@ -156,12 +167,13 @@ class Sync
|
|||
$object->delete();
|
||||
}
|
||||
}
|
||||
if (! $object->object_name) {
|
||||
continue;
|
||||
}
|
||||
$object->store($db);
|
||||
}
|
||||
|
||||
$dba->commit();
|
||||
}
|
||||
|
||||
return 42; // We have no sync_run history table yet
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue