Kickstart: deal with multiple DBs

This commit is contained in:
Thomas Gelf 2018-10-08 06:18:32 +02:00
parent 8cec78a7c3
commit fa70ecde0e
2 changed files with 29 additions and 10 deletions

View File

@ -22,7 +22,6 @@ class IndexController extends DashboardController
} }
} else { } else {
$this->showKickstartForm(); $this->showKickstartForm();
return;
} }
if ($migrations->hasPendingMigrations()) { if ($migrations->hasPendingMigrations()) {
@ -45,7 +44,11 @@ class IndexController extends DashboardController
$this->addSingleTab($this->translate('Kickstart')); $this->addSingleTab($this->translate('Kickstart'));
} }
$this->content()->prepend(KickstartForm::load()->handleRequest()); $form = KickstartForm::load();
if ($name = $this->getPreferredDbResourceName()) {
$form->setDbResourceName($name);
}
$this->content()->prepend($form->handleRequest());
} }
protected function hasDeploymentEndpoint() protected function hasDeploymentEndpoint()

View File

@ -26,8 +26,9 @@ class KickstartForm extends DirectorForm
/** @var IcingaEndpoint */ /** @var IcingaEndpoint */
private $endpoint; private $endpoint;
private $dbResourceName;
/** /**
* @throws \Icinga\Exception\IcingaException
* @throws \Zend_Form_Exception * @throws \Zend_Form_Exception
*/ */
public function setup() public function setup()
@ -36,6 +37,7 @@ class KickstartForm extends DirectorForm
$this->createDbLabel = $this->translate('Create database schema'); $this->createDbLabel = $this->translate('Create database schema');
$this->migrateDbLabel = $this->translate('Apply schema migrations'); $this->migrateDbLabel = $this->translate('Apply schema migrations');
if ($this->dbResourceName === null) {
$this->addResourceConfigElements(); $this->addResourceConfigElements();
$this->addResourceDisplayGroup(); $this->addResourceDisplayGroup();
@ -43,6 +45,7 @@ class KickstartForm extends DirectorForm
|| ($this->config()->get('db', 'resource') !== $this->getResourceName())) { || ($this->config()->get('db', 'resource') !== $this->getResourceName())) {
return; return;
} }
}
if (!$this->migrations()->hasSchema()) { if (!$this->migrations()->hasSchema()) {
$this->addHtmlHint($this->translate( $this->addHtmlHint($this->translate(
@ -266,6 +269,10 @@ class KickstartForm extends DirectorForm
*/ */
protected function addResourceDisplayGroup() protected function addResourceDisplayGroup()
{ {
if ($this->dbResourceName !== null) {
return;
}
$elements = array( $elements = array(
'HINT_no_resource', 'HINT_no_resource',
'resource', 'resource',
@ -353,7 +360,6 @@ class KickstartForm extends DirectorForm
} }
/** /**
* @throws \Icinga\Exception\IcingaException
* @throws \Icinga\Exception\ProgrammingError * @throws \Icinga\Exception\ProgrammingError
* @throws \Zend_Form_Exception * @throws \Zend_Form_Exception
*/ */
@ -385,8 +391,19 @@ class KickstartForm extends DirectorForm
parent::onSuccess(); parent::onSuccess();
} }
public function setDbResourceName($name)
{
$this->dbResourceName = $name;
return $this;
}
protected function getResourceName() protected function getResourceName()
{ {
if ($this->dbResourceName !== null) {
return $this->dbResourceName;
}
if ($this->hasBeenSent()) { if ($this->hasBeenSent()) {
$resource = $this->getSentValue('resource'); $resource = $this->getSentValue('resource');
$resources = $this->enumResources(); $resources = $this->enumResources();
@ -412,7 +429,6 @@ class KickstartForm extends DirectorForm
/** /**
* @return Migrations * @return Migrations
* @throws \Icinga\Exception\IcingaException
*/ */
protected function migrations() protected function migrations()
{ {