allow user preferences to work without pmadb, but warn users about that

This commit is contained in:
Crack
2010-07-09 20:37:04 +02:00
parent 5717683ef1
commit bcaecbf10a
4 changed files with 45 additions and 12 deletions

View File

@@ -416,7 +416,7 @@ class PMA_Config
} }
/** /**
* loads user preferences and merges them with current config * Loads user preferences and merges them with current config
* must be called after control connection has been estabilished * must be called after control connection has been estabilished
* *
* @uses $GLOBALS['cfg'] * @uses $GLOBALS['cfg']
@@ -443,6 +443,7 @@ class PMA_Config
$prefs = PMA_load_userprefs(); $prefs = PMA_load_userprefs();
$_SESSION['cache']['userprefs'] = PMA_apply_userprefs($prefs['config_data']); $_SESSION['cache']['userprefs'] = PMA_apply_userprefs($prefs['config_data']);
$_SESSION['cache']['userprefs_mtime'] = $prefs['mtime']; $_SESSION['cache']['userprefs_mtime'] = $prefs['mtime'];
$_SESSION['cache']['userprefs_type'] = $prefs['type'];
$_SESSION['cache']['config_mtime'] = $config_mtime; $_SESSION['cache']['config_mtime'] = $config_mtime;
} }
} else if (!isset($_SESSION['cache']['userprefs'])) { } else if (!isset($_SESSION['cache']['userprefs'])) {
@@ -450,12 +451,11 @@ class PMA_Config
return; return;
} }
$config_data = $_SESSION['cache']['userprefs']; $config_data = $_SESSION['cache']['userprefs'];
// todo: check for empty user data, user_preferences should then be true // type id 'db' or 'session'
$this->set('user_preferences', $_SESSION['cache']['userprefs_type']);
if (!$config_data) { if (!$config_data) {
$this->set('user_preferences', false);
return false; return false;
} }
$this->set('user_preferences', true);
// backup some settings // backup some settings
$fontsize = $this->get('fontsize'); $fontsize = $this->get('fontsize');
@@ -511,13 +511,15 @@ class PMA_Config
function setUserValue($cookie_name, $cfg_path, $new_cfg_value, $default_value = null) function setUserValue($cookie_name, $cfg_path, $new_cfg_value, $default_value = null)
{ {
// use permanent user preferences if possible // use permanent user preferences if possible
if ($this->get('user_preferences')) { $prefs_type = $this->get('user_preferences');
if ($prefs_type) {
require_once './libraries/user_preferences.lib.php'; require_once './libraries/user_preferences.lib.php';
if ($default_value === null) { if ($default_value === null) {
$default_value = PMA_array_read($cfg_path, $this->default); $default_value = PMA_array_read($cfg_path, $this->default);
} }
PMA_persist_option($cfg_path, $new_cfg_value, $default_value); PMA_persist_option($cfg_path, $new_cfg_value, $default_value);
} else if ($cookie_name) { }
if ($prefs_type != 'db' && $cookie_name) {
// fall back to cookies // fall back to cookies
if ($default_value === null) { if ($default_value === null) {
$default_value = PMA_array_read($cfg_path, $this->settings); $default_value = PMA_array_read($cfg_path, $this->settings);
@@ -538,8 +540,9 @@ class PMA_Config
function getUserValue($cookie_name, $cfg_value) function getUserValue($cookie_name, $cfg_value)
{ {
$cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]); $cookie_exists = isset($_COOKIE) && !empty($_COOKIE[$cookie_name]);
if ($this->get('user_preferences')) { $prefs_type = $this->get('user_preferences');
// user preferences value exists, remove cookie if ($prefs_type == 'db') {
// permanent user preferences value exists, remove cookie
if ($cookie_exists) { if ($cookie_exists) {
$this->removeCookie($cookie_name); $this->removeCookie($cookie_name);
} }

View File

@@ -74,6 +74,11 @@ $arr2 .= '<br />Blacklist: ' . (empty($cfg['UserprefsDisallow'])
$msg = PMA_Message::notice('Debug: ' . $arr2); $msg = PMA_Message::notice('Debug: ' . $arr2);
$msg->display(); $msg->display();
// warn about using session storage for settings
$msg = __('Your preferences will be saved only for current session. Storing them permanently requires %s pmadb %s.');
$msg = PMA_sanitize(sprintf($msg, '[a@http://wiki.phpmyadmin.net/pma/pmadb@_blank]', '[/a]'));
PMA_Message::notice($msg)->display();
if (isset($error) && $error) { if (isset($error) && $error) {
if (!$error instanceof PMA_Message) { if (!$error instanceof PMA_Message) {
$error = PMA_Message::error($error); $error = PMA_Message::error($error);

View File

@@ -12,7 +12,9 @@
* Returns false or an array: * Returns false or an array:
* * config_data - path => value pairs * * config_data - path => value pairs
* * mtime - last modification time * * mtime - last modification time
* * type - 'db' (config read from pmadb) or 'session' (read from user session)
* *
* @uses $_SESSION['userconfig']
* @uses PMA_array_merge_recursive * @uses PMA_array_merge_recursive
* @uses PMA_backquote() * @uses PMA_backquote()
* @uses PMA_DBI_fetch_single_row() * @uses PMA_DBI_fetch_single_row()
@@ -25,8 +27,18 @@ function PMA_load_userprefs()
{ {
$cfgRelation = PMA_getRelationsParam(); $cfgRelation = PMA_getRelationsParam();
if (!$cfgRelation['userconfigwork']) { if (!$cfgRelation['userconfigwork']) {
return false; // no pmadb table, use session storage
if (!isset($_SESSION['userconfig'])) {
$_SESSION['userconfig'] = array(
'db' => array(),
'ts' => time());
}
return array(
'config_data' => $_SESSION['userconfig']['db'],
'mtime' => $_SESSION['userconfig']['ts'],
'type' => 'session');
} }
// load configuration from pmadb
$query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']); $query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']);
$query = ' $query = '
SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts SELECT `config_data`, UNIX_TIMESTAMP(`timevalue`) ts
@@ -39,7 +51,8 @@ function PMA_load_userprefs()
$config_data = unserialize($row['config_data']); $config_data = unserialize($row['config_data']);
return array( return array(
'config_data' => $config_data, 'config_data' => $config_data,
'mtime' => $row['ts']); 'mtime' => $row['ts'],
'type' => 'db');
} }
/** /**
@@ -47,6 +60,7 @@ function PMA_load_userprefs()
* *
* @uses $GLOBALS['controllink'] * @uses $GLOBALS['controllink']
* @uses $_SESSION['cache']['userprefs'] * @uses $_SESSION['cache']['userprefs']
* @uses $_SESSION['userconfig']
* @uses ConfigFile::getConfigArray() * @uses ConfigFile::getConfigArray()
* @uses ConfigFile::getInstance() * @uses ConfigFile::getInstance()
* @uses PMA_backquote() * @uses PMA_backquote()
@@ -64,8 +78,18 @@ function PMA_load_userprefs()
function PMA_save_userprefs(array $config_array) function PMA_save_userprefs(array $config_array)
{ {
$cfgRelation = PMA_getRelationsParam(); $cfgRelation = PMA_getRelationsParam();
$config_data = serialize($config_array); if (!$cfgRelation['userconfigwork']) {
// no pmadb table, use session storage
$_SESSION['userconfig'] = array(
'db' => $config_array,
'ts' => time());
if (isset($_SESSION['cache']['userprefs'])) {
unset($_SESSION['cache']['userprefs']);
}
return true;
}
// save configuration to pmadb
$query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']); $query_table = PMA_backquote($cfgRelation['db']) . '.' . PMA_backquote($cfgRelation['userconfig']);
$query = ' $query = '
SELECT `username` SELECT `username`
@@ -73,6 +97,7 @@ function PMA_save_userprefs(array $config_array)
WHERE `username` = \'' . PMA_sqlAddslashes($cfgRelation['user']) . '\''; WHERE `username` = \'' . PMA_sqlAddslashes($cfgRelation['user']) . '\'';
$has_config = PMA_DBI_fetch_value($query, 0, 0, $GLOBALS['controllink']); $has_config = PMA_DBI_fetch_value($query, 0, 0, $GLOBALS['controllink']);
$config_data = serialize($config_array);
if ($has_config) { if ($has_config) {
$query = ' $query = '
UPDATE ' . $query_table . ' UPDATE ' . $query_table . '

View File

@@ -1217,7 +1217,7 @@ code.sql {
.group-cnt { .group-cnt {
padding: 0 0 0 0.5em; padding: 0 0 0 0.5em;
display: inline-block; display: inline-block;
width: 100%; width: 98%;
} }
/* for elements that should be revealed only via js */ /* for elements that should be revealed only via js */