# R53455 - in /trunk/phpgwapi: inc/ setup/

**URL:** <http://discourse.egroupware.org/t/r53455-in-trunk-phpgwapi-inc-setup/66120>\
**Category:** eGW-svn\
**Created:** [August 24, 2015, 4:00pm UTC](http://discourse.egroupware.org/t/r53455-in-trunk-phpgwapi-inc-setup/66120 "2015-08-24T16:00:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![ralfbecker\_sf](http://discourse.egroupware.org/letter_avatar_proxy/v4/letter/r/b2d939/32.png) [@ralfbecker\_sf](http://discourse.egroupware.org/u/ralfbecker_sf)\
**Post date:** [August 24, 2015, 4:00pm UTC](http://discourse.egroupware.org/t/r53455-in-trunk-phpgwapi-inc-setup/66120/1 "2015-08-24T16:00:32Z")

</div>

Author: ralfbecker  
New Revision: 53455

URL: [http://svn.stylite.de/viewvc/egroupware?rev=53455&view=rev](http://svn.stylite.de/viewvc/egroupware?rev=53455&view=rev)  
Log:

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

Modified:  
trunk/phpgwapi/inc/class.egw\_favorites.inc.php  
trunk/phpgwapi/inc/class.preferences.inc.php  
trunk/phpgwapi/setup/setup.inc.php  
trunk/phpgwapi/setup/tables\_update.inc.php

# Modified: trunk/phpgwapi/inc/class.egw\_favorites.inc.php URL: [http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/inc/class.egw\_favorites.inc.php?rev=53455&r1=53454&r2=53455&view=diff](http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/inc/class.egw_favorites.inc.php?rev=53455&r1=53454&r2=53455&view=diff)

— trunk/phpgwapi/inc/class.egw\_favorites.inc.php (original)  
+++ trunk/phpgwapi/inc/class.egw\_favorites.inc.php Mon Aug 24 18:00:31 2015  
@@ -78,7 +78,6 @@  
error\_log( **METHOD**.‘Favorite filter "’.$name.’" is not supposed to be empty, it should be an array. Skipping, more investigation needed. 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 @@  
{  
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;
  	}
  }

```

# Modified: trunk/phpgwapi/inc/class.preferences.inc.php URL: [http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/inc/class.preferences.inc.php?rev=53455&r1=53454&r2=53455&view=diff](http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/inc/class.preferences.inc.php?rev=53455&r1=53454&r2=53455&view=diff)

— trunk/phpgwapi/inc/class.preferences.inc.php (original)  
+++ trunk/phpgwapi/inc/class.preferences.inc.php Mon Aug 24 18:00:31 2015  
@@ -216,17 +216,6 @@  
$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 @@  
/\*\*  
\* 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 @@  
{  
$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 @@  
{  
$prefs = self::unserialize($row[‘preference\_value’]);

- 

```
  	if (isset($old_value) && $prefs[$name] != $old_value) continue;

```

- 
- 

```
  	if ((string)$value !== '')

```

- 

```
  	{

```

- 

```
  		$prefs[$name] = $value;

```

- 

```
  	if ($name[0] == '/' && substr($name, -1) == '/')

```

- 

```
  	{

```

- 

```
  		$attrs = array_filter(array_keys($prefs), function($n) use ($name)

```

- 

```
  		{

```

- 

```
  			return preg_match($name, $n);

```

- 

```
  		});
  	}
  	else
  	{

```

- 

```
  		unset($prefs[$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']])

```

- 

```
  	{

```

- 

```
  		$cached[$row['preference_app']] = $prefs;

```

- 

```
  		egw_cache::setInstance( __CLASS__ , $row['preference_owner'], $cached);

```

- 

```
  		$attrs = array($name);

```

- 

```
  	}

```

- 
- 

```
  	$updated = false;

```

- 

```
  	foreach($attrs as $attr)

```

- 

```
  	{

```

- 

```
  		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);

```

- 

```
  		}
  	}
  }

```

}

# Modified: trunk/phpgwapi/setup/setup.inc.php URL: [http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/setup/setup.inc.php?rev=53455&r1=53454&r2=53455&view=diff](http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/setup/setup.inc.php?rev=53455&r1=53454&r2=53455&view=diff)

— trunk/phpgwapi/setup/setup.inc.php (original)  
+++ trunk/phpgwapi/setup/setup.inc.php Mon Aug 24 18:00:31 2015  
@@ -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.900’;  
+$setup\_info[‘phpgwapi’][‘version’] = ‘14.3.901’;  
$setup\_info[‘phpgwapi’][‘versions’][‘current\_header’] = ‘1.29’;  
$setup\_info[‘phpgwapi’][‘enable’] = 3;  
$setup\_info[‘phpgwapi’][‘app\_order’] = 1;

# Modified: trunk/phpgwapi/setup/tables\_update.inc.php URL: [http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/setup/tables\_update.inc.php?rev=53455&r1=53454&r2=53455&view=diff](http://svn.stylite.de/viewvc/egroupware/trunk/phpgwapi/setup/tables_update.inc.php?rev=53455&r1=53454&r2=53455&view=diff)

— trunk/phpgwapi/setup/tables\_update.inc.php (original)  
+++ trunk/phpgwapi/setup/tables\_update.inc.php Mon Aug 24 18:00:31 2015  
@@ -815,6 +815,32 @@  
}

/\*\*

- 
  - 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’;  
+}
- 

+/\*\*

- Updates on the way to 15.1  
\*/

@@ -823,9 +849,21 @@  
\*

- @return string  
\*/  
-function phpgwapi\_upgrade14\_3\_002()  
+function phpgwapi\_upgrade14\_3\_003()  
{  
$GLOBALS[‘egw\_setup’]-\>oProc-\>DropTable(‘egw\_api\_content\_history’);

- 

+/\*\*

- 
  - Run 14.3.002 upgrade for everyone who was already on 14.3.900

- \*/  
+function phpgwapi\_upgrade14\_3\_900()  
+{
- if (empty($GLOBALS[‘run-from-upgrade14\_3\_002’]))
- {
- 

```
  phpgwapi_upgrade14_3_002();

```

- }
- return $GLOBALS[‘setup\_info’][‘phpgwapi’][‘currentver’] = ‘14.3.901’;  
+}

* * *

* * *

eGroupWare-cvs mailing list  
[eGroupWare-cvs@lists.sourceforge.net](mailto:eGroupWare-cvs@lists.sourceforge.net)  
[https://lists.sourceforge.net/lists/listinfo/egroupware-cvs](https://lists.sourceforge.net/lists/listinfo/egroupware-cvs)
