Delete newly added Services in Service Set when restoring it from snapshot

The Services which were added into the Service Set after the snapshot was created
must be deleted when the Service Set is being restored from the snapshot.
This commit is contained in:
raviks789 2022-01-24 14:05:08 +01:00 committed by Thomas Gelf
parent 420dfcbdbf
commit b04fe28932

View File

@ -219,11 +219,13 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface
's.*'
)->where('service_set_id = ?', $setId);
$existingServices = IcingaService::loadAll($db, $sQuery, 'object_name');
$serviceNames = [];
foreach ($services as $service) {
if (isset($service->fields)) {
unset($service->fields);
}
$name = $service->object_name;
$serviceNames[] = $name;
if (isset($existingServices[$name])) {
$existing = $existingServices[$name];
$existing->setProperties((array) $service);
@ -238,6 +240,12 @@ class IcingaServiceSet extends IcingaObject implements ExportInterface
}
}
foreach ($existingServices as $existing) {
if (!in_array($existing->getObjectName(), $serviceNames)) {
$existing->delete();
}
}
return $object;
}