From f66ab8dae2f3d0418759f81a3a64dc9517a62449 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 14 Apr 2024 15:17:31 +0200 Subject: Adding upstream version 1.10.2. Signed-off-by: Daniel Baumann --- application/controllers/IndexController.php | 79 +++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 application/controllers/IndexController.php (limited to 'application/controllers/IndexController.php') diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php new file mode 100644 index 0000000..3f6c62e --- /dev/null +++ b/application/controllers/IndexController.php @@ -0,0 +1,79 @@ +Config()->get('db', 'resource')) { + $migrations = new Migrations($this->db()); + + if ($migrations->hasSchema()) { + if (!$this->hasDeploymentEndpoint()) { + $this->showKickstartForm(); + } + } + + if ($migrations->hasPendingMigrations()) { + $this->content()->prepend( + ApplyMigrationsForm::load() + ->setMigrations($migrations) + ->handleRequest() + ); + } elseif ($migrations->hasBeenDowngraded()) { + $this->content()->add(Hint::warning(sprintf($this->translate( + 'Your DB schema (migration #%d) is newer than your code base.' + . ' Downgrading Icinga Director is not supported and might' + . ' lead to unexpected problems.' + ), $migrations->getLastMigrationNumber()))); + } + + if ($migrations->hasSchema()) { + parent::indexAction(); + } else { + $this->addTitle(sprintf( + $this->translate('Icinga Director Setup: %s'), + $this->translate('Create Schema') + )); + $this->addSingleTab('Setup'); + } + } else { + $this->addTitle(sprintf( + $this->translate('Icinga Director Setup: %s'), + $this->translate('Choose DB Resource') + )); + $this->addSingleTab('Setup'); + $this->showKickstartForm(); + } + } + + protected function showKickstartForm() + { + $form = KickstartForm::load(); + if ($name = $this->getPreferredDbResourceName()) { + $form->setDbResourceName($name); + } + $this->content()->prepend($form->handleRequest()); + } + + protected function hasDeploymentEndpoint() + { + try { + $this->hasDeploymentEndpoint = $this->db()->hasDeploymentEndpoint(); + } catch (Exception $e) { + return false; + } + + return $this->hasDeploymentEndpoint; + } +} -- cgit v1.2.3