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();
|
$imported = array();
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
$rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
|
||||||
$key = $source->key_column;
|
$key = $source->key_column;
|
||||||
|
$sourceColumns[$sourceId][$key] = $key;
|
||||||
|
$rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
||||||
|
|
||||||
$imported[$sourceId] = array();
|
$imported[$sourceId] = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
if (! property_exists($row, $key)) {
|
if (! property_exists($row, $key)) {
|
||||||
|
@ -78,7 +80,9 @@ class Sync
|
||||||
// TODO: Filter auf object, nicht template
|
// TODO: Filter auf object, nicht template
|
||||||
$objects = IcingaHost::loadAll($db, null, 'object_name');
|
$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) {
|
foreach ($imported[$sourceId] as $key => $row) {
|
||||||
$newProps = array(
|
$newProps = array(
|
||||||
'object_type' => 'object',
|
'object_type' => 'object',
|
||||||
|
@ -88,6 +92,8 @@ class Sync
|
||||||
$newVars = array();
|
$newVars = array();
|
||||||
|
|
||||||
foreach ($properties as $p) {
|
foreach ($properties as $p) {
|
||||||
|
if ($p->source_id !== $sourceId) continue;
|
||||||
|
|
||||||
$prop = $p->destination_field;
|
$prop = $p->destination_field;
|
||||||
$val = $this->fillVariables($p->source_expression, $row);
|
$val = $this->fillVariables($p->source_expression, $row);
|
||||||
|
|
||||||
|
@ -106,6 +112,7 @@ class Sync
|
||||||
$objects[$key]->vars()->$prop = $var;
|
$objects[$key]->vars()->$prop = $var;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'merge':
|
case 'merge':
|
||||||
$object = $objects[$key];
|
$object = $objects[$key];
|
||||||
foreach ($newProps as $prop => $value) {
|
foreach ($newProps as $prop => $value) {
|
||||||
|
@ -117,6 +124,7 @@ class Sync
|
||||||
$object->vars()->$prop = $var;
|
$object->vars()->$prop = $var;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
// policy 'ignore', no action
|
// policy 'ignore', no action
|
||||||
}
|
}
|
||||||
|
@ -126,6 +134,9 @@ class Sync
|
||||||
$objects[$key]->vars()->$prop = $var;
|
$objects[$key]->vars()->$prop = $var;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$dba = $db->getDbAdapter();
|
$dba = $db->getDbAdapter();
|
||||||
$dba->beginTransaction();
|
$dba->beginTransaction();
|
||||||
|
@ -156,12 +167,13 @@ class Sync
|
||||||
$object->delete();
|
$object->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (! $object->object_name) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
$object->store($db);
|
$object->store($db);
|
||||||
}
|
}
|
||||||
|
|
||||||
$dba->commit();
|
$dba->commit();
|
||||||
}
|
|
||||||
|
|
||||||
return 42; // We have no sync_run history table yet
|
return 42; // We have no sync_run history table yet
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue