diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-14 13:17:31 +0000 |
commit | f66ab8dae2f3d0418759f81a3a64dc9517a62449 (patch) | |
tree | fbff2135e7013f196b891bbde54618eb050e4aaf /application/controllers/IndexController.php | |
parent | Initial commit. (diff) | |
download | icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.tar.xz icingaweb2-module-director-f66ab8dae2f3d0418759f81a3a64dc9517a62449.zip |
Adding upstream version 1.10.2.upstream/1.10.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'application/controllers/IndexController.php')
-rw-r--r-- | application/controllers/IndexController.php | 79 |
1 files changed, 79 insertions, 0 deletions
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 @@ +<?php + +namespace Icinga\Module\Director\Controllers; + +use Exception; +use gipfl\Web\Widget\Hint; +use Icinga\Module\Director\Db\Migrations; +use Icinga\Module\Director\Forms\ApplyMigrationsForm; +use Icinga\Module\Director\Forms\KickstartForm; +use ipl\Html\Html; + +class IndexController extends DashboardController +{ + protected $hasDeploymentEndpoint; + + public function indexAction() + { + if ($this->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; + } +} |