Skip to content
Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
nijel committed Jun 17, 2016
1 parent cd229d7 commit 331c560
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 5 deletions.
33 changes: 28 additions & 5 deletions setup/config.php
Expand Up @@ -15,6 +15,24 @@

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($GLOBALS['ConfigFile']);
$form_display->registerForm('_config.php', $forms['_config.php']);
$form_display->save('_config.php');
Expand Down Expand Up @@ -44,20 +62,25 @@
//
// Save generated config file on the server
//
file_put_contents(
$result = @file_put_contents(
$config_file_path,
ConfigGenerator::getConfigFile($GLOBALS['ConfigFile'])
);
if ($result === false) {
$state = 'config_not_saved';
} else {
$state = 'config_saved';
}
header('HTTP/1.1 303 See Other');
header('Location: index.php' . PMA_URL_getCommon() . '&action_done=config_saved');
header('Location: index.php' . PMA_URL_getCommon() . '&action_done=' . $state);
exit;
} elseif (PMA_ifSetOr($_POST['submit_load'], '')) {
//
// Load config file from the server
//
$cfg = array();
include $config_file_path;
$GLOBALS['ConfigFile']->setConfigData($cfg);
$GLOBALS['ConfigFile']->setConfigData(
loadConfig($config_file_path)
);
header('HTTP/1.1 303 See Other');
header('Location: index.php' . PMA_URL_getCommon());
exit;
Expand Down
14 changes: 14 additions & 0 deletions setup/frames/index.inc.php
Expand Up @@ -126,6 +126,20 @@
)
);
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;
}
Expand Down

0 comments on commit 331c560

Please sign in to comment.