mirror of
https://github.com/Icinga/icingaweb2-module-director.git
synced 2025-09-25 10:57:41 +02:00
IcingaArguments: test and fix modification tracking
This fixes related behaviour when working on CLI, API or through Sync Rules - but not web forms refs #12266
This commit is contained in:
parent
a4d6ed1b6e
commit
6258230fdb
@ -91,6 +91,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||||||
if ($this->arguments[$key]->hasBeenModified()) {
|
if ($this->arguments[$key]->hasBeenModified()) {
|
||||||
$this->modified = true;
|
$this->modified = true;
|
||||||
}
|
}
|
||||||
|
} elseif (array_key_exists($key, $this->storedArguments)) {
|
||||||
|
$this->arguments[$key] = clone($this->storedArguments[$key]);
|
||||||
|
$this->arguments[$key]->replaceWith($argument);
|
||||||
|
if ($this->arguments[$key]->hasBeenModified()) {
|
||||||
|
$this->modified = true;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$this->add($argument);
|
$this->add($argument);
|
||||||
$this->modified = true;
|
$this->modified = true;
|
||||||
@ -191,8 +197,12 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||||||
array_keys($this->arguments),
|
array_keys($this->arguments),
|
||||||
array_keys($arguments)
|
array_keys($arguments)
|
||||||
) as $arg) {
|
) as $arg) {
|
||||||
|
if ($this->arguments[$arg]->hasBeenLoadedFromDb()) {
|
||||||
$this->arguments[$arg]->markForRemoval();
|
$this->arguments[$arg]->markForRemoval();
|
||||||
$this->modified = true;
|
$this->modified = true;
|
||||||
|
} else {
|
||||||
|
unset($this->arguments[$arg]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
@ -336,6 +346,7 @@ class IcingaArguments implements Iterator, Countable, IcingaConfigRenderer
|
|||||||
unset($this->arguments[$key]);
|
unset($this->arguments[$key]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$this->cloneStored();
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,6 +58,76 @@ class IcingaCommandTest extends BaseTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testCanBePersistedToDb()
|
||||||
|
{
|
||||||
|
if ($this->skipForMissingDb()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = $this->getDb();
|
||||||
|
|
||||||
|
$command = $this->newCommandWithArguments();
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
$command->store($db),
|
||||||
|
true
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
$command->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanBeLoadedFromDb()
|
||||||
|
{
|
||||||
|
if ($this->skipForMissingDb()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = $this->getDb();
|
||||||
|
|
||||||
|
$name = $this->testCommandName;
|
||||||
|
$command = $this->newCommandWithArguments($db);
|
||||||
|
$command->store($db);
|
||||||
|
|
||||||
|
$command = IcingaCommand::load($name, $db);
|
||||||
|
$this->assertEquals(
|
||||||
|
$command->object_name,
|
||||||
|
$name
|
||||||
|
);
|
||||||
|
|
||||||
|
$command->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testArgumentMotificationsAreDetected()
|
||||||
|
{
|
||||||
|
if ($this->skipForMissingDb()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = $this->getDb();
|
||||||
|
|
||||||
|
$command = $this->newCommandWithArguments($db);
|
||||||
|
$command->store($db);
|
||||||
|
$command->arguments()->set('-H', 'no-host');
|
||||||
|
$this->assertTrue($command->hasBeenModified());
|
||||||
|
$this->assertTrue($command->store());
|
||||||
|
$command->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function newCommandWithArguments()
|
||||||
|
{
|
||||||
|
$command = $this->command();
|
||||||
|
$command->arguments = array(
|
||||||
|
'-H' => '$host$',
|
||||||
|
'-x' => (object) array(
|
||||||
|
'required' => true,
|
||||||
|
'value' => 'bal'
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
return $command;
|
||||||
|
}
|
||||||
|
|
||||||
public function testAbsolutePathsAreDetected()
|
public function testAbsolutePathsAreDetected()
|
||||||
{
|
{
|
||||||
$command = $this->command();
|
$command = $this->command();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user