From be8119f96407063394a67f2f306bd0f0205acd1a Mon Sep 17 00:00:00 2001 From: Sukhwinder Dhillon Date: Mon, 18 Aug 2025 12:33:18 +0200 Subject: [PATCH] `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 --- library/Businessprocess/BpConfig.php | 11 +++++++++++ library/Businessprocess/Web/Controller.php | 6 +++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/library/Businessprocess/BpConfig.php b/library/Businessprocess/BpConfig.php index 1d8b032..548d09d 100644 --- a/library/Businessprocess/BpConfig.php +++ b/library/Businessprocess/BpConfig.php @@ -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++; diff --git a/library/Businessprocess/Web/Controller.php b/library/Businessprocess/Web/Controller.php index d8d1d63..71eac44 100644 --- a/library/Businessprocess/Web/Controller.php +++ b/library/Businessprocess/Web/Controller.php @@ -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; }