mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
Sync: simplifying prepareSyncForRule() method
This commit is contained in:
parent
c6842520d9
commit
e34b0e0d95
@ -177,38 +177,45 @@ class Sync
|
|||||||
return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string);
|
return preg_replace_callback('/\${([A-Za-z0-9\._-]+)}/', $func, $string);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected function perpareImportSources($properties, $db)
|
||||||
* Evaluates a SyncRule and returns a list of modified objects
|
|
||||||
*
|
|
||||||
* TODO: This needs to be splitted into smaller methods
|
|
||||||
*
|
|
||||||
* @param SyncRule $rule The synchronization rule that should be used
|
|
||||||
*
|
|
||||||
* @return array List of modified IcingaObjects
|
|
||||||
*/
|
|
||||||
protected function prepareSyncForRule(SyncRule $rule)
|
|
||||||
{
|
{
|
||||||
$db = $rule->getConnection();
|
|
||||||
$properties = $rule->fetchSyncProperties();
|
|
||||||
$sourceColumns = array();
|
|
||||||
$sources = array();
|
$sources = array();
|
||||||
|
|
||||||
// $fieldMap = array();
|
|
||||||
|
|
||||||
foreach ($properties as $p) {
|
foreach ($properties as $p) {
|
||||||
$sourceId = $p->source_id;
|
$sourceId = $p->source_id;
|
||||||
if (! array_key_exists($sourceId, $sources)) {
|
if (! array_key_exists($sourceId, $sources)) {
|
||||||
$sources[$sourceId] = ImportSource::load($sourceId, $db);
|
$sources[$sourceId] = ImportSource::load($sourceId, $db);
|
||||||
$sourceColumns[$sourceId] = array();
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sources;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function prepareSourceColumns($properties)
|
||||||
|
{
|
||||||
|
// $fieldMap = array();
|
||||||
|
$columns = array();
|
||||||
|
|
||||||
|
foreach ($properties as $p) {
|
||||||
|
$sourceId = $p->source_id;
|
||||||
|
if (! array_key_exists($sourceId, $sources)) {
|
||||||
|
$columns[$sourceId] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->extractVariableNames($p->source_expression) as $varname) {
|
foreach ($this->extractVariableNames($p->source_expression) as $varname) {
|
||||||
$sourceColumns[$sourceId][$varname] = $varname;
|
$columns[$sourceId][$varname] = $varname;
|
||||||
// -> ? $fieldMap[
|
// -> ? $fieldMap[
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $columns;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function fetchImportedData($sources, $properties, $db)
|
||||||
|
{
|
||||||
$imported = array();
|
$imported = array();
|
||||||
|
|
||||||
|
$sourceColumns = $this->prepareSourceColumns($properties);
|
||||||
|
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
$key = $source->key_column;
|
$key = $source->key_column;
|
||||||
@ -232,6 +239,25 @@ class Sync
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $imported;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Evaluates a SyncRule and returns a list of modified objects
|
||||||
|
*
|
||||||
|
* TODO: This needs to be splitted into smaller methods
|
||||||
|
*
|
||||||
|
* @param SyncRule $rule The synchronization rule that should be used
|
||||||
|
*
|
||||||
|
* @return array List of modified IcingaObjects
|
||||||
|
*/
|
||||||
|
protected function prepareSyncForRule(SyncRule $rule)
|
||||||
|
{
|
||||||
|
$db = $rule->getConnection();
|
||||||
|
$properties = $rule->fetchSyncProperties();
|
||||||
|
$sources = $this->perpareImportSources($properties, $db);
|
||||||
|
$imported = $this->fetchImportedData($sources, $properties, $db);
|
||||||
|
|
||||||
// TODO: Filter auf object, nicht template
|
// TODO: Filter auf object, nicht template
|
||||||
$objects = IcingaObject::loadAllByType($rule->object_type, $db);
|
$objects = IcingaObject::loadAllByType($rule->object_type, $db);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user