Improve error handling in setup in case config dir is not present

We do not show these options in UI, but the scripts should handle it
gracefully.

Signed-off-by: Michal Čihař <michal@cihar.com>
This commit is contained in:
Michal Čihař 2016-06-17 10:53:23 +02:00
parent 96c6a7c0a2
commit fa7a9b787b
2 changed files with 45 additions and 5 deletions

View File

@ -16,6 +16,24 @@ require_once './setup/lib/ConfigGenerator.class.php';
require './libraries/config/setup.forms.php';
/**
* Loads configuration file path
*
* Do this in a function to avoid messing up with global $cfg
*
* @param string $config_file_path
*
* @return array
*/
function loadConfig($config_file_path)
{
$cfg = array();
if (file_exists($config_file_path)) {
include $config_file_path;
}
return $cfg;
}
$form_display = new FormDisplay();
$form_display->registerForm('_config.php', $forms['_config.php']);
$form_display->save('_config.php');
@ -45,17 +63,25 @@ if (PMA_ifSetOr($_POST['submit_clear'], '')) {
//
// Save generated config file on the server
//
file_put_contents($config_file_path, ConfigGenerator::getConfigFile());
$result = @file_put_contents(
$config_file_path,
ConfigGenerator::getConfigFile()
);
if ($result === false) {
$state = 'config_not_saved';
} else {
$state = 'config_saved';
}
header('HTTP/1.1 303 See Other');
header('Location: index.php?action_done=config_saved');
header('Location: index.php?action_done=' . $state);
exit;
} elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
//
// Load config file from the server
//
$cfg = array();
include_once $config_file_path;
ConfigFile::getInstance()->setConfigData($cfg);
ConfigFile::getInstance()->setConfigData(
loadConfig($config_file_path)
);
header('HTTP/1.1 303 See Other');
header('Location: index.php');
exit;

View File

@ -102,6 +102,20 @@ case 'config_saved':
PMA_lang(__('Configuration saved to file config/config.inc.php in phpMyAdmin top level directory, copy it to top level one and delete directory config to use it.'))
);
break;
case 'config_not_saved':
/* Use uniqid to display this message every time configuration is saved */
PMA_messagesSet(
'notice', uniqid('config_not_saved'), __('Configuration not saved!'),
PMA_sanitize(
__(
'Please create web server writable folder [em]config[/em] in '
. 'phpMyAdmin top level directory as described in '
. '[doc@setup_script]documentation[/doc]. Otherwise you will be '
. 'only able to download or display it.'
)
)
);
break;
default:
break;
}