CustomVariables: handle deleted vars

This commit is contained in:
Thomas Gelf 2015-07-31 14:35:49 +02:00
parent 4780e11241
commit 3a96f9ebe4

View File

@ -89,7 +89,12 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
protected function refreshIndex() protected function refreshIndex()
{ {
$this->idx = array_keys($this->vars); $this->idx = array();
foreach ($this->vars as $name => $var) {
if (! $var->hasBeenDeleted()) {
$this->idx[] = $name;
}
}
} }
public static function loadForStoredObject(IcingaObject $object) public static function loadForStoredObject(IcingaObject $object)
@ -223,10 +228,11 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer
public function __unset($key) public function __unset($key)
{ {
if (! array_key_exists($key, $this->vars)) { if (! array_key_exists($key, $this->vars)) {
throw new Exception('Trying to unset invalid key'); return;
} }
unset($this->vars[$key]); $this->vars[$key]->delete();
$this->modified = true;
$this->refreshIndex(); $this->refreshIndex();
} }