2011-06-10 21:55:32 +00:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* This file is part of MySQLDumper released under the GNU/GPL 2 license
|
|
|
|
* http://www.mysqldumper.net
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Config
|
|
|
|
* @version SVN: $Rev$
|
|
|
|
* @author $Author$
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* Config Validator
|
|
|
|
*
|
|
|
|
* Model to validate configuration values set in config form
|
|
|
|
*
|
|
|
|
* @package MySQLDumper
|
|
|
|
* @subpackage Config
|
|
|
|
*/
|
|
|
|
|
|
|
|
class Application_Model_Config_FormValidator
|
|
|
|
{
|
2012-08-08 22:36:28 +00:00
|
|
|
/**
|
|
|
|
* Current configuration.
|
|
|
|
*
|
|
|
|
* @var Msd_Config|null
|
|
|
|
*/
|
|
|
|
protected $_config;
|
|
|
|
|
2011-06-10 21:55:32 +00:00
|
|
|
/**
|
|
|
|
* Config data to validate
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
private $_configData = array();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct
|
|
|
|
*
|
|
|
|
* @param array $configData The data to validate
|
|
|
|
*/
|
|
|
|
public function __construct($configData)
|
|
|
|
{
|
2012-08-08 22:36:28 +00:00
|
|
|
$this->_config = Msd_Registry::getConfig();
|
2011-06-10 21:55:32 +00:00
|
|
|
// unset values we only used for form handling
|
|
|
|
unset(
|
|
|
|
$configData['general']['selectedTab'],
|
|
|
|
$configData['general']['param']
|
|
|
|
);
|
|
|
|
$this->_configData = $configData;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-08-05 17:05:08 +00:00
|
|
|
* Validate config data and save when valid
|
2011-06-10 21:55:32 +00:00
|
|
|
*
|
|
|
|
* Checks database connection params.
|
|
|
|
* If connection is successfull the values are saved to the config file.
|
|
|
|
*
|
2012-08-21 20:22:56 +00:00
|
|
|
* @param Zend_View_Interface $view The view of the form for adding messages
|
2011-06-10 21:55:32 +00:00
|
|
|
*/
|
2012-08-05 17:05:08 +00:00
|
|
|
public function validateAndSaveConfig(Zend_View $view)
|
2011-06-10 21:55:32 +00:00
|
|
|
{
|
|
|
|
$saveConfig = false;
|
|
|
|
$translator = Msd_Language::getInstance()->getTranslator();
|
|
|
|
$db = Msd_Db::getAdapter($this->_configData['dbuser']);
|
|
|
|
try {
|
|
|
|
$db->getServerInfo();
|
|
|
|
$saveConfig = true;
|
|
|
|
} catch (Msd_Exception $e) {
|
|
|
|
$msg = $translator->_('L_ERROR').' (' . $e->getCode().') ';
|
|
|
|
$msg .= $e->getMessage();
|
|
|
|
$view->popUpMessage()->addMessage(
|
|
|
|
'db-access-error',
|
|
|
|
'L_ERROR',
|
|
|
|
$msg,
|
|
|
|
array(
|
|
|
|
'modal' => true,
|
|
|
|
'dialogClass' => 'error',
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($saveConfig) {
|
2012-08-08 22:36:28 +00:00
|
|
|
$this->_config->setConfig($this->_configData);
|
|
|
|
$saved = $this->_config->save();
|
2012-08-05 17:05:08 +00:00
|
|
|
if ($saved === true) {
|
2012-08-21 20:22:56 +00:00
|
|
|
$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'
|
|
|
|
)
|
|
|
|
);
|
2012-08-05 17:05:08 +00:00
|
|
|
} else {
|
|
|
|
die("Fehler beim Speichern der Konfiguration!");
|
|
|
|
}
|
2011-06-10 21:55:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|