CustomVariable: improve modification handling

This commit is contained in:
Thomas Gelf 2015-08-28 18:36:16 +02:00
parent b9a4820515
commit 053854e2c6
2 changed files with 21 additions and 5 deletions

View File

@ -100,6 +100,12 @@ abstract class CustomVariable implements IcingaConfigRenderer
return $this->setModified(false);
}
public function setLoadedFromDb($loaded = true)
{
$this->loadedFromDb = $loaded;
return $this;
}
abstract public function equals(CustomVariable $var);
public function differsFrom(CustomVariable $var)
@ -166,6 +172,7 @@ abstract class CustomVariable implements IcingaConfigRenderer
}
$var->loadedFromDb = true;
$var->modified = false;
return $var;
}

View File

@ -43,13 +43,22 @@ class CustomVariableArray extends CustomVariable
$new[] = self::wantCustomVariable($k, $v);
}
// WTF?
if ($this->value === $new) {
return $this;
$equals = true;
if (is_array($this->value) && count($new) === count($this->value)) {
foreach ($this->value as $k => $v) {
if (! $new[$k]->equals($v)) {
$equals = false;
break;
}
}
} else {
$equals = false;
}
$this->value = $new;
$this->setModified();
if (! $equals) {
$this->value = $new;
$this->setModified();
}
return $this;
}