KickstartHelper: handle renamed zones...

...when triggered multiple times
This commit is contained in:
Thomas Gelf 2016-10-06 16:20:25 +00:00
parent 2c071e215d
commit 081ea72497
1 changed files with 15 additions and 1 deletions

View File

@ -27,6 +27,8 @@ class KickstartHelper
protected $loadedZones; protected $loadedZones;
protected $removeZones;
protected $config = array( protected $config = array(
'endpoint' => null, 'endpoint' => null,
'host' => null, 'host' => null,
@ -101,6 +103,7 @@ class KickstartHelper
->loadZones() ->loadZones()
->storeZones() ->storeZones()
->storeEndpoints() ->storeEndpoints()
->removeZones()
->importCommands(); ->importCommands();
$this->apiUser()->store(); $this->apiUser()->store();
@ -178,6 +181,7 @@ class KickstartHelper
{ {
$db = $this->db; $db = $this->db;
$existing = $db->listExternal('zone'); $existing = $db->listExternal('zone');
foreach ($this->loadedZones as $name => $zone) { foreach ($this->loadedZones as $name => $zone) {
if ($zone::exists($name, $db)) { if ($zone::exists($name, $db)) {
$zone = $zone::load($name, $db)->replaceWith($zone); $zone = $zone::load($name, $db)->replaceWith($zone);
@ -185,7 +189,17 @@ class KickstartHelper
$zone->store(); $zone->store();
unset($existing[$name]); unset($existing[$name]);
} }
foreach ($existing as $name) {
$this->removeZones = $existing;
return $this;
}
protected function removeZones()
{
$db = $this->db;
foreach ($this->removeZones as $name) {
IcingaZone::load($name, $db)->delete(); IcingaZone::load($name, $db)->delete();
} }