mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-07-31 01:34:12 +02:00
Sync: initial work to support more object types
This commit is contained in:
parent
d4d48a41d8
commit
abd17e8be7
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace Icinga\Module\Director\Import;
|
namespace Icinga\Module\Director\Import;
|
||||||
|
|
||||||
use Icinga\Module\Director\Objects\IcingaHost;
|
use Icinga\Module\Director\Objects\IcingaObject;
|
||||||
use Icinga\Module\Director\Objects\ImportSource;
|
use Icinga\Module\Director\Objects\ImportSource;
|
||||||
use Icinga\Module\Director\Objects\SyncRule;
|
use Icinga\Module\Director\Objects\SyncRule;
|
||||||
|
|
||||||
@ -78,7 +78,9 @@ class Sync
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Filter auf object, nicht template
|
// TODO: Filter auf object, nicht template
|
||||||
$objects = IcingaHost::loadAll($db, null, 'object_name');
|
$objects = IcingaObject::loadAllByType($rule->object_type, $db);
|
||||||
|
$dummy = IcingaObject::createByType($rule->object_type, array());
|
||||||
|
$objectKey = $rule->object_type === 'datalistEntry' ? 'entry_name' : 'object_name';
|
||||||
|
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
$sourceId = $source->id;
|
$sourceId = $source->id;
|
||||||
@ -89,6 +91,10 @@ class Sync
|
|||||||
'object_name' => $key
|
'object_name' => $key
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if ($rule->object_type === 'datalistEntry') {
|
||||||
|
$newProps = array();
|
||||||
|
}
|
||||||
|
|
||||||
$newVars = array();
|
$newVars = array();
|
||||||
$imports = array();
|
$imports = array();
|
||||||
|
|
||||||
@ -112,7 +118,12 @@ class Sync
|
|||||||
if (array_key_exists($key, $objects)) {
|
if (array_key_exists($key, $objects)) {
|
||||||
switch ($rule->update_policy) {
|
switch ($rule->update_policy) {
|
||||||
case 'override':
|
case 'override':
|
||||||
$objects[$key] = IcingaHost::create($newProps);
|
$objects[$key] = IcingaObject::createByType(
|
||||||
|
$rule->object_type,
|
||||||
|
$newProps,
|
||||||
|
$db
|
||||||
|
);
|
||||||
|
|
||||||
foreach ($newVars as $prop => $var) {
|
foreach ($newVars as $prop => $var) {
|
||||||
$objects[$key]->vars()->$prop = $var;
|
$objects[$key]->vars()->$prop = $var;
|
||||||
}
|
}
|
||||||
@ -141,7 +152,7 @@ class Sync
|
|||||||
// policy 'ignore', no action
|
// policy 'ignore', no action
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$objects[$key] = IcingaHost::create($newProps);
|
$objects[$key] = IcingaObject::createByType($rule->object_type, $newProps, $db);
|
||||||
foreach ($newVars as $prop => $var) {
|
foreach ($newVars as $prop => $var) {
|
||||||
$objects[$key]->vars()->$prop = $var;
|
$objects[$key]->vars()->$prop = $var;
|
||||||
}
|
}
|
||||||
@ -157,12 +168,12 @@ class Sync
|
|||||||
$dba = $db->getDbAdapter();
|
$dba = $db->getDbAdapter();
|
||||||
$dba->beginTransaction();
|
$dba->beginTransaction();
|
||||||
foreach ($objects as $object) {
|
foreach ($objects as $object) {
|
||||||
if ($object->isTemplate()) {
|
if ($object instanceof IcingaObject && $object->isTemplate()) {
|
||||||
if ($object->hasBeenModified()) {
|
if ($object->hasBeenModified()) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
sprintf(
|
sprintf(
|
||||||
'Sync is not allowed to modify template "%s"',
|
'Sync is not allowed to modify template "%s"',
|
||||||
$object->object_name
|
$object->$objectKey
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -173,7 +184,7 @@ class Sync
|
|||||||
if ($object->hasBeenLoadedFromDb() && $rule->purge_existing === 'y') {
|
if ($object->hasBeenLoadedFromDb() && $rule->purge_existing === 'y') {
|
||||||
$found = false;
|
$found = false;
|
||||||
foreach ($sources as $source) {
|
foreach ($sources as $source) {
|
||||||
if (array_key_exists($object->object_name, $imported[$source->id])) {
|
if (array_key_exists($object->$objectKey, $imported[$source->id])) {
|
||||||
$found = true;
|
$found = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -183,7 +194,7 @@ class Sync
|
|||||||
$object->delete();
|
$object->delete();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (! $object->object_name) {
|
if (! $object->$objectKey) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
$object->store($db);
|
$object->store($db);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user