* Calendar/all apps: fix since last package not working old favorites and json-encode all php-serialized preferences

This commit is contained in:
Ralf Becker 2015-08-24 16:02:07 +00:00
parent 88b4624d78
commit bb84db6161
4 changed files with 75 additions and 50 deletions

View File

@ -78,7 +78,6 @@ class egw_favorites
error_log(__METHOD__.'Favorite filter is not suppose to be empty, it should be an array. filter = '. array2string($filters[$name]));
continue;
}
$href = "javascript:app.$app.setState(" . json_encode($filter,JSON_FORCE_OBJECT) . ');';
$li = "<li data-id='$name' data-group='{$filter['group']}' class='ui-menu-item' role='menuitem'>\n";
$li .= '<a href="#" class="ui-corner-all" tabindex="-1">';
$li .= "<div class='" . ((string)$name === (string)$default_filter ? 'ui-icon ui-icon-heart' : 'sideboxstar') . "'></div>".
@ -158,20 +157,8 @@ class egw_favorites
{
if(strpos($pref_name, $pref_prefix) === 0)
{
if(!is_array($pref)) // old favorite
{
if (!($pref = unserialize($pref)))
{
continue;
}
$pref = array(
'name' => substr($pref_name,strlen($pref_prefix)),
'group' => !isset($GLOBALS['egw']->preferences->user[$app][$pref_name]),
'state' => $pref,
);
//error_log(__METHOD__."() old favorite '$pref_name' converted to ".array2string($pref));
}
//else error_log(__METHOD__."() new favorite '$pref_name' ".array2string($pref));
if(!is_array($pref)) continue; // old favorite
$favorites[(string)substr($pref_name,strlen($pref_prefix))] = $pref;
}
}

View File

@ -216,17 +216,6 @@ class preferences
$app = trim($row['preference_app']);
$prefs[$row['preference_owner']][$app] = self::unserialize($row['preference_value']);
// fix old PHP serialized attribute-values
foreach($prefs[$row['preference_owner']][$app] as $name => &$val)
{
if (is_string($val) && $val[0] != 'a' && $val[1] != ':' &&
// using a white-list currently only matching favorites
substr($name, 0, 9) == 'favorite_' && ($v = php_safe_unserialize($val)))
{
$val = $v;
}
}
}
foreach($db_read as $id)
{
@ -740,9 +729,9 @@ class preferences
/**
* Change single value in preferences of all users (incl. groups, default and forced)
*
* @param string $app
* @param string $name
* @param string $value new value to set, or null or '' to delete it
* @param string $app app-name or null for all apps
* @param string $name attribute name or regular expression (enclosed in /) to match attribute-name eg. '/^favorite_/'
* @param string|callable $value new value to set, or null or '' to delete it or callable returning new value: function($attr, $old_value)
* @param string $old_value if given, only change if that's current value
* @param string $type if given limit to "user", "forced", "default", "group"
*/
@ -750,9 +739,9 @@ class preferences
{
$db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db;
$where = array(
'preference_app' => $app,
);
$where = array();
if ($app) $where['preference_app'] = $app;
switch($type)
{
case 'forced':
@ -772,30 +761,53 @@ class preferences
{
$prefs = self::unserialize($row['preference_value']);
if (isset($old_value) && $prefs[$name] != $old_value) continue;
if ((string)$value !== '')
if ($name[0] == '/' && substr($name, -1) == '/')
{
$prefs[$name] = $value;
$attrs = array_filter(array_keys($prefs), function($n) use ($name)
{
return preg_match($name, $n);
});
}
else
{
unset($prefs[$name]);
$attrs = array($name);
}
$db->update(self::TABLE, array(
'preference_value' => json_encode($prefs),
), array(
'preference_owner' => $row['preference_owner'],
'preference_app' => $row['preference_app'],
), __LINE__, __FILE__);
// update instance-wide cache
$cached = egw_cache::getInstance(__CLASS__, $row['preference_owner']);
if($cached && $cached[$row['preference_app']])
$updated = false;
foreach($attrs as $attr)
{
$cached[$row['preference_app']] = $prefs;
egw_cache::setInstance(__CLASS__, $row['preference_owner'], $cached);
if (isset($old_value) && $prefs[$attr] != $old_value) continue;
$val = is_callable($value) ? call_user_func($value, $attr, $prefs[$attr]) : $value;
if ($val === $prefs[$attr]) continue;
$updated = true;
if ((string)$val !== '')
{
$prefs[$attr] = $val;
}
else
{
unset($prefs[$attr]);
}
}
// if somethings changed or old row was php-serialized --> store it again json-encoded
if ($updated || $row['preference_value'][0] == 'a' && $row['preference_value'][1] == ':')
{
$db->update(self::TABLE, array(
'preference_value' => json_encode($prefs),
), array(
'preference_owner' => $row['preference_owner'],
'preference_app' => $row['preference_app'],
), __LINE__, __FILE__);
// update instance-wide cache
$cached = egw_cache::getInstance(__CLASS__, $row['preference_owner']);
if($cached && $cached[$row['preference_app']])
{
$cached[$row['preference_app']] = $prefs;
egw_cache::setInstance(__CLASS__, $row['preference_owner'], $cached);
}
}
}
}

View File

@ -12,7 +12,7 @@
/* Basic information about this app */
$setup_info['phpgwapi']['name'] = 'phpgwapi';
$setup_info['phpgwapi']['title'] = 'EGroupware API';
$setup_info['phpgwapi']['version'] = '14.3.002';
$setup_info['phpgwapi']['version'] = '14.3.003';
$setup_info['phpgwapi']['versions']['current_header'] = '1.29';
$setup_info['phpgwapi']['enable'] = 3;
$setup_info['phpgwapi']['app_order'] = 1;

View File

@ -809,3 +809,29 @@ function phpgwapi_upgrade14_3_001()
return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.002';
}
/**
* Fix old php-serialized favorites to use new format with name, group and state attributes
* Change still php-serialized values in column egw_preferences.preference_value to json-encoding
*
* @return string
*/
function phpgwapi_upgrade14_3_002()
{
$GLOBALS['run-from-upgrade14_3_002'] = true;
preferences::change_preference(null, '/^favorite_/', function($name, $value, $owner)
{
if (is_string($value) && $value[0] == 'a' && $value[1] == ':' && ($state = php_safe_unserialize($value)))
{
$value = array(
'name' => substr($name, 9), // skip "favorite_"
'group' => !($owner > 0),
'state' => $state,
);
}
return $value;
});
return $GLOBALS['setup_info']['phpgwapi']['currentver'] = '14.3.003';
}