From 4a569043a69b14921ca3ee244d80cda3de4bf0ce Mon Sep 17 00:00:00 2001 From: DSB Date: Tue, 21 Aug 2012 20:22:56 +0000 Subject: [PATCH] MSD-19 - Changed old configuration to new class for installation - removed old classes --- application/Bootstrap.php | 15 +- application/configs/defaultConfig.ini | 49 ++- application/controllers/ConfigController.php | 4 +- application/controllers/IndexController.php | 17 +- application/controllers/InstallController.php | 266 ++++++++------- .../controllers/SqlServerController.php | 3 +- application/forms/Config/Email.php | 4 +- application/forms/Config/Ftp.php | 25 +- application/models/Config/FormValidator.php | 22 +- application/views/scripts/install/step4.phtml | 170 +++++----- .../Action/Helper/AssignConfigAndLanguage.php | 8 +- library/Msd/Config.php | 8 +- library/Msd/Config/IoHandler/Default.php | 22 +- library/Msd/Configuration.php | 317 ------------------ library/Msd/ConfigurationPhpValues.php | 138 -------- library/Msd/Controller/Action.php | 8 +- library/Msd/Registry.php | 6 +- .../controllers/IndexControllerTest.php | 16 +- 18 files changed, 345 insertions(+), 753 deletions(-) delete mode 100644 library/Msd/Configuration.php delete mode 100644 library/Msd/ConfigurationPhpValues.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index ea61915..82d49a3 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -47,12 +47,19 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap */ public function _initConfiguration() { - $dynamicConfig = new Msd_Config_Dynamic(); - $configFile = $dynamicConfig->getParam('configFile', 'mysqldumper.ini'); + $dynamicConfig = Msd_Registry::getDynamicConfig(); + if ($dynamicConfig === null) { + $dynamicConfig = new Msd_Config_Dynamic(); + } + $configFile = $dynamicConfig->getParam('configFile', 'defaultConfig.ini'); Msd_Registry::setConfigFilename($configFile); - $config = new Msd_Config( + $config = new Msd_Config( 'Default', - array('directories' => realpath(APPLICATION_PATH . '/../work/config')) + array('directories' => array( + realpath(APPLICATION_PATH . '/../work/config'), + realpath(APPLICATION_PATH . '/configs') + ) + ) ); $config->load($configFile); Msd_Registry::setConfig($config); diff --git a/application/configs/defaultConfig.ini b/application/configs/defaultConfig.ini index 9bdb702..f1649aa 100644 --- a/application/configs/defaultConfig.ini +++ b/application/configs/defaultConfig.ini @@ -1,4 +1,5 @@ [general] +title = "MySQLDumper" mode = "easy" logMaxsize = "1048576" logUnit = "kb" @@ -7,11 +8,17 @@ maxspeed = "10000" gzip = "y" multipart = "n" multipartSize = "" -multipartSizeUnit = "kb" optimize = "n" errorHandling = "s" dbDelete = "n" -title = "defaultConfig" + +[dbuser] +user = "root" +pass = "" +host = "localhost" +defaultDb = "otrance" +port = "" +socket = "" [autodelete] Activated = "n" @@ -25,8 +32,11 @@ RecipientAddress = "" RecipientName = "" attachBackup = "n" Maxsize = "" -MaxsizeUnit = "kb" -Program = "php" +SendmailCall = "" +SMTPHost = "" +SMTPPort = "" +SMTPUser = "" +SMTPPassword = "" [ftp] 0.use = "n" @@ -38,6 +48,15 @@ Program = "php" 0.user = "" 0.pass = "" 0.dir = "/" +1.use = "n" +1.timeout = "10" +1.passiveMode = "y" +1.ssl = "n" +1.server = "" +1.port = "21" +1.user = "" +1.pass = "" +1.dir = "/" [cronscript] perlExtension = "pl" @@ -47,7 +66,7 @@ perlTextOutputComplete = "y" perlFileComment = "" [interface] -language = "de" +language = "en" theme = "msd" notificationWindowPosition = "middleCenter" showServerCaption = "y" @@ -57,15 +76,15 @@ recordsPerPage = "50" sqlbrowserViewMode = "compact" refreshProcesslist = "3" -[dbuser] -host = "localhost" -user = "root" -pass = "" -manual = "" -port = "" -socket = "" -defaultDb = "information_schema" - [systemDatabases] 0 = "mysql" -1 = "information_schema" \ No newline at end of file +1 = "information_schema" + +[paths] +work = "E:\\PHP\\msd2/work/" +log = "E:\\PHP\\msd2/work/log" +backup = "E:\\PHP\\msd2/work/backup" +config = "E:\\PHP\\msd2/work/config" +iconPath = "css/msd/icons" + + diff --git a/application/controllers/ConfigController.php b/application/controllers/ConfigController.php index 2f608b0..01d16b8 100644 --- a/application/controllers/ConfigController.php +++ b/application/controllers/ConfigController.php @@ -215,7 +215,7 @@ class ConfigController extends Msd_Controller_Action */ public function addRecipientCcAction() { - $recipientsCc = $this->_config->Param('email.RecipientCc'); + $recipientsCc = $this->_config->getParam('email.RecipientCc'); if ($recipientsCc === null) { $recipientsCc = array(); } @@ -286,6 +286,7 @@ class ConfigController extends Msd_Controller_Action sort($ftpConfig); } $this->_config->setParam('ftp', $ftpConfig); + //$this->_config->save(); } $this->_forward('index'); } @@ -410,6 +411,7 @@ class ConfigController extends Msd_Controller_Action $value = $this->_config->getParam($group . '.' . $element); if (is_array($value)) { list (, $key) = explode('.', $element); + $value[$key] = isset($value[$key]) ? $value[$key] : ''; $subForm->setDefault($element, $value[$key]); } else if ($value !== null) { $subForm->setDefault($element, $value); diff --git a/application/controllers/IndexController.php b/application/controllers/IndexController.php index 2c98245..6d460b6 100644 --- a/application/controllers/IndexController.php +++ b/application/controllers/IndexController.php @@ -58,7 +58,6 @@ class IndexController extends Msd_Controller_Action array('message' => 'L_PHP_VERSION_TOO_OLD') ); } - try { $dbo = Msd_Db::getAdapter(); $data = Msd_File::getLatestBackupInfo(); @@ -265,14 +264,14 @@ class IndexController extends Msd_Controller_Action // if we get here wrong credentials are given $this->view->popUpMessage() ->addMessage( - 'login-message', - 'L_LOGIN', - $user->getAuthMessages(), - array( - 'modal' => true, - 'dialogClass' => 'error' - ) - ); + 'login-message', + 'L_LOGIN', + $user->getAuthMessages(), + array( + 'modal' => true, + 'dialogClass' => 'error' + ) + ); } } $this->view->form = $form; diff --git a/application/controllers/InstallController.php b/application/controllers/InstallController.php index 0f0d10d..a4798d6 100644 --- a/application/controllers/InstallController.php +++ b/application/controllers/InstallController.php @@ -16,8 +16,22 @@ * @package MySQLDumper * @subpackage Controllers */ -class InstallController extends Zend_Controller_Action +class InstallController extends Msd_Controller_Action { + /** + * @var Msd_Config + */ + public $config; + /** + * @var Msd_DynamicConfig + */ + public $dynamicConfig; + + /** + * @var Msd_Language + */ + public $lang; + /** * Init controller * @@ -27,23 +41,28 @@ class InstallController extends Zend_Controller_Action { $layout = Zend_Layout::getMvcInstance(); $layout->setLayout('install'); - $this->version = new Msd_Version(); + $this->version = new Msd_Version(); $_SESSION['msd_install'] = true; - if ( - $this->_request->getActionName() != 'badversion!' && - !$this->version->checkPhpVersion() - ) { + if ($this->_request->getActionName() != 'badversion!' && !$this->version->checkPhpVersion()) { $this->_forward( 'badversion', 'install', 'default', array( - 'message' => 'L_PHP_VERSION_TOO_OLD' + 'message' => 'L_PHP_VERSION_TOO_OLD' ) ); } - $config = Msd_Configuration::getInstance('defaultConfig'); - $config->set('config.interface.theme', 'msd'); + $this->_config->setParam('interface.theme', 'msd'); + $this->_config->setParam('paths.iconPath', 'css/msd/icons'); + $this->_config->setParam('configFile', 'mysqldumper.ini'); + $this->view->config = $this->_config; + $lang = $_SESSION['msd_lang']; + if ($lang == '') { + $lang = 'en'; + } + $translator = Msd_Language::getInstance(); + $this->view->lang = $translator->loadLanguage($lang); } /** @@ -53,31 +72,27 @@ class InstallController extends Zend_Controller_Action */ public function indexAction() { - // delete cookie from further installation if present - // to not import old values + // delete cookie from further installation if present to not import old values if (isset($_SESSION['msd_autologin'])) { setcookie('msd_autologin', null, null, '/'); $_SESSION['msd_autologin'] = array(); } Zend_Session_Namespace::resetSingleInstance('MySQLDumper'); - $config = Msd_Configuration::getInstance('defaultConfig', true); - $lang = Msd_Language::getInstance(); if ($this->_request->isPost()) { $language = $this->_getParam('language'); - $config->set('config.interface.language', $language); - $config->set('dynamic.configFile', 'mysqldumper'); - $config->set('config.general.title', 'MySQLDumper'); - $config->saveConfigToSession(); + $this->_config->setParam('interface.language', $language); + $this->_config->setParam('general.title', 'MySQLDumper'); + $this->_config->setParam('configFile', 'mysqldumper.ini'); $_SESSION['msd_lang'] = $language; - $redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step2'), null, true); + $redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step2'), null, true); $this->_response->setRedirect($redirectUrl); } // set selected languge - $language = $this->_getParam('language', null); - $languages = $lang->getAvailableLanguages(); + $language = $this->_getParam('language', null); + $languages = $this->_lang->getAvailableLanguages(); // check user browser language - $locale = new Zend_Locale(); + $locale = new Zend_Locale(); $browserLocale = array_keys($locale->getBrowser()); // get default or last selected language @@ -99,22 +114,24 @@ class InstallController extends Zend_Controller_Action $this->view->stepInfo = array( 'language' => $language, 'stepInfo' => array( - 'number' => 1, - 'description' => $lang->getTranslator() - ->_('L_SELECT_LANGUAGE') - . ' (' . $language . ')')); - $languagesStatus = array(); + 'number' => 1, + 'description' => $this->_lang->getTranslator() + ->_('L_SELECT_LANGUAGE') + . ' (' . $language . ')')); + $languagesStatus = array(); foreach ($languages as $langId => $langName) { $languagesStatus[$langId] = array( - 'langName' => $langName, + 'langName' => $langName, 'installed' => file_exists( APPLICATION_PATH . '/language/' . $langId . '/lang.php' ) ); } - $config->set('config.interface.language', $language); + $this->_config->setParam('interface.language', $language); $this->view->languages = $languagesStatus; - $this->view->lang = $lang; + $this->view->lang = Msd_Language::getInstance(); + Msd_Registry::setConfig($this->_config); + $this->view->config = Msd_Registry::getConfig(); } /** @@ -126,24 +143,22 @@ class InstallController extends Zend_Controller_Action */ public function step2Action() { - $lang = Msd_Language::getInstance(); - $config = Msd_Configuration::getInstance(); - $language = $config->get('config.interface.language'); + $language = $this->_config->getParam('interface.language'); $this->view->stepInfo = array( - 'language' => $language, + 'language' => $language, 'firstStepOK' => true, - 'stepInfo' => array( - 'number' => 2, - 'description' => $lang->getTranslator()->_('L_CHECK_DIRS'), + 'stepInfo' => array( + 'number' => 2, + 'description' => $this->_lang->getTranslator()->_('L_CHECK_DIRS'), ) ); - $creationStatus = array(); - $checkDirs = array( - 'work' => $config->get('paths.work'), - 'config' => $config->get('paths.config'), - 'log' => $config->get('paths.log'), - 'backup' => $config->get('paths.backup'), - 'iconpath' => $config->get('paths.iconPath') + $creationStatus = array(); + $checkDirs = array( + 'work' => $this->_config->getParam('paths.work'), + 'config' => $this->_config->getParam('paths.config'), + 'log' => $this->_config->getParam('paths.log'), + 'backup' => $this->_config->getParam('paths.backup'), + 'iconpath' => $this->_config->getParam('paths.iconPath') ); foreach ($checkDirs as $checkDir) { @@ -152,22 +167,21 @@ class InstallController extends Zend_Controller_Action @mkdir($checkDir, 0777); } clearstatcache(); - $checkExists = file_exists($checkDir); - $checkWritable = Msd_File::isWritable($checkDir, 0777); + $checkExists = file_exists($checkDir); + $checkWritable = Msd_File::isWritable($checkDir, 0777); $creationStatus[$checkDir] = array( - 'chmod' => Msd_File::getChmod($checkDir), - 'exists' => $checkExists, + 'chmod' => Msd_File::getChmod($checkDir), + 'exists' => $checkExists, 'writable' => $checkWritable, ); - $this->view->status = $creationStatus; + $this->view->status = $creationStatus; } if (!in_array(false, $creationStatus)) { - $config->set('dynamic.configFile', 'mysqldumper'); - $config->saveConfigToSession(); + $this->_config->setParam('configFile', 'mysqldumper'); + //$this->_config->save(); $redirectUrl = $this->view->url(array('controller' => 'install', 'action' => 'step3'), null, true); $this->_response->setRedirect($redirectUrl); } - $this->view->lang = $lang; } /** @@ -177,23 +191,20 @@ class InstallController extends Zend_Controller_Action */ public function step3Action() { - $lang = Msd_Language::getInstance(); - $config = Msd_Configuration::getInstance(); - $language = $config->get('config.interface.language'); - $form = new Application_Form_Install_User(); + $language = $this->_config->getParam('interface.language'); + $form = new Application_Form_Install_User(); $this->view->stepInfo = array( - 'language' => $language, - 'firstStepOK' => true, + 'language' => $language, + 'firstStepOK' => true, 'secondStepOK' => true, - 'stepInfo' => array( - 'number' => 3, - 'description' => $lang->getTranslator()->_('L_AUTHENTICATE'), + 'stepInfo' => array( + 'number' => 3, + 'description' => $this->_lang->getTranslator()->_('L_AUTHENTICATE'), ) ); if ($this->_request->isPost()) { $postData = $this->_request->getParams(); - $form->getElement('pass_confirm')->getValidator('Identical') - ->setToken($postData['pass']); + $form->getElement('pass_confirm')->getValidator('Identical')->setToken($postData['pass']); if ($form->isValid($postData)) { $ini = new Msd_Ini(); $ini->set('name', $postData['user'], 'user'); @@ -204,7 +215,7 @@ class InstallController extends Zend_Controller_Action } } $this->view->form = $form; - $this->view->lang = $lang; + $this->view->lang = Msd_Language::getInstance(); } /** @@ -214,63 +225,61 @@ class InstallController extends Zend_Controller_Action */ public function step4Action() { - $lang = Msd_Language::getInstance(); - $config = Msd_Configuration::getInstance(); - $language = $config->get('config.interface.language'); + $language = $this->_config->getParam('interface.language'); $this->view->stepInfo = array( - 'language' => $language, - 'firstStepOK' => true, + 'language' => $language, + 'firstStepOK' => true, 'secondStepOK' => true, - 'thirdStepOK' => true, - 'stepInfo' => array( - 'number' => 4, - 'description' => $lang->getTranslator()->_('L_DBPARAMETER'), + 'thirdStepOK' => true, + 'stepInfo' => array( + 'number' => 4, + 'description' => $this->_lang->getTranslator()->_('L_DBPARAMETER'), ) ); if ($this->_request->isPost()) { $options = array( - 'host' => $this->_getParam('host'), - 'user' => $this->_getParam('user'), - 'pass' => $this->_getParam('pass'), + 'host' => $this->_getParam('host'), + 'user' => $this->_getParam('user'), + 'pass' => $this->_getParam('pass'), 'manual' => $this->_getParam('manual'), - 'port' => $this->_getParam('port'), + 'port' => $this->_getParam('port'), 'socket' => $this->_getParam('socket'), ); + + $dbAdapter = Msd_Db::getAdapter($options); + try { + $this->view->databases = $dbAdapter->getDatabaseNames(); + $this->view->success = true; + $this->_config->setParam('dbuser', $options); + if (!$this->version->checkMysqlVersion()) { + $this->_forward( + 'badversion', + 'install', + 'default', + array( + 'message' => 'L_MYSQL_VERSION_TOO_OLD' + ) + ); + } + } catch (Msd_Exception $e) { + $this->view->errorMessage = $e->getMessage(); + $this->view->success = false; + return; + } + $saveParam = $this->_getParam('save'); - $config->set('config.dbuser', $options); + $this->_config->setParam('dbuser', $options); if ($saveParam !== null && $saveParam == 1) { - $config->set('config.general.title', 'MySQLDumper'); - $config->set('config.dbuser.defaultDb', $this->_getParam('defaultDb')); - $config->save('mysqldumper'); + $this->_config->setParam('general.title', 'MySQLDumper'); + $this->_config->setParam('dbuser.defaultDb', $this->_getParam('defaultDb')); + $this->_config->save('mysqldumper.ini'); unset($_SESSION['msd_lang']); unset($_SESSION['msd_install']); $redirectUrl = $this->view->url(array('controller' => 'index', 'action' => 'index', null, true)); $this->_response->setRedirect($redirectUrl); - } else { - $dbAdapter = Msd_Db::getAdapter($options); - try { - $this->view->databases = $dbAdapter->getDatabaseNames(); - $this->view->success = true; - $config->set('config.dbuser', $options); - if (!$this->version->checkMysqlVersion()) { - $this->_forward( - 'badversion', - 'install', - 'default', - array( - 'message' => 'L_MYSQL_VERSION_TOO_OLD' - ) - ); - } - $config->saveConfigToSession(); - } catch (Msd_Exception $e) { - $this->view->errorMessage = $e->getMessage(); - $this->view->success = false; - } } } - $this->view->lang = $lang; } /** @@ -284,15 +293,14 @@ class InstallController extends Zend_Controller_Action Zend_Controller_Front::getInstance()->setParam('noViewRenderer', true); $this->_response->setHeader('Content-Type', 'text/javascript'); $language = $this->_request->getParam('lang'); - $lang = Msd_Language::getInstance(); - $version = new Msd_Version(); - $files = array( + $version = new Msd_Version(); + $files = array( 'lang' => ':language/lang.php', 'flag' => ':language/flag.gif' ); if ($language === null) { if (!isset($_SESSION['langlist'])) { - $languages = $lang->getAvailableLanguages(); + $languages = $this->_lang->getAvailableLanguages(); $_SESSION['langlist'] = array_keys($languages); } rsort($_SESSION['langlist']); @@ -303,9 +311,7 @@ class InstallController extends Zend_Controller_Action echo json_encode('done'); return; } - $update = new Msd_Update( - APPLICATION_PATH . '/configs/update.ini' - ); + $update = new Msd_Update(APPLICATION_PATH . '/configs/update.ini'); $update->setUpdateParam('language', $language); $update->setUpdateParam('version', $version->getMsdVersion()); $updateResult = $update->doUpdate('language', $files); @@ -313,20 +319,20 @@ class InstallController extends Zend_Controller_Action switch ($updateResult['action']) { case 'connection': $message = array('L_UPDATE_CONNECTION_FAILED', - $updateResult['server']); + $updateResult['server']); break; case 'saveresponse': $message = array('L_UPDATE_ERROR_RESPONSE', - $updateResult['status']); + $updateResult['status']); break; case 'createfile': $message = array('L_WRONG_RIGHTS', - $updateResult['file'], - '0777'); + $updateResult['file'], + '0777'); break; case 'getrequest': $message = array('L_UPDATE_ERROR_RESPONSE', - $updateResult['status']); + $updateResult['status']); break; default: $message = ''; @@ -334,25 +340,25 @@ class InstallController extends Zend_Controller_Action if ($message !== '') { $this->view - ->popUpMessage() - ->addMessage( - 'update-message', - 'L_LOGIN', - $message, - array( - 'modal' => true, - 'dialogClass' => 'error' - ) - ); + ->popUpMessage() + ->addMessage( + 'update-message', + 'L_LOGIN', + $message, + array( + 'modal' => true, + 'dialogClass' => 'error' + ) + ); $updateResult['message'] = (string)$this->view->popUpMessage(); } } echo json_encode( array( - 'language' => $language, - 'success' => ($updateResult === true) ? true : false, - 'error' => ($updateResult === true) ? '' : $updateResult + 'language' => $language, + 'success' => ($updateResult === true) ? true : false, + 'error' => ($updateResult === true) ? '' : $updateResult ) ); } @@ -365,8 +371,8 @@ class InstallController extends Zend_Controller_Action public function badversionAction() { $translator = Msd_Language::getInstance()->getTranslator(); - $messageId = $this->_request->get('message'); - $message = $translator->_($messageId); + $messageId = $this->_request->get('message'); + $message = $translator->_($messageId); if ($messageId == 'L_PHP_VERSION_TOO_OLD') { $this->view->message = sprintf( $message, @@ -374,7 +380,7 @@ class InstallController extends Zend_Controller_Action PHP_VERSION ); } else { - $dbObject = Msd_Db::getAdapter(); + $dbObject = Msd_Db::getAdapter(); $this->view->message = sprintf( $message, $dbObject->getServerInfo(), diff --git a/application/controllers/SqlServerController.php b/application/controllers/SqlServerController.php index 8963d30..24785ab 100644 --- a/application/controllers/SqlServerController.php +++ b/application/controllers/SqlServerController.php @@ -90,8 +90,7 @@ class SqlServerController extends Msd_Controller_Action public function showProcesslistAction() { $this->getProcesslistAction(false); - $interval = $this->view->config - ->get('config.interface.refreshProcesslist'); + $interval = $this->view->config->getParam('interface.refreshProcesslist'); if ($interval < 2) { $interval = 2; } diff --git a/application/forms/Config/Email.php b/application/forms/Config/Email.php index 2e020dd..141b9ed 100644 --- a/application/forms/Config/Email.php +++ b/application/forms/Config/Email.php @@ -25,7 +25,7 @@ class Application_Form_Config_Email extends Zend_Form_SubForm /** * Configuration - * @var Msd_Configuration + * @var Msd_Config */ protected $_config; @@ -596,7 +596,7 @@ class Application_Form_Config_Email extends Zend_Form_SubForm * @param string $name * @param string $value * - * @return void + * @return Zend_Form */ public function setDefault($name, $value) { diff --git a/application/forms/Config/Ftp.php b/application/forms/Config/Ftp.php index 50c6dee..65b5a61 100644 --- a/application/forms/Config/Ftp.php +++ b/application/forms/Config/Ftp.php @@ -329,8 +329,7 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm 'escape' => false, 'label' => '', 'class' => 'Formbutton ftpToggle' . $index, - 'onclick' => "testFtpConnection(" . - $index . ");", + 'onclick' => "testFtpConnection(" . $index . ");", ) ); @@ -346,8 +345,7 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm 'escape' => false, 'label' => '', 'class' => 'Formbutton', - 'onclick' => "deleteFtpConnection(" . - $index . ");", + 'onclick' => "deleteFtpConnection(" . $index . ");", ) ); } @@ -361,19 +359,21 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm */ public function getValidValues($data) { - $values = parent::getValidValues($data, true); - while (false !== (list($key, $value) = each($values))) { + //$values = parent::getValidValues($data, true); + $ftpData = array(); + foreach ($data as $key => $value) { if (substr($key, 0, 4) != 'ftp_') { continue; } list(, $ftpId, $ftpKey) = explode('_', $key); - if (!isset($values[$ftpId])) { - $values[$ftpId] = array(); + if (!isset($ftpData[$ftpId])) { + $ftpData[$ftpId] = array(); } - $values[$ftpId][$ftpKey] = $value; - unset($values[$key]); + $ftpData[$ftpId][$ftpKey] = $value; + //unset($values[$key]); } - return $values; + //var_dump($ftpData); die(); + return $ftpData; } /** @@ -409,9 +409,6 @@ class Application_Form_Config_Ftp extends Zend_Form_SubForm */ public function setDefault($name, $value) { - if (is_array($value)) { - list($ftpId, $key) = explode('.', $name); - } $name = 'ftp_' . str_replace('.', '_', $name); parent::setDefault($name, $value); } diff --git a/application/models/Config/FormValidator.php b/application/models/Config/FormValidator.php index 7019acb..7c48f39 100644 --- a/application/models/Config/FormValidator.php +++ b/application/models/Config/FormValidator.php @@ -54,7 +54,7 @@ class Application_Model_Config_FormValidator * Checks database connection params. * If connection is successfull the values are saved to the config file. * - * @param Zend_View $view The view of the form for adding messages + * @param Zend_View_Interface $view The view of the form for adding messages */ public function validateAndSaveConfig(Zend_View $view) { @@ -81,17 +81,17 @@ class Application_Model_Config_FormValidator if ($saveConfig) { $this->_config->setConfig($this->_configData); $saved = $this->_config->save(); - $this->_config->load(Msd_Registry::getConfigFilename()); if ($saved === true) { - $view->popUpMessage()->addMessage( - 'save-config', - 'L_NOTICE', - array('L_SAVE_SUCCESS', $this->_config->getParam('general.title')), - array( - 'modal' => true, - 'dialogClass' => 'notice' - ) - ); + $this->_config->load(Msd_Registry::getConfigFilename()); + $view->popUpMessage()->addMessage( + 'save-config', + 'L_NOTICE', + array('L_SAVE_SUCCESS', $this->_config->getParam('general.title')), + array( + 'modal' => true, + 'dialogClass' => 'notice' + ) + ); } else { die("Fehler beim Speichern der Konfiguration!"); } diff --git a/application/views/scripts/install/step4.phtml b/application/views/scripts/install/step4.phtml index ffb9381..b04b6fe 100644 --- a/application/views/scripts/install/step4.phtml +++ b/application/views/scripts/install/step4.phtml @@ -1,17 +1,16 @@ +getIcon('Ok', null, 16); +$request = Zend_Controller_Front::getInstance()->getRequest(); +?>
-$okIcon = $this->getIcon('Ok', null, 16); -$request = Zend_Controller_Front::getInstance()->getRequest(); - -?>" method="post" enctype="multipart/formdata"> success) && $this->success) { -?> +if (isset($this->success) && $this->success) { ?> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + +

@@ -19,85 +18,77 @@ if (isset($this->success) && $this->success) { getIcon('save'); ?> lang->L_SAVEANDCONTINUE; ?>

lang->L_DB_HOST; ?>:
lang->L_DB_USER; ?>:
lang->L_DB_PASS; ?>:
lang->L_DB; ?>: -

lang->L_ENTER_DB_INFO; ?>

lang->L_PORT; ?>: -

lang->L_INSTALL_HELP_PORT; ?>

lang->L_SOCKET; ?>: -

lang->L_INSTALL_HELP_SOCKET; ?>

lang->L_TESTCONNECTION; ?>:
lang->L_DB_HOST; ?>:
lang->L_DB_USER; ?>:
lang->L_DB_PASS; ?>:
lang->L_DB; ?>: +

lang->L_ENTER_DB_INFO; ?>

lang->L_PORT; ?>: +

lang->L_INSTALL_HELP_PORT; ?>

lang->L_SOCKET; ?>: +

lang->L_INSTALL_HELP_SOCKET; ?>

lang->L_TESTCONNECTION; ?>:
-success)) { -?>

- -success) { -?> + +success)) { ?> +

 

+
success) { ?> - -databases) > 0) { - foreach ($this->databases as $database) { -?> - - - -databases as $index => $database) { ?> + + + - - - - + } else { ?> + + + - - + @@ -117,12 +106,9 @@ if(isset($this->success)) { - - -
lang->L_DBCONNECTION; ?>
-
- -
- -
- -
-
+
+ +
+ +
+ +
+
lang->L_NO_DB_FOUND_INFO; ?>
lang->L_NO_DB_FOUND_INFO; ?>

@@ -106,10 +97,8 @@ if(isset($this->success)) {

lang->L_DBCONNECTION; ?> getIcon('delete'); ?>

errorMessage; ?>

- + -
\ No newline at end of file + diff --git a/library/Msd/Action/Helper/AssignConfigAndLanguage.php b/library/Msd/Action/Helper/AssignConfigAndLanguage.php index 15a2163..2c6de28 100644 --- a/library/Msd/Action/Helper/AssignConfigAndLanguage.php +++ b/library/Msd/Action/Helper/AssignConfigAndLanguage.php @@ -35,7 +35,13 @@ class Msd_Action_Helper_AssignConfigAndLanguage extends Zend_Controller_Action_H if ($controllerName == 'install') { return; } - $view = $this->getView(); + + $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'); + $redirector->gotoUrl($redirectUrl); + } $view->config = Msd_Registry::getConfig(); $view->dynamicConfig = Msd_Registry::getDynamicConfig(); $view->lang = Msd_Language::getInstance(); diff --git a/library/Msd/Config.php b/library/Msd/Config.php index 1cbbca7..c681779 100644 --- a/library/Msd/Config.php +++ b/library/Msd/Config.php @@ -107,8 +107,14 @@ class Msd_Config * * @return bool */ - public function save() + public function save($configFilenameAndPath = null) { + //$configFilename = $this->getParam('configFile'); + //echo "Dateiname: ". $configFilename; + if ($configFilenameAndPath !== null) { + $this->_ioHandler->setConfigFilename(basename($configFilenameAndPath)); + } + return $this->_ioHandler->save($this->_config); } diff --git a/library/Msd/Config/IoHandler/Default.php b/library/Msd/Config/IoHandler/Default.php index 0f252e7..b529bc7 100644 --- a/library/Msd/Config/IoHandler/Default.php +++ b/library/Msd/Config/IoHandler/Default.php @@ -79,7 +79,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface if (count($config) == 0) { // Search for the config file in the given directories. - $this->_initIni(); + $this->_initIni($config); $config = $this->_iniConfig->getIniData(); // Put configuration into session. $this->_sessionNamespace->config = $config; @@ -88,6 +88,16 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface return $config; } + /** + * Set configuration file name + * + * @param string $configFilename File name of configuration file (without path) + */ + public function setConfigFilename($configFilename) + { + $this->_configFilename = $configFilename; + } + /** * Saves the configuration to session and .ini file. * @@ -98,7 +108,7 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface public function save($config) { if ($this->_iniConfig === null) { - $this->_initIni(); + $this->_initIni($config); } // Save config to session $this->_sessionNamespace->config = $config; @@ -111,17 +121,21 @@ class Msd_Config_IoHandler_Default implements Msd_Config_IoHandler_Interface /** * Initializes the .ini file handler and sets the full filename of the .ini file. * + * @param array Configuration as array + * * @return void */ - private function _initIni() + private function _initIni($config) { foreach ($this->_configDirectories as $configDir) { $filename = rtrim($configDir, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . $this->_configFilename; if (file_exists($filename)) { $this->_configFilename = $filename; $this->_iniConfig = new Msd_Ini($filename); - break; + return; } } + $this->_iniConfig = new Msd_Ini(); + $this->_iniConfig->setIniData($config); } } diff --git a/library/Msd/Configuration.php b/library/Msd/Configuration.php deleted file mode 100644 index 8179e23..0000000 --- a/library/Msd/Configuration.php +++ /dev/null @@ -1,317 +0,0 @@ -_session = new Zend_Session_Namespace('MySQLDumper'); - if ($forceLoading === false && isset($this->_session->dynamic->configFile)) { - $this->loadConfigFromSession(); - return; - } - - $this->_data = new stdClass; - - if ($configName == '') { - $configName = 'defaultConfig'; - } - $this->_data->dynamic = Msd_ConfigurationPhpValues::getDynamicValues(); - $this->_data->paths = $this->_loadUserDirectories(); - $this->loadConfiguration($configName); - $this->set('dynamic.configFile', $configName); - - $defaultDb = $this->get('config.dbuser.defaultDb'); - if ($defaultDb != '') { - $this->set('dynamic.dbActual', $defaultDb); - } - - $this->saveConfigToSession(); - } - - /** - * No cloning for singleton - * - * @return void - */ - public function __clone() - { - throw new Msd_Exception('Cloning is not allowed'); - } - - /** - * Returns the configuration instance - * - * @param string $configName The name of the configuration file to load. - * If not set we will load the config from - * session if present. - * @param boolean $forceLoading If set the config will be read from file. - * - * @return Msd_Configuration - */ - public static function getInstance($configName = '', $forceLoading = false) - { - if (null == self::$_instance) { - self::$_instance = new self($configName, $forceLoading); - } - if ($forceLoading) { - self::$_instance->loadConfiguration($configName, true); - } - return self::$_instance; - } - - /** - * Set a key to a val - * - * @param string $configPath Must begin with "config", "dynamic" or "paths" - * @param string $val The value to set - * - * @return Msd_Configuration - */ - public function set($configPath, $val) - { - $args = explode('.', $configPath); - if (!in_array($args[0], array('config', 'paths', 'dynamic'))) { - $msg = 'Trying to set config value with illegal key. First key ' - . 'must be "config", "paths" or "dynamic"'; - throw new Msd_Exception($msg); - } - switch (count($args)) { - case 2: - list($type, $var) = $args; - $this->_data->$type->$var = $val; - break; - case 3: - list($type, $section, $var) = $args; - $this->_data->$type->$section->$var = $val; - break; - default: - $backTrace = debug_backtrace(false); - throw new Msd_Exception( - 'Path couldn\'t be set!' . PHP_EOL . $configPath . - ' invoked from ' . $backTrace[0]['file'] . '[' . - $backTrace[0]['line'] . ']', - E_USER_NOTICE - ); - } - return $this; - } - - /** - * Get a config parameter - * - * If first part isn't config, paths or dynamic, we assume config is meant. - * - * @param string $key Path to get - * - * @return string|array - */ - public function get($key) - { - $params = explode('.', $key); - if (!in_array($params[0], array('config', 'paths', 'dynamic'))) { - $msg = 'Trying to get config value with illegal key. First key ' - . 'must be "config", "paths" or "dynamic"'; - throw new Msd_Exception($msg); - } - $values = $this->_data->$params[0]; - if (!is_array($values)) { - $values = $this->_data->$params[0]->toArray(); - } - if (sizeof($params) == 1) { - return $values; - } - unset($params[0]); - foreach ($params as $index) { - if (isset($values[$index])) { - $values = $values[$index]; - } else { - $values = null; - break; - } - } - return $values; - } - - /** - * Save configurations to file - * - * @param string $fileName Name of configuration without extension .ini - * @param array $configArray Data to save as array - * - * @return void - */ - public function save($fileName = null, $configArray = null) - { - if ($fileName === null) { - $fileName = $this->get('dynamic.configFile'); - } - $fileName .= '.ini'; - // save branch config and skip groups "dynamic" and "paths" - if ($configArray !== null) { - $configData = new Zend_Config($configArray, true); - } else { - $configData = $this->_data->config; - } - $configWriter = new Zend_Config_Writer_Ini( - array( - 'filename' => $this->get('paths.config') . '/' . $fileName, - 'config' => $configData, - ) - ); - $configWriter->write(); - $this->_data->config = $configData; - $this->set('dynamic.configFile', basename($fileName, '.ini')); - $this->saveConfigToSession(); - } - - /** - * Save config to session - * - * @return void - */ - public function saveConfigToSession() - { - $this->_session->unsetAll(); - $this->_session->config = $this->_data->config; - $this->_session->dynamic = $this->_data->dynamic; - $this->_session->paths = $this->_data->paths; - } - - /** - * Get config from session - * - * @return object - */ - public function loadConfigFromSession() - { - if (isset($this->_session->config)) { - $this->_data->config = $this->_session->config; - } - if (isset($this->_session->dynamic)) { - $this->_data->dynamic = $this->_session->dynamic; - } - if (isset($this->_session->paths)) { - $this->_data->paths = $this->_session->paths; - } - } - - /** - * Load configuration file - * - * @param string $configName The configuration file to load - * @param boolean $applyValues Whether to apply loaded values to config - * - * @return Zend_Config_ini Loaded configuration as Zend_Config_Ini - */ - public function loadConfiguration($configName, $applyValues = true) - { - $this->_loadUserDirectories(); - if ($configName != 'defaultConfig') { - $configName .= '.ini'; - $configPath = $this->get('paths.config'); - $configFile = $configPath . '/' . $configName; - } else { - // special case - defaultConfig.ini is in application/configs - $configFile = realpath(APPLICATION_PATH . '/configs') . '/defaultConfig.ini'; - } - if (!is_readable($configFile)) { - throw new Msd_Exception( - 'Couldn\'t read configuration file ' . $configFile - ); - } - $options = array('allowModifications' => true); - $config = new Zend_Config_Ini($configFile, null, $options); - if (!$applyValues) { - return $config; - } - $this->_data->config = null; - $this->_data->config = $config; - $this->set('dynamic.configFile', basename($configFile, '.ini')); - $iconPath = 'css/' . $this->get('config.interface.theme') . '/icons'; - $this->set('paths.iconpath', $iconPath); - $this->saveConfigToSession(); - return $config; - } - - /** - * Get user directories and save them to config - * - * @return Zend_Config Directories as object - */ - private function _loadUserDirectories() - { - // set paths - $workRoot = realpath(APPLICATION_PATH . '/..') . '/work/'; - $directories = array( - 'work' => $workRoot, - 'log' => $workRoot . 'log', - 'backup' => $workRoot . 'backup', - 'config' => $workRoot . 'config' - ); - return new Zend_Config($directories, true); - } - - /** - * Return name of configuration - * - * @return string - */ - public function getTitle() - { - return $this->get('config.general.title'); - } - - /** - * Reloads the configuration from the current ini file. - * - * @return void - */ - public function reloadConfig() - { - $this->loadConfiguration($this->get('dynamic.configFile')); - } -} diff --git a/library/Msd/ConfigurationPhpValues.php b/library/Msd/ConfigurationPhpValues.php deleted file mode 100644 index 6ead210..0000000 --- a/library/Msd/ConfigurationPhpValues.php +++ /dev/null @@ -1,138 +0,0 @@ - self::_getConfigSetting('sendmail_path'), - 'safeMode' => self::_getConfigSetting('safe_mode', true), - 'magicQuotesGpc' => get_magic_quotes_gpc(), - 'disabledPhpFunctions' => - str_replace( - ',', - ', ', - self::_getConfigSetting('disable_functions') - ), - 'maxExecutionTime' => self::_getMaxExecutionTime(), - 'uploadMaxFilesize' => self::_getUploadMaxFilesize(), - 'phpextensions' => implode(', ', get_loaded_extensions()), - 'phpRam' => $phpRam, - 'memoryLimit' => round($phpRam * 1024 * 1024 * 0.9, 0), - 'compression' => self::_hasZlib(), - ); - return new Zend_Config($dynConfig, true); - } - - /** - * Read PHP's max_execution_time - * - * @return int - */ - private static function _getMaxExecutionTime() - { - $maxExecutionTime = - self::_getConfigSetting('max_execution_time', true); - if ($maxExecutionTime <= 5) { - // we didn't get the real value from the server - some deliver "-1" - $maxExecutionTime = 30; - } elseif ($maxExecutionTime > 30) { - // we don't use more than 30 seconds to avoid brower timeouts - $maxExecutionTime = 30; - } - return $maxExecutionTime; - } - - /** - * Get PHP's upload_max_filesize - * - * @return int - */ - private static function _getUploadMaxFilesize() - { - $uploadMaxFilesize = self::_getConfigSetting('upload_max_filesize'); - // Is value in Megabytes? If yes create output - if (strpos($uploadMaxFilesize, 'M')) { - $uploadMaxFilesize = str_replace('M', '', $uploadMaxFilesize); - $uploadMaxFilesize = trim($uploadMaxFilesize); - // re-calculate to Bytes - $uploadMaxFilesize *= 1024 * 1024; - } - return (int) $uploadMaxFilesize;; - } - - /** - * Get PHP's ram size - * - * @return integer The memory limit in MB - */ - private static function _getPhpRam() - { - $ram = self::_getConfigSetting('memory_limit'); - // we don't trust the value delivered by server config if < 16 - if ($ram < 16) { - $ram = 16; - } - return $ram; - } - - /** - * Detect if zlib is installed - * - * @return boolean - */ - private static function _hasZlib() - { - $zlib = false; - $extensions = get_loaded_extensions(); - if (in_array('zlib', $extensions)) { - $zlib = true; - }; - return (boolean) $zlib; - } - - /** - * Returns a PHP-Setting from ini - * - * First try to read via ini_get(), then fall back to get_cfg_var() - * - * @param string $varName The name of the setting to read - * @param bool $returnAsInt Whether to return value as integer - * - * @return mixed - */ - private function _getConfigSetting($varName, $returnAsInt = false) - { - $value = @ini_get($varName); - - // fallback if ini_get doesn't work - if ($value == '' || $value === null) { - $value = @get_cfg_var($varName); - } - - if ($returnAsInt) { - $value = (int) $value; - } - return $value; - } -} diff --git a/library/Msd/Controller/Action.php b/library/Msd/Controller/Action.php index ad811e6..02a7f45 100644 --- a/library/Msd/Controller/Action.php +++ b/library/Msd/Controller/Action.php @@ -26,6 +26,11 @@ class Msd_Controller_Action extends Zend_Controller_Action */ protected $_dynamicConfig; + /** + * @var Msd_Language + */ + protected $_lang; + /** * Class constructor * @@ -59,8 +64,9 @@ class Msd_Controller_Action extends Zend_Controller_Action array $invokeArgs = array() ) { - $this->_config = Msd_Registry::getConfig(); + $this->_config = Msd_Registry::getConfig(); $this->_dynamicConfig = Msd_Registry::getDynamicConfig(); + $this->_lang = Msd_Language::getInstance(); parent::__construct($request, $response, $invokeArgs); } } diff --git a/library/Msd/Registry.php b/library/Msd/Registry.php index 3312ee4..8a44df1 100644 --- a/library/Msd/Registry.php +++ b/library/Msd/Registry.php @@ -21,21 +21,21 @@ class Msd_Registry extends Zend_Registry * * @const string */ - const CONFIG_FILENAME_KEY = '_configFilename'; + const CONFIG_FILENAME_KEY = 'configFilename'; /** * Key for the dynamic configuration. This is used inside the 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. diff --git a/tests/functional/controllers/IndexControllerTest.php b/tests/functional/controllers/IndexControllerTest.php index b3aaa88..8f7c0f5 100644 --- a/tests/functional/controllers/IndexControllerTest.php +++ b/tests/functional/controllers/IndexControllerTest.php @@ -176,8 +176,8 @@ class Msd_Application_Controller_IndexControllerTest 'lastController' => 'index' ) ); - $config = Msd_Configuration::getInstance(); - $config->set('dynamic.dbActual', -1); + $dynamicConfig = Msd_Registry::getDynamicConfig(); + $dynamicConfig->set('dbActual', -1); $this->dispatch('/index/dbrefresh'); $this->assertRedirectTo('/index/phpinfo'); } @@ -185,9 +185,9 @@ class Msd_Application_Controller_IndexControllerTest public function testCanSelectDb() { $this->loginUser(); - $config = Msd_Configuration::getInstance(); + $dynamicConfig = Msd_Registry::getDynamicConfig(); // set invalid active db - $config->set('dynamic.dbActual', -1); + $dynamicConfig->setParam('dbActual', -1); $this->getRequest() ->setMethod('POST') ->setParams( @@ -202,7 +202,7 @@ class Msd_Application_Controller_IndexControllerTest // check if actual db was switched $this->assertEquals( 'information_schema', - $config->get('dynamic.dbActual') + $dynamicConfig->getParam('dbActual') ); } @@ -228,8 +228,8 @@ class Msd_Application_Controller_IndexControllerTest ) ); $this->dispatch('/index/switchconfig'); - $config = Msd_Configuration::getInstance(); - $this->assertEquals('mysqldumper', $config->get('dynamic.configFile')); + $dynamicConfig = Msd_Registry::getDynamicConfig(); + $this->assertEquals('mysqldumper', $dynamicConfig->getParam('configFile')); // are we still on the phpinfo page? $this->assertQueryCount('#phpinfo', 1); @@ -265,4 +265,4 @@ class Msd_Application_Controller_IndexControllerTest $this->assertTrue(true); } -} \ No newline at end of file +}