diff --git a/application/clicommands/MigrateCommand.php b/application/clicommands/MigrateCommand.php index e084a954c..5d2280044 100644 --- a/application/clicommands/MigrateCommand.php +++ b/application/clicommands/MigrateCommand.php @@ -63,6 +63,8 @@ public function navigationAction(): void $rc = 0; $directories = file_exists($preferencesPath) ? new DirectoryIterator($preferencesPath) : []; + $anythingChanged = false; + /** @var string $directory */ foreach ($directories as $directory) { /** @var string $username */ @@ -87,14 +89,15 @@ public function navigationAction(): void if (! $menuItems->isEmpty()) { $menuUpdated = $this->transformNavigationItems($menuItems, $username, $rc); + $anythingChanged |= $menuUpdated; } if (! $icingadbHostActions->isEmpty()) { - $this->transformNavigationItems($icingadbHostActions, $username, $rc); + $anythingChanged |= $this->transformNavigationItems($icingadbHostActions, $username, $rc); } if (! $icingadbServiceActions->isEmpty()) { - $this->transformNavigationItems( + $anythingChanged |= $this->transformNavigationItems( $icingadbServiceActions, $username, $rc @@ -106,10 +109,11 @@ public function navigationAction(): void if (! $menuItems->isEmpty()) { $menuUpdated = $this->migrateNavigationItems($menuItems, $username, $directory . '/menu.ini', $rc); + $anythingChanged |= $menuUpdated; } if (! $hostActions->isEmpty()) { - $this->migrateNavigationItems( + $anythingChanged |= $this->migrateNavigationItems( $hostActions, $username, $directory . '/icingadb-host-actions.ini', @@ -118,7 +122,7 @@ public function navigationAction(): void } if (! $serviceActions->isEmpty()) { - $this->migrateNavigationItems( + $anythingChanged |= $this->migrateNavigationItems( $serviceActions, $username, $directory . '/icingadb-service-actions.ini', @@ -142,18 +146,19 @@ public function navigationAction(): void $menuUpdated = false; $originalMenuItems = $this->readFromIni($sharedNavigation . '/menu.ini', $rc); - Logger::info('Transforming legacy wildcard filters of existing shared Icinga DB Web'); + Logger::info('Transforming legacy wildcard filters of existing shared Icinga DB Web navigation items'); if (! $menuItems->isEmpty()) { $menuUpdated = $this->transformNavigationItems($menuItems, $user, $rc); + $anythingChanged |= $menuUpdated; } if (! $icingadbHostActions->isEmpty()) { - $this->transformNavigationItems($icingadbHostActions, $user, $rc); + $anythingChanged |= $this->transformNavigationItems($icingadbHostActions, $user, $rc); } if (! $icingadbServiceActions->isEmpty()) { - $this->transformNavigationItems( + $anythingChanged |= $this->transformNavigationItems( $icingadbServiceActions, $user, $rc @@ -161,14 +166,15 @@ public function navigationAction(): void } if (! $this->skipMigration) { - Logger::info('Migrating shared monitoring navigation items to the Icinga DB Web actions'); + Logger::info('Migrating shared monitoring navigation items to the Icinga DB Web items'); if (! $menuItems->isEmpty()) { $menuUpdated = $this->migrateNavigationItems($menuItems, $user, $sharedNavigation . '/menu.ini', $rc); + $anythingChanged |= $menuUpdated; } if (! $hostActions->isEmpty()) { - $this->migrateNavigationItems( + $anythingChanged |= $this->migrateNavigationItems( $hostActions, $user, $sharedNavigation . '/icingadb-host-actions.ini', @@ -177,7 +183,7 @@ public function navigationAction(): void } if (! $serviceActions->isEmpty()) { - $this->migrateNavigationItems( + $anythingChanged |= $this->migrateNavigationItems( $serviceActions, $user, $sharedNavigation . '/icingadb-service-actions.ini', @@ -200,7 +206,9 @@ public function navigationAction(): void exit($rc); } - if ($this->skipMigration) { + if (! $anythingChanged) { + Logger::info('Nothing to do'); + } elseif ($this->skipMigration) { Logger::info('Successfully transformed all icingadb navigation item filters'); } else { Logger::info('Successfully migrated all monitoring navigation items'); @@ -446,6 +454,8 @@ public function dashboardAction(): void $rc = 0; $directories = new DirectoryIterator($dashboardsPath); + $anythingChanged = false; + /** @var string $directory */ foreach ($directories as $directory) { /** @var string $userName */ @@ -505,6 +515,10 @@ public function dashboardAction(): void $this->createBackupIni("$directory/dashboard", $backupConfig); } + if ($changed) { + $anythingChanged = true; + } + try { $dashboardsConfig->saveIni(); } catch (NotWritableError $error) { @@ -523,7 +537,9 @@ public function dashboardAction(): void exit($rc); } - if ($this->skipMigration) { + if (! $anythingChanged) { + Logger::info('Nothing to do'); + } elseif ($this->skipMigration) { Logger::info('Successfully transformed all icingadb dashboards'); } else { Logger::info('Successfully migrated dashboards for all the matched users');