ProcessChanges::ApplyChanges(): Apply db states before applying changes

On drag & drop, nodes are sorted by `display_name asc` using aliases if
available. Previously, backend states were not applied at save time, so
aliases were unavailable and nodes fell back to sorting by node name,
producing a different sort order and causing a node to be removed
unexpectedly in some cases.

Add if condition to only call `applyChanges()` if changes exist
This commit is contained in:
Sukhwinder Dhillon 2025-08-18 12:33:18 +02:00 committed by Eric Lippmann
parent 96137e0df1
commit be8119f964
2 changed files with 16 additions and 1 deletions

View file

@ -12,6 +12,8 @@ use Icinga\Exception\NotFoundError;
use Icinga\Module\Businessprocess\Exception\NestingError;
use Icinga\Module\Businessprocess\Modification\ProcessChanges;
use Icinga\Module\Businessprocess\ProvidedHook\Icingadb\IcingadbSupport;
use Icinga\Module\Businessprocess\State\IcingaDbState;
use Icinga\Module\Businessprocess\State\MonitoringState;
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
use Icinga\Module\Monitoring\Backend\MonitoringBackend;
use ipl\Sql\Connection as IcingaDbConnection;
@ -177,6 +179,15 @@ class BpConfig
*/
public function applyChanges(ProcessChanges $changes)
{
if (
Module::exists('icingadb')
&& (! $this->hasBackendName() && IcingadbSupport::useIcingaDbAsBackend())
) {
IcingaDbState::apply($this);
} else {
MonitoringState::apply($this);
}
$cnt = 0;
foreach ($changes->getChanges() as $change) {
$cnt++;

View file

@ -199,7 +199,11 @@ class Controller extends CompatController
$changes->clear();
$this->redirectNow($this->url()->without('dismissChanges')->without('unlocked'));
}
$bp->applyChanges($changes);
if (! $changes->isEmpty()) {
$bp->applyChanges($changes);
}
return $bp;
}