Sync: separate datalist cleanup logic

This commit is contained in:
Thomas Gelf 2016-02-19 12:42:02 +01:00
parent 7141fb2612
commit c1f3e1c041
1 changed files with 30 additions and 24 deletions

View File

@ -257,26 +257,9 @@ 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)
// TODO: This is rubbish, we need to filter at fetch time
protected function removeForeignListEntries(& $objects, & $properties)
{
$db = $rule->getConnection();
$properties = $rule->fetchSyncProperties();
$sources = $this->perpareImportSources($properties, $db);
$imported = $this->fetchImportedData($sources, $properties, $rule, $db);
// TODO: Filter auf object, nicht template
$objects = IcingaObject::loadAllByType($rule->object_type, $db);
if ($rule->object_type === 'datalistEntry') {
$listId = null;
foreach ($properties as $prop) {
if ($prop->destination_field === 'list_id') {
@ -301,6 +284,29 @@ class Sync
unset($objects[$k]);
}
}
/**
* 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, $rule, $db);
// TODO: Make object_type and object_name mandatory?
$objects = IcingaObject::loadAllByType($rule->object_type, $db);
if ($rule->object_type === 'datalistEntry') {
$this->removeForeignListEntries($objects, $properties);
}
$objectKey = $rule->object_type === 'datalistEntry' ? 'entry_name' : 'object_name';
foreach ($sources as $source) {