From 55e0ebd02d885c23210be47a8a8fb1a910c3eee6 Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Mon, 31 Oct 2016 08:34:26 +0000 Subject: [PATCH] kickstart: add new route /kickstart allowing one... ...to re-run the kickstart wizard fixes #13014 --- .../controllers/KickstartController.php | 18 ++++++++ application/forms/KickstartForm.php | 42 ++++++++++++++++--- .../views/scripts/kickstart/index.phtml | 15 +++++++ 3 files changed, 70 insertions(+), 5 deletions(-) create mode 100644 application/controllers/KickstartController.php create mode 100644 application/views/scripts/kickstart/index.phtml diff --git a/application/controllers/KickstartController.php b/application/controllers/KickstartController.php new file mode 100644 index 00000000..e665aa1d --- /dev/null +++ b/application/controllers/KickstartController.php @@ -0,0 +1,18 @@ +singleTab($this->view->title = $this->translate('Kickstart')); + $this->view->form = $this + ->loadForm('kickstart') + ->setEndpoint($this->db()->getDeploymentEndpoint()) + ->handleRequest(); + } +} diff --git a/application/forms/KickstartForm.php b/application/forms/KickstartForm.php index b1da43c5..c8298561 100644 --- a/application/forms/KickstartForm.php +++ b/application/forms/KickstartForm.php @@ -7,18 +7,22 @@ use Icinga\Application\Config; use Icinga\Data\ResourceFactory; use Icinga\Module\Director\Db; use Icinga\Module\Director\Db\Migrations; +use Icinga\Module\Director\Objects\IcingaEndpoint; use Icinga\Module\Director\KickstartHelper; use Icinga\Module\Director\Web\Form\QuickForm; class KickstartForm extends QuickForm { - protected $config; + private $config; - protected $storeConfigLabel; + private $storeConfigLabel; - protected $createDbLabel; + private $createDbLabel; - protected $migrateDbLabel; + private $migrateDbLabel; + + /** @var IcingaEndpoint */ + private $endpoint; public function setup() { @@ -56,7 +60,7 @@ class KickstartForm extends QuickForm return; } - if ($this->getDb()->hasDeploymentEndpoint()) { + if (! $this->endpoint && $this->getDb()->hasDeploymentEndpoint()) { $hint = sprintf($this->translate( 'Your database looks good, you are ready to %s' ), $this->getView()->qlink( @@ -136,6 +140,24 @@ class KickstartForm extends QuickForm 'required' => true, )); + if ($ep = $this->endpoint) { + $user = $ep->getApiUser(); + $this->setDefaults(array( + 'endpoint' => $ep->object_name, + 'host' => $ep->host, + 'port' => $ep->port, + 'username' => $user->object_name, + 'password' => $user->password, + )); + + if (! empty($user->password)) { + $this->getElement('password')->setAttrib( + 'placeholder', + '(use stored password)' + )->setRequired(false); + } + } + $this->addKickstartDisplayGroup(); $this->setSubmitLabel($this->translate('Run import')); } @@ -288,6 +310,12 @@ class KickstartForm extends QuickForm } } + public function setEndpoint(IcingaEndpoint $endpoint) + { + $this->endpoint = $endpoint; + return $this; + } + public function onSuccess() { try { @@ -306,6 +334,10 @@ class KickstartForm extends QuickForm } $values = $this->getValues(); + if ($this->endpoint && empty($values['password'])) { + $values['password'] = $this->endpoint->getApiUser()->password; + } + $kickstart = new KickstartHelper($this->getDb()); unset($values['resource']); $kickstart->setConfig($values)->run(); diff --git a/application/views/scripts/kickstart/index.phtml b/application/views/scripts/kickstart/index.phtml new file mode 100644 index 00000000..822e4334 --- /dev/null +++ b/application/views/scripts/kickstart/index.phtml @@ -0,0 +1,15 @@ +
+tabs ?> +

escape($this->title) ?>subtitle) { + echo ' ' . $this->escape($this->subtitle) . ''; +} +?>

+ +actionLinks ?> + +
+ +
+form ?> +