Commit 6046d0bf authored by Navid Sassan's avatar Navid Sassan
Browse files

fixed 'Trying to recreate service' occuring

the error occured when importing a service set which includes a service
with a changed name but with a guid already
parent a56ff2b8
......@@ -222,11 +222,28 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface
's.*'
)->where('service_set_id = ?', $setId);
$existingServices = IcingaService::loadAll($db, $sQuery, 'object_name');
$existingServicesGuid = IcingaService::loadAll($db, $sQuery, 'guid');
$newServicesGuids = array();
foreach ($services as $service) {
if (isset($service->fields)) {
unset($service->fields);
}
if (isset($service->guid)) {
$guid = $service->guid;
echo "$service->object_name\n";
if (isset($existingServicesGuid[$guid])) {
$existing = $existingServicesGuid[$guid];
$existing->setProperties((array) $service);
$existing->set('service_set_id', $setId);
if ($existing->hasBeenModified()) {
$existing->store();
}
unset($existingServicesGuid[$guid]);
continue;
}
}
$name = $service->object_name;
if (isset($existingServices[$name])) {
$existing = $existingServices[$name];
......@@ -236,11 +253,12 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface
$existing->store();
}
unset($existingServices[$name]);
} else {
$new = IcingaService::create((array) $service, $db);
$new->set('service_set_id', $setId);
$new->store();
continue;
}
$new = IcingaService::create((array) $service, $db);
$new->set('service_set_id', $setId);
$new->store();
}
// remove all services from $existingServices that are not in $services (aka delete services that are not part of the basket import)
foreach ($existingServices as $name => $service) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment