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