From fa7a9b787b394c086a5e7c5e7eaa2eacacddbd01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20=C4=8Ciha=C5=99?= Date: Fri, 17 Jun 2016 10:53:23 +0200 Subject: [PATCH] Improve error handling in setup in case config dir is not present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We do not show these options in UI, but the scripts should handle it gracefully. Signed-off-by: Michal Čihař --- setup/config.php | 36 +++++++++++++++++++++++++++++++----- setup/frames/index.inc.php | 14 ++++++++++++++ 2 files changed, 45 insertions(+), 5 deletions(-) diff --git a/setup/config.php b/setup/config.php index e923211132..eeb1e6ae46 100644 --- a/setup/config.php +++ b/setup/config.php @@ -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; diff --git a/setup/frames/index.inc.php b/setup/frames/index.inc.php index 4989187539..5feb84be99 100644 --- a/setup/frames/index.inc.php +++ b/setup/frames/index.inc.php @@ -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; }