icingaweb2-module-director/application/controllers/IndexController.php

80 lines
2.5 KiB
PHP
Raw Normal View History

<?php
2015-10-20 22:34:04 +02:00
namespace Icinga\Module\Director\Controllers;
2016-03-13 23:48:22 +01:00
use Exception;
2020-10-26 18:50:13 +01:00
use gipfl\Web\Widget\Hint;
use Icinga\Module\Director\Db\Migrations;
use Icinga\Module\Director\Forms\ApplyMigrationsForm;
2018-06-07 23:37:28 +02:00
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()) {
2017-06-22 02:09:31 +02:00
$this->content()->prepend(
ApplyMigrationsForm::load()
->setMigrations($migrations)
->handleRequest()
);
} elseif ($migrations->hasBeenDowngraded()) {
2020-10-26 18:50:13 +01:00
$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');
}
2016-04-22 11:19:54 +02:00
} else {
$this->addTitle(sprintf(
$this->translate('Icinga Director Setup: %s'),
$this->translate('Choose DB Resource')
));
$this->addSingleTab('Setup');
$this->showKickstartForm();
2016-04-22 11:19:54 +02:00
}
2016-04-22 14:31:41 +02:00
}
protected function showKickstartForm()
2016-04-22 15:51:38 +02:00
{
2018-10-08 06:18:32 +02:00
$form = KickstartForm::load();
if ($name = $this->getPreferredDbResourceName()) {
$form->setDbResourceName($name);
}
$this->content()->prepend($form->handleRequest());
2016-04-22 11:19:54 +02:00
}
protected function hasDeploymentEndpoint()
{
try {
$this->hasDeploymentEndpoint = $this->db()->hasDeploymentEndpoint();
} catch (Exception $e) {
return false;
2015-12-18 10:51:38 +01:00
}
return $this->hasDeploymentEndpoint;
}
}