1
0
Fork 0
- Changed old configuration to new class for installation
- removed old classes
Dieser Commit ist enthalten in:
DSB 2012-08-21 20:22:56 +00:00
Ursprung c0be3ce898
Commit 4a569043a6
18 geänderte Dateien mit 345 neuen und 753 gelöschten Zeilen

Datei anzeigen

@ -47,12 +47,19 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
*/
public function _initConfiguration()
{
$dynamicConfig = Msd_Registry::getDynamicConfig();
if ($dynamicConfig === null) {
$dynamicConfig = new Msd_Config_Dynamic();
$configFile = $dynamicConfig->getParam('configFile', 'mysqldumper.ini');
}
$configFile = $dynamicConfig->getParam('configFile', 'defaultConfig.ini');
Msd_Registry::setConfigFilename($configFile);
$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);

Datei anzeigen

@ -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"
[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"

Datei anzeigen

@ -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);

Datei anzeigen

@ -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();

Datei anzeigen

@ -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
*
@ -29,10 +43,7 @@ class InstallController extends Zend_Controller_Action
$layout->setLayout('install');
$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',
@ -42,8 +53,16 @@ class InstallController extends Zend_Controller_Action
)
);
}
$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,28 +72,24 @@ 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);
$this->_response->setRedirect($redirectUrl);
}
// set selected languge
$language = $this->_getParam('language', null);
$languages = $lang->getAvailableLanguages();
$languages = $this->_lang->getAvailableLanguages();
// check user browser language
$locale = new Zend_Locale();
@ -100,7 +115,7 @@ class InstallController extends Zend_Controller_Action
'language' => $language,
'stepInfo' => array(
'number' => 1,
'description' => $lang->getTranslator()
'description' => $this->_lang->getTranslator()
->_('L_SELECT_LANGUAGE')
. ' (' . $language . ')'));
$languagesStatus = array();
@ -112,9 +127,11 @@ class InstallController extends Zend_Controller_Action
)
);
}
$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,
'firstStepOK' => true,
'stepInfo' => array(
'number' => 2,
'description' => $lang->getTranslator()->_('L_CHECK_DIRS'),
'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')
'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) {
@ -162,12 +177,11 @@ class InstallController extends Zend_Controller_Action
$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,9 +191,7 @@ class InstallController extends Zend_Controller_Action
*/
public function step3Action()
{
$lang = Msd_Language::getInstance();
$config = Msd_Configuration::getInstance();
$language = $config->get('config.interface.language');
$language = $this->_config->getParam('interface.language');
$form = new Application_Form_Install_User();
$this->view->stepInfo = array(
'language' => $language,
@ -187,13 +199,12 @@ class InstallController extends Zend_Controller_Action
'secondStepOK' => true,
'stepInfo' => array(
'number' => 3,
'description' => $lang->getTranslator()->_('L_AUTHENTICATE'),
'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,9 +225,7 @@ 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,
@ -224,7 +233,7 @@ class InstallController extends Zend_Controller_Action
'thirdStepOK' => true,
'stepInfo' => array(
'number' => 4,
'description' => $lang->getTranslator()->_('L_DBPARAMETER'),
'description' => $this->_lang->getTranslator()->_('L_DBPARAMETER'),
)
);
@ -237,22 +246,12 @@ class InstallController extends Zend_Controller_Action
'port' => $this->_getParam('port'),
'socket' => $this->_getParam('socket'),
);
$saveParam = $this->_getParam('save');
$config->set('config.dbuser', $options);
if ($saveParam !== null && $saveParam == 1) {
$config->set('config.general.title', 'MySQLDumper');
$config->set('config.dbuser.defaultDb', $this->_getParam('defaultDb'));
$config->save('mysqldumper');
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);
$this->_config->setParam('dbuser', $options);
if (!$this->version->checkMysqlVersion()) {
$this->_forward(
'badversion',
@ -263,15 +262,25 @@ class InstallController extends Zend_Controller_Action
)
);
}
$config->saveConfigToSession();
} catch (Msd_Exception $e) {
$this->view->errorMessage = $e->getMessage();
$this->view->success = false;
return;
}
$saveParam = $this->_getParam('save');
$this->_config->setParam('dbuser', $options);
if ($saveParam !== null && $saveParam == 1) {
$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);
}
}
}
$this->view->lang = $lang;
}
/**
* Ajax action for loading language packs
@ -284,7 +293,6 @@ 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(
'lang' => ':language/lang.php',
@ -292,7 +300,7 @@ class InstallController extends Zend_Controller_Action
);
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);

Datei anzeigen

@ -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;
}

Datei anzeigen

@ -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)
{

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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,8 +81,8 @@ 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) {
$this->_config->load(Msd_Registry::getConfigFilename());
$view->popUpMessage()->addMessage(
'save-config',
'L_NOTICE',

Datei anzeigen

@ -1,17 +1,16 @@
<?php
$okIcon = $this->getIcon('Ok', null, 16);
$request = Zend_Controller_Front::getInstance()->getRequest();
?>
<form action="<?php
echo $this->url(array(
'controller' => 'install',
'action' => 'step4',
));
));?>" method="post" enctype="multipart/formdata">
$okIcon = $this->getIcon('Ok', null, 16);
$request = Zend_Controller_Front::getInstance()->getRequest();
?>" method="post" enctype="multipart/formdata">
<table cellpadding="0" cellspacing="0" class="bdr" style="width: 700px;" summary="Provide MySQL access data">
<?php
if (isset($this->success) && $this->success) {
?>
if (isset($this->success) && $this->success) { ?>
<tr class="thead">
<td style="text-align:center;" colspan="2">
<br />
@ -19,10 +18,8 @@ if (isset($this->success) && $this->success) {
<?php echo $this->getIcon('save'); ?> <?php echo $this->lang->L_SAVEANDCONTINUE; ?>
</button><br class="clear" /><br />
</td>
</tr>
<?php
}
?>
</tr><?php
} ?>
<tr class="row-even">
<td><?php echo $this->lang->L_DB_HOST; ?>:</td>
<td><input type="text" class="text" name="host" maxlength="100" style="width:250px;"
@ -63,41 +60,35 @@ if (isset($this->success) && $this->success) {
</button></td>
</tr>
</table>
<?php
if(isset($this->success)) {
?><br/><br/>
<table class="bdr" cellpadding="0" cellspacing="0" style="width:700px;" summary="MySQL connection results">
<?php
if ($this->success) {
?>
<?php if(isset($this->success)) { ?>
<p>&nbsp;</p>
<table class="bdr" cellpadding="0" cellspacing="0" style="width:700px;" summary="MySQL connection results"><?php
if ($this->success) { ?>
<tr class="thead">
<th><?php echo $this->lang->L_DBCONNECTION; ?> <?php echo $okIcon; ?></th>
</tr>
<?php
</tr><?php
if (count($this->databases) > 0) {
foreach ($this->databases as $database) {
?>
foreach ($this->databases as $index => $database) { ?>
<tr class="dbrow">
<td class="small success">
<div style="float:left; padding-right: 5px;" title="<?php echo $this->lang->L_INSTALL_DB_DEFAULT; ?>">
<input type="radio" name="defaultDb" value="<?php echo $database; ?>" />
<input id="db-<?php echo $index;?>" type="radio" name="defaultDb" value="<?php echo $database; ?>" />
</div>
<label for="db-<?php echo $index;?>">
<?php echo $database; ?>
</label>
<div style="float:right;">
<?php echo $okIcon; ?>
</div>
</td>
</tr>
<?php
</tr><?php
}
} else {
?>
} else { ?>
<tr>
<td><?php echo $okIcon; ?> <?php echo $this->lang->L_NO_DB_FOUND_INFO; ?></td>
</tr>
<?php
}
?>
</tr><?php
} ?>
<tr class="thead">
<td style="text-align:center;">
<br />
@ -106,10 +97,8 @@ if(isset($this->success)) {
</button><br class="clear" /><br />
<input type="hidden" name="save" value="1"/>
</td>
</tr>
<?php
} else {
?>
</tr><?php
} else { ?>
<tr class="thead">
<th><?php echo $this->lang->L_DBCONNECTION; ?> <?php echo $this->getIcon('delete'); ?></th>
</tr>
@ -117,12 +106,9 @@ if(isset($this->success)) {
<td class="error">
<br /><?php echo $this->errorMessage; ?><br /><br/>
</td>
</tr>
<?php
}
?>
</table>
<?php
</tr><?php
}?>
</table><?php
}
?>
</form>

Datei anzeigen

@ -35,7 +35,13 @@ class Msd_Action_Helper_AssignConfigAndLanguage extends Zend_Controller_Action_H
if ($controllerName == 'install') {
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');
$redirector->gotoUrl($redirectUrl);
}
$view->config = Msd_Registry::getConfig();
$view->dynamicConfig = Msd_Registry::getDynamicConfig();
$view->lang = Msd_Language::getInstance();

Datei anzeigen

@ -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);
}

Datei anzeigen

@ -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);
}
}

Datei anzeigen

@ -1,317 +0,0 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Configuration
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Configuration class implemented as singleton
*
* Handles getting and setting of configuration variables
*
* @package MySQLDumper
* @subpackage Configuration
*/
class Msd_Configuration
{
/**
* Instance
*
* @var Msd_Configuration
*/
private static $_instance = NULL;
/**
* Configuration params
*
* @var StdClass
*/
private $_data = null;
/**
* Session to old values
*
* @var Zend_Session_Namespace
*/
private $_session = null;
/**
* Constructor
*
* @param string $configName The name of the configuration file to load.
* If not set we will load the config from
* session if present.
* @param bool $forceLoading Force loading of configuration from file
*/
private function __construct($configName = '', $forceLoading = false)
{
$this->_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'));
}
}

