Drop the ModulePage

refs #8191
This commit is contained in:
Johannes Meyer 2015-01-21 09:59:48 +01:00
parent 99699a14ad
commit b468be2813
2 changed files with 0 additions and 176 deletions

View File

@ -1,161 +0,0 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
// {{{ICINGA_LICENSE_HEADER}}}
namespace Icinga\Module\Setup\Forms;
use InvalidArgumentException;
use Icinga\Application\Icinga;
use Icinga\Web\Form;
use Icinga\Web\Session;
use Icinga\Web\Request;
class ModulePage extends Form
{
protected $session;
protected $wizards;
protected $modules;
protected $pageData;
protected $modulePaths;
/**
* Initialize this page
*/
public function init()
{
$this->setName('setup_modules');
$this->setViewScript('form/setup-modules.phtml');
$this->session = Session::getSession()->getNamespace(get_class($this));
$this->modulePaths = array();
if (($appModulePath = realpath(Icinga::app()->getApplicationDir() . '/../modules')) !== false) {
$this->modulePaths[] = $appModulePath;
}
}
public function setPageData(array $pageData)
{
$this->pageData = $pageData;
return $this;
}
public function handleRequest(Request $request = null)
{
$isPost = strtolower($request->getMethod()) === 'post';
if ($isPost && $this->wasSent($request->getPost())) {
if (($newModule = $request->getPost('module')) !== null) {
$this->setCurrentModule($newModule);
$this->getResponse()->redirectAndExit($this->getRedirectUrl());
} else {
// The user submitted this form but with the parent wizard's navigation
// buttons so it's now up to the parent wizard to handle the request..
}
} else {
$wizard = $this->getCurrentWizard();
$wizardPage = $wizard->getCurrentPage();
$wizard->handleRequest($request);
if ($isPost && $wizard->isFinished() && $wizardPage->wasSent($request->getPost())) {
$wizards = $this->getWizards();
$newModule = null;
foreach ($wizards as $moduleName => $moduleWizard) {
if (false === $moduleWizard->isFinished()) {
$newModule = $moduleName;
}
}
if ($newModule === null) {
// In case all module wizards were completed just pick the first one again
reset($wizards);
$newModule = key($wizards);
}
$this->setCurrentModule($newModule);
}
}
}
public function clearSession()
{
$this->session->clear();
foreach ($this->getWizards() as $wizard) {
$wizard->clearSession();
}
}
public function setCurrentModule($moduleName)
{
if (false === array_key_exists($moduleName, $this->getWizards())) {
throw new InvalidArgumentException(sprintf('Module "%s" does not provide a setup wizard', $moduleName));
}
$this->session->currentModule = $moduleName;
}
public function getCurrentModule()
{
$moduleName = $this->session->get('currentModule');
if ($moduleName === null) {
$moduleName = key($this->getWizards());
$this->setCurrentModule($moduleName);
}
return $moduleName;
}
public function getCurrentWizard()
{
$wizards = $this->getWizards();
return $wizards[$this->getCurrentModule()];
}
public function getModules()
{
if ($this->modules !== null) {
return $this->modules;
} else {
$this->modules = array();
}
$moduleManager = Icinga::app()->getModuleManager();
$moduleManager->detectInstalledModules($this->modulePaths);
foreach ($moduleManager->listInstalledModules() as $moduleName) {
$this->modules[] = $moduleManager->loadModule($moduleName)->getModule($moduleName);
}
return $this->modules;
}
public function getWizards()
{
if ($this->wizards !== null) {
return $this->wizards;
} else {
$this->wizards = array();
}
foreach ($this->getModules() as $module) {
if ($module->providesSetupWizard()) {
$this->wizards[$module->getName()] = $module->getSetupWizard();
}
}
$this->mergePageData($this->wizards);
return $this->wizards;
}
protected function mergePageData(array $wizards)
{
foreach ($wizards as $wizard) {
$wizardPageData = & $wizard->getPageData();
foreach ($this->pageData as $pageName => $pageData) {
$wizardPageData[$pageName] = $pageData;
}
}
}
}

View File

@ -94,7 +94,6 @@ class WebWizard extends Wizard implements SetupWizard
$this->addPage(new AdminAccountPage());
$this->addPage(new GeneralConfigPage());
$this->addPage(new DatabaseCreationPage());
$this->addPage(new ModulePage());
$this->addPage(new SummaryPage());
}
@ -167,9 +166,6 @@ class WebWizard extends Wizard implements SetupWizard
unset($pageData['setup_admin_account']);
unset($pageData['setup_authentication_backend']);
}
} elseif ($page->getName() === 'setup_modules') {
$page->setPageData($this->getPageData());
$page->handleRequest($request);
}
}
@ -263,7 +259,6 @@ class WebWizard extends Wizard implements SetupWizard
public function clearSession()
{
parent::clearSession();
$this->getPage('setup_modules')->clearSession();
$tokenPath = Config::resolvePath('setup.token');
if (file_exists($tokenPath)) {
@ -358,12 +353,6 @@ class WebWizard extends Wizard implements SetupWizard
)
);
foreach ($this->getPage('setup_modules')->setPageData($this->getPageData())->getWizards() as $wizard) {
if ($wizard->isFinished()) {
$setup->addSteps($wizard->getSetup()->getSteps());
}
}
return $setup;
}
@ -548,10 +537,6 @@ class WebWizard extends Wizard implements SetupWizard
)
);
foreach ($this->getPage('setup_modules')->setPageData($this->getPageData())->getWizards() as $wizard) {
$requirements->merge($wizard->getRequirements()->allOptional());
}
return $requirements;
}
}