From a2ac0b33e43c9a0f03cd496b2602ab19d612d48a Mon Sep 17 00:00:00 2001 From: DSB Date: Wed, 22 Aug 2012 16:43:15 +0000 Subject: [PATCH] MSD-19 InstallController: - finished changing installation to new configuration class --- application/controllers/InstallController.php | 6 ++++-- .../Action/Helper/AssignConfigAndLanguage.php | 17 ++++++++++----- library/Msd/Config.php | 10 ++++----- library/Msd/Config/IoHandler/Default.php | 21 ++++++++++++------- library/Msd/Registry.php | 4 ++-- 5 files changed, 37 insertions(+), 21 deletions(-) diff --git a/application/controllers/InstallController.php b/application/controllers/InstallController.php index 1905b96..c5745e9 100644 --- a/application/controllers/InstallController.php +++ b/application/controllers/InstallController.php @@ -265,14 +265,16 @@ class InstallController extends Msd_Controller_Action return; } - $saveParam = $this->_getParam('save'); + $saveParam = $this->_getParam('save', null); $this->_config->setParam('dbuser', $options); - if ($saveParam !== null && $saveParam == 1) { + if ($saveParam == 1) { $this->_config->setParam('general.title', 'MySQLDumper'); $this->_config->setParam('dbuser.defaultDb', $this->_getParam('defaultDb')); $this->_config->save('mysqldumper.ini'); + Msd_Registry::setConfig($this->_config); unset($_SESSION['msd_lang']); unset($_SESSION['msd_install']); + $this->_config->load('mysqldumper.ini'); $redirectUrl = $this->view->url(array('controller' => 'index', 'action' => 'index', null, true)); $this->_response->setRedirect($redirectUrl); } diff --git a/library/Msd/Action/Helper/AssignConfigAndLanguage.php b/library/Msd/Action/Helper/AssignConfigAndLanguage.php index 2c6de28..a7b00a4 100644 --- a/library/Msd/Action/Helper/AssignConfigAndLanguage.php +++ b/library/Msd/Action/Helper/AssignConfigAndLanguage.php @@ -36,13 +36,20 @@ class Msd_Action_Helper_AssignConfigAndLanguage extends Zend_Controller_Action_H return; } - $view = $this->getView(); - if (Msd_Registry::getConfigFilename() == 'defaultConfig.ini') { - $redirectUrl = $view->serverUrl() . $view->url(array('controller' => 'install', 'action' => 'index', null, true)); - $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); + $view = $this->getView(); + $config = Msd_Registry::getConfig(); + if ($config->getParam('configFile', 'defaultConfig.ini') == 'defaultConfig.ini') { + $redirectUrl = $view->serverUrl() . $view->url( + array( + 'controller' => 'install', + 'action' => 'index', + null, + true) + ); + $redirector = Zend_Controller_Action_HelperBroker::getStaticHelper('redirector'); $redirector->gotoUrl($redirectUrl); } - $view->config = Msd_Registry::getConfig(); + $view->config = $config; $view->dynamicConfig = Msd_Registry::getDynamicConfig(); $view->lang = Msd_Language::getInstance(); } diff --git a/library/Msd/Config.php b/library/Msd/Config.php index c681779..d053de4 100644 --- a/library/Msd/Config.php +++ b/library/Msd/Config.php @@ -105,14 +105,14 @@ class Msd_Config * Saves the configuration for the next request. * The filename is used for static storage. * + * @param string filename The file name of the fiel to save (without path) + * * @return bool */ - public function save($configFilenameAndPath = null) + public function save($filename = null) { - //$configFilename = $this->getParam('configFile'); - //echo "Dateiname: ". $configFilename; - if ($configFilenameAndPath !== null) { - $this->_ioHandler->setConfigFilename(basename($configFilenameAndPath)); + if ($filename !== null) { + $this->_ioHandler->setConfigFilename($filename); } return $this->_ioHandler->save($this->_config); diff --git a/library/Msd/Config/IoHandler/Default.php b/library/Msd/Config/IoHandler/Default.php index b529bc7..ff536f8 100644 --- a/library/Msd/Config/IoHandler/Default.php +++ b/library/Msd/Config/IoHandler/Default.php @@ -58,7 +58,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface } // Create new namespace for session access. - $this->_sessionNamespace = new Zend_Session_Namespace('Config'); + $this->_sessionNamespace = new Zend_Session_Namespace('config'); } /** @@ -101,7 +101,9 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface /** * Saves the configuration to session and .ini file. * - * @param array $config Configuration to save. + * @param array $config Configuration to save. + * + * @throws Msd_Config_Exception * * @return bool */ @@ -110,18 +112,23 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface if ($this->_iniConfig === null) { $this->_initIni($config); } - // Save config to session - $this->_sessionNamespace->config = $config; // Save config to .ini file $this->_iniConfig->setIniData($config); - return $this->_iniConfig->saveFile($this->_configFilename); + + // Save config to session + $this->_sessionNamespace->config = $config; + if (!isset($this->_configDirectories[0])) { + throw new Msd_Config_Exception('No directory for saving the configuration set!'); + } + $configDirectory = $this->_configDirectories[0]; + return $this->_iniConfig->saveFile($configDirectory . '/' . $this->_configFilename); } /** * Initializes the .ini file handler and sets the full filename of the .ini file. * - * @param array Configuration as array + * @param array $config Configuration as array * * @return void */ @@ -130,7 +137,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface foreach ($this->_configDirectories as $configDir) { $filename = rtrim($configDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->_configFilename; if (file_exists($filename)) { - $this->_configFilename = $filename; + $this->_configFilename = basename($filename); $this->_iniConfig = new Msd_Ini($filename); return; } diff --git a/library/Msd/Registry.php b/library/Msd/Registry.php index 8a44df1..dac525a 100644 --- a/library/Msd/Registry.php +++ b/library/Msd/Registry.php @@ -28,14 +28,14 @@ class Msd_Registry extends Zend_Registry * * @const string */ - const DYNAMIC_CONFIG_KEY = 'Dynamic'; + const DYNAMIC_CONFIG_KEY = 'dynamic'; /** * Key for the configuration. This is used inside the registry. * * @const string */ - const CONFIG_KEY = 'Config'; + const CONFIG_KEY = 'config'; /** * Returns the config instance if it has been registered, returns null otherwise.