Datei anzeigen

@ -1,138 +0,0 @@
<?php
/**
* This file is part of MySQLDumper released under the GNU/GPL 2 license
* http://www.mysqldumper.net
*
* @package MySQLDumper
* @subpackage Configuration
* @version SVN: $Rev$
* @author $Author$
*/
/**
* Helper for getting dynamic configuration values like phpRam etc.
*
* @package MySQLDumper
* @subpackage Configuration
*/
class Msd_ConfigurationPhpValues
{
/**
* Read dynamic PHP config values
*
* @return Zend_Config
*/
public static function getDynamicValues ()
{
$phpRam = self::_getPhpRam();
$dynConfig = array(
'sendmailCall' => 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;
}
}

Datei anzeigen

@ -26,6 +26,11 @@ class Msd_Controller_Action extends Zend_Controller_Action
*/
protected $_dynamicConfig;
/**
* @var Msd_Language
*/
protected $_lang;
/**
* Class constructor
*
@ -61,6 +66,7 @@ class Msd_Controller_Action extends Zend_Controller_Action
{
$this->_config = Msd_Registry::getConfig();
$this->_dynamicConfig = Msd_Registry::getDynamicConfig();
$this->_lang = Msd_Language::getInstance();
parent::__construct($request, $response, $invokeArgs);
}
}

Datei anzeigen

@ -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.

Datei anzeigen

@ -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);