Skip to content

Commit

Permalink
Add basic structure for the installation routine
Browse files Browse the repository at this point in the history
refs #3761
  • Loading branch information
Johannes Meyer committed Oct 11, 2013
1 parent c38ae72 commit 8fe60fd
Show file tree
Hide file tree
Showing 4 changed files with 327 additions and 5 deletions.
39 changes: 35 additions & 4 deletions installer/controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,29 @@
*/
// {{{ICINGA_LICENSE_HEADER}}}

require_once 'Zend/Config.php';
require_once 'Zend/Session.php';
require_once 'Zend/Session/Namespace.php';
require_once 'Zend/Controller/Action.php';
require_once realpath(__DIR__ . '/../forms/WizardForm.php');
require_once realpath(__DIR__ . '/../forms/EndForm.php');
require_once realpath(__DIR__ . '/../forms/StartForm.php');
require_once realpath(__DIR__ . '/../forms/DbConfigForm.php');
require_once realpath(__DIR__ . '/../forms/AuthConfigForm.php');
require_once realpath(__DIR__ . '/../forms/RequirementsForm.php');
require_once realpath(__DIR__ . '/../forms/ConfirmationForm.php');
require_once realpath(__DIR__ . '/../forms/BackendConfigForm.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Util/Report.php');
require_once realpath(__DIR__ . '/../../library/Icinga/Application/Installer.php');

use \Zend_Config;
use \Zend_Session;
use \Zend_Session_Namespace;
use \Zend_Controller_Action;
use \Icinga\Util\Report;
use \Icinga\Application\Wizard;
use \Icinga\Application\Installer;
use \Icinga\Installer\Pages\EndForm;
use \Icinga\Installer\Pages\StartForm;
use \Icinga\Installer\Pages\DbConfigForm;
use \Icinga\Installer\Pages\AuthConfigForm;
Expand Down Expand Up @@ -88,8 +95,8 @@ public function indexAction()
}
break;
case 7:
if ($this->validateConfirmation($namespace)) {
$this->runInstallation();
if ($this->validateConfirmation($namespace) && $this->runInstallation($namespace)) {
Zend_Session::namespaceUnset('installation');
}
}
}
Expand Down Expand Up @@ -249,9 +256,33 @@ private function validateConfirmation($session)

/**
* Process the entire details and run the installation
*
* @return bool Whether the installation succeeded
*/
private function runInstallation()
private function runInstallation($session)
{
throw new \Exception('Not implemented');
$installer = new Installer(
Wizard::getInstance()->getConfigurationDir(),
new Zend_Config(
array(
'backendConfig' => $session->backendDetails,
'dbConfig' => $session->databaseDetails,
'authConfig' => $session->authenticationDetails
)
)
);
$installer->run();

$this->view->form = new EndForm();
$this->view->form->setRequest($this->getRequest());
$this->view->form->setResult($installer->getResult());

if ($installer->hasFailed()) {
$this->view->form->retryInstallation();
return false;
} else {
$this->view->form->finishInstallation();
return true;
}
}
}
102 changes: 102 additions & 0 deletions installer/forms/EndForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Installer\Pages;

/**
* Wizard-Page that shows the user an installation result/report
*/
class EndForm extends WizardForm
{
/**
* Whether the installation succeeded
*
* @var bool
*/
private $success;

/**
* The result to present
*
* @var array
*/
private $result;

/**
* Set the result that is shown to the user
*
* @param array $result The result to show
*/
public function setResult(array $result)
{
$this->result = $result;
}

public function create()
{
$this->addNote('End', 1);

foreach ($this->result as $title => $lines) {
$this->addNote($title, 2);
$this->addNote(implode('<br />', $lines));
}

if ($this->success) {
$this->addNote(
'<span style="font-weight:bold;">The installation has successfully completed!</span>' .
' You can now start exploring icingaweb by clicking "Finish". (Remember the default' .
' admin user you have defined earlier!)'
);
$this->setSubmitLabel('Finish');
} else {
$this->addNote(
'<span style="font-weight:bold;">The installation seems to have failed!</span>' .
' Please fix the issues and retry the installation.'
);
$this->setSubmitLabel('Retry installation');
}
}

/**
* Inform the user that the installation has failed
*/
public function retryInstallation()
{
$this->success = false;
$this->stayOnPage();
}

/**
* Inform the user that the installation was successful
*/
public function finishInstallation()
{
$this->success = true;
$this->endWizard();
}
}
9 changes: 8 additions & 1 deletion installer/forms/WizardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

require_once 'Zend/Db.php';
require_once 'Zend/Form.php';
require_once 'Zend/Config.php';
require_once 'Zend/Validate/Abstract.php';
require_once 'Zend/Form/Element/Xhtml.php';
require_once 'Zend/Form/Element/Submit.php';
Expand Down Expand Up @@ -144,6 +143,14 @@ public function stayOnPage()
$this->setProgress($this->getRequest()->getPost('progress', 1));
}

/**
* Mark the current page to not to advance and return to the first one
*/
public function endWizard()
{
$this->setProgress(1);
}

/**
* Set the progress of the wizard
*
Expand Down
182 changes: 182 additions & 0 deletions library/Icinga/Application/Installer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Application;

use \Exception;
use \Zend_Config;

class Installer
{
/**
* The configuration directory to use
*
* @var string
*/
private $configDir;

/**
* The installation options to use
*
* @var Zend_Config
*/
private $options;

/**
* The installation "log"
*
* @var array
*/
private $result;

/**
* Whether the installation failed
*
* @var bool
*/
private $failed;

/**
* Initialise a new icingaweb installer
*
* @param string $configDir The configuration directory to use
* @param Zend_Config $options The installation options to use
*/
public function __construct($configDir, Zend_Config $options)
{
$this->configDir = $configDir;
$this->options = $options;
$this->result = array();
$this->failed = false;
}

/**
* Get the installation result
*
* @return array
*/
public function getResult()
{
return $this->result;
}

/**
* Return whether the installation failed
*
* @return bool
*/
public function hasFailed()
{
return $this->failed;
}

/**
* Run the installation
*
* @return array
*/
public function run()
{
try {
$this->setupResources();
$this->setupAuthentication();
$this->setupPreferences();
$this->setupDefaultAdmin();
$this->setupBackend();
} catch (Exception $error) {
// TODO: Log this exception? (To the logfile, not $this->log()!)
$this->failed = true;
return;
}

$this->finalize();
}

/**
* Log a result message
*
* @param string $section The section/title for which the message is for
* @param string $message The message
*/
private function log($section, $message)
{
if (!array_key_exists($section, $this->result)) {
$this->result[$section] = array();
}

array_push($this->result[$section], $message);
}

/**
* Set up the resources.ini
*/
private function setupResources()
{

}

/**
* Set up the authentication.ini
*/
private function setupAuthentication()
{

}

/**
* Set up the preferences (config.ini)
*/
private function setupPreferences()
{

}

/**
* Set up the default admin user
*/
private function setupDefaultAdmin()
{

}

/**
* Set up the initial backend
*/
private function setupBackend()
{

}

/**
* Do any finalization steps
*/
private function finalize()
{

}
}

0 comments on commit 8fe60fd

Please sign in to comment.