icingaweb2-module-director/application/controllers/IndexController.php
Eric Lippmann b6af283732 License source files as GPL-3.0-or-later
Add SPDX license headers and mark source files as GPL-3.0-or-later to
preserve the option to relicense under later GPL versions.
2026-03-24 11:30:06 +01:00

82 lines
2.6 KiB
PHP

<?php
// SPDX-FileCopyrightText: 2018 Icinga GmbH <https://icinga.com>
// SPDX-License-Identifier: GPL-3.0-or-later
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;
}
}