From 3a96f9ebe4344ea9c26b2c22cf93e3fb7c20bd0f Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Fri, 31 Jul 2015 14:35:49 +0200 Subject: [PATCH] CustomVariables: handle deleted vars --- library/Director/CustomVariable/CustomVariables.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/library/Director/CustomVariable/CustomVariables.php b/library/Director/CustomVariable/CustomVariables.php index 5c830c1e..31acf9ac 100644 --- a/library/Director/CustomVariable/CustomVariables.php +++ b/library/Director/CustomVariable/CustomVariables.php @@ -89,7 +89,12 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer 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) @@ -223,10 +228,11 @@ class CustomVariables implements Iterator, Countable, IcingaConfigRenderer public function __unset($key) { 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(); }