index/kickstart: offer schema creation
This commit is contained in:
parent
ead2bf8fb0
commit
07db0034dc
|
@ -2,6 +2,7 @@
|
|||
|
||||
namespace Icinga\Module\Director\Controllers;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Module\Director\Web\Controller\ActionController;
|
||||
|
||||
class IndexController extends ActionController
|
||||
|
@ -22,11 +23,23 @@ class IndexController extends ActionController
|
|||
return;
|
||||
}
|
||||
|
||||
$this->view->hasDeploymentEndpoint = $this->db()->hasDeploymentEndpoint();
|
||||
$this->view->stats = $this->db()->getObjectSummary();
|
||||
$this->view->undeployedActivities = $this->db()->countActivitiesSinceLastDeployedConfig();
|
||||
if ((int) $this->view->stats['apiuser']->cnt_total === 0) {
|
||||
if (! $this->fetchStats()
|
||||
|| (int) $this->view->stats['apiuser']->cnt_total === 0
|
||||
) {
|
||||
$this->view->form = $this->loadForm('kickstart')->setDb($this->db)->handleRequest();
|
||||
}
|
||||
}
|
||||
|
||||
protected function fetchStats()
|
||||
{
|
||||
try {
|
||||
$this->view->hasDeploymentEndpoint = $this->db()->hasDeploymentEndpoint();
|
||||
$this->view->stats = $this->db()->getObjectSummary();
|
||||
$this->view->undeployedActivities = $this->db()->countActivitiesSinceLastDeployedConfig();
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
namespace Icinga\Module\Director\Forms;
|
||||
|
||||
use Exception;
|
||||
use Icinga\Module\Director\Db\Migrations;
|
||||
use Icinga\Module\Director\KickstartHelper;
|
||||
use Icinga\Module\Director\Web\Form\QuickForm;
|
||||
|
||||
|
@ -10,8 +11,21 @@ class KickstartForm extends QuickForm
|
|||
{
|
||||
protected $db;
|
||||
|
||||
protected $createDbLabel;
|
||||
|
||||
public function setup()
|
||||
{
|
||||
$this->createDbLabel = $this->translate('Create database schema');
|
||||
if (!$this->migrations()->hasSchema()) {
|
||||
|
||||
$this->addHtmlHint($this->translate(
|
||||
'No database schema has been created yet'
|
||||
));
|
||||
|
||||
$this->setSubmitLabel($this->createDbLabel);
|
||||
return ;
|
||||
}
|
||||
|
||||
$this->addHtmlHint(
|
||||
$this->translate(
|
||||
'Your installation of Icinga Director has not yet been prepared for deployments.'
|
||||
|
@ -73,11 +87,15 @@ class KickstartForm extends QuickForm
|
|||
public function onSuccess()
|
||||
{
|
||||
try {
|
||||
if ($this->getSubmitLabel() === $this->createDbLabel) {
|
||||
$this->migrations()->applyPendingMigrations();
|
||||
return parent::onSuccess();
|
||||
}
|
||||
$kickstart = new KickstartHelper($this->db);
|
||||
$kickstart->setConfig($this->getValues())->run();
|
||||
parent::onSuccess();
|
||||
} catch (Exception $e) {
|
||||
$this->getElement('endpoint')->addError($e->getMessage());
|
||||
$this->addError($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,4 +108,9 @@ class KickstartForm extends QuickForm
|
|||
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function migrations()
|
||||
{
|
||||
return new Migrations($this->db);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
<p class="error"><?= $this->errorMessage ?></p>
|
||||
<?php endif ?>
|
||||
<?php if (! $this->stats): ?>
|
||||
<?= $this->form ?>
|
||||
</div>
|
||||
<?php return; endif ?>
|
||||
<?php
|
||||
|
|
Loading…
Reference in New Issue