mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-28 16:24:05 +02:00
Sync: simplify methods, do not pass $db
This commit is contained in:
parent
650ef67dc6
commit
22e3d72014
@ -202,13 +202,13 @@ 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)
|
protected function perpareImportSources($properties)
|
||||||
{
|
{
|
||||||
$sources = array();
|
$sources = 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, $this->db);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -268,7 +268,6 @@ class Sync
|
|||||||
{
|
{
|
||||||
$imported = array();
|
$imported = array();
|
||||||
$rule = $this->rule;
|
$rule = $this->rule;
|
||||||
$db = $this->db;
|
|
||||||
|
|
||||||
$sourceColumns = $this->prepareSourceColumns($properties);
|
$sourceColumns = $this->prepareSourceColumns($properties);
|
||||||
|
|
||||||
@ -276,7 +275,7 @@ class Sync
|
|||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
$key = $source->key_column;
|
$key = $source->key_column;
|
||||||
$sourceColumns[$sourceId][$key] = $key;
|
$sourceColumns[$sourceId][$key] = $key;
|
||||||
$rows = $db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
$rows = $this->db->fetchLatestImportedRows($sourceId, $sourceColumns[$sourceId]);
|
||||||
|
|
||||||
$imported[$sourceId] = array();
|
$imported[$sourceId] = array();
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
@ -348,9 +347,8 @@ class Sync
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function prepareNewObjects($rule, & $properties, & $sources, & $imported)
|
protected function prepareNewObjects(& $properties, & $sources, & $imported)
|
||||||
{
|
{
|
||||||
$db = $rule->getConnection();
|
|
||||||
$newObjects = array();
|
$newObjects = array();
|
||||||
|
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
@ -385,16 +383,16 @@ class Sync
|
|||||||
}
|
}
|
||||||
if (! array_key_exists($key, $newObjects)) {
|
if (! array_key_exists($key, $newObjects)) {
|
||||||
$newObjects[$key] = IcingaObject::createByType(
|
$newObjects[$key] = IcingaObject::createByType(
|
||||||
$rule->object_type,
|
$this->rule->object_type,
|
||||||
array(),
|
array(),
|
||||||
$db
|
$this->db
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
$object = $newObjects[$key];
|
$object = $newObjects[$key];
|
||||||
|
|
||||||
// Safe default values for object_type and object_name
|
// Safe default values for object_type and object_name
|
||||||
if ($rule->object_type !== 'datalistEntry') {
|
if ($this->rule->object_type !== 'datalistEntry') {
|
||||||
if (! array_key_exists('object_type', $newProps)
|
if (! array_key_exists('object_type', $newProps)
|
||||||
|| $newProps['object_type'] === null
|
|| $newProps['object_type'] === null
|
||||||
) {
|
) {
|
||||||
@ -452,7 +450,6 @@ class Sync
|
|||||||
|
|
||||||
// TODO: directly work on existing objects, remember imported keys, then purge
|
// TODO: directly work on existing objects, remember imported keys, then purge
|
||||||
$newObjects = $this->prepareNewObjects(
|
$newObjects = $this->prepareNewObjects(
|
||||||
$rule,
|
|
||||||
$properties,
|
$properties,
|
||||||
$sources,
|
$sources,
|
||||||
$imported
|
$imported
|
||||||
|
Loading…
x
Reference in New Issue
Block a user