Skip to content

Commit

Permalink
NavigationCommand: Introduce override switch to override existing Ici…
Browse files Browse the repository at this point in the history
…nga DB navigation items
  • Loading branch information
raviks789 committed Oct 24, 2023
1 parent ef8b6a3 commit 9ed688e
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion modules/migrate/application/clicommands/NavigationCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ class NavigationCommand extends Command
* --user=<username> Migrate monitoring navigation items only for
* the given user. (Default *)
*
* --override Override the existing Icinga DB navigation items
*
* --delete Remove the legacy files after successfully
* migrated the navigation items.
*/
Expand Down Expand Up @@ -120,6 +122,7 @@ public function indexAction()
private function migrateNavigationItems($config, $path, $shared, &$rc)
{
$deleteLegacyFiles = $this->params->get('delete');
$override = $this->params->get('override');
$newConfig = $this->readFromIni($path, $rc);
$counter = 1;

Expand Down Expand Up @@ -157,7 +160,7 @@ private function migrateNavigationItems($config, $path, $shared, &$rc)

$section = $config->key();

if (! $newConfig->hasSection($section)) {
if (! $newConfig->hasSection($section) || $override) {
$oldPath = $shared
? sprintf(
'%s/%s/%ss.ini',
Expand All @@ -172,6 +175,12 @@ private function migrateNavigationItems($config, $path, $shared, &$rc)
);

$oldConfig = $this->readFromIni($oldPath, $rc);

if ($override && $oldConfig->hasSection($section)) {
$oldConfig->removeSection($section);
$oldConfig->saveIni();
}

if (! $oldConfig->hasSection($section)) {
$newConfig->setSection($section, $configObject);
}
Expand Down

0 comments on commit 9ed688e

Please sign in to comment.