copy felamimail preferences to new mail app, if they still exist there

This commit is contained in:
Ralf Becker 2014-07-22 14:57:23 +00:00
parent cf519cb666
commit f2ca4d2762
2 changed files with 61 additions and 1 deletions

View File

@ -28,3 +28,21 @@ if (!$GLOBALS['egw_setup']->db->affected_rows())
// change common/default_app pref to mail, if it was felamimail
preferences::change_preference('common', 'default_app', 'mail', 'felamimail');
// copy felamimail preferences to new mail app, if they still exist there
preferences::copy_preferences('felamimail', 'mail', array(
'htmlOptions',
'allowExternalIMGs',
'message_forwarding',
'composeOptions',
'replyOptions',
'disableRulerForSignatureSeparation',
'insertSignatureAtTopOffMessage',
'attachVCardAtCompose',
'deleteOptions',
'sendOptions',
'trustServerUnseenInfo',
'showAllFoldersInFolderPane',
'prefaskformove',
'saveAsOptions',
));

View File

@ -801,6 +801,48 @@ class preferences
self::change_preference($app, $name, null, null, $type);
}
/**
* Copy preferences from one app to an other
*
* @param string $from_app
* @param string $to_app
* @param array $names=null array of names to copy or null for all
*/
public static function copy_preferences($from_app, $to_app, array $names=null)
{
$db = isset($GLOBALS['egw_setup']->db) ? $GLOBALS['egw_setup']->db : $GLOBALS['egw']->db;
foreach($db->select(self::TABLE, '*', array('preference_app' => $from_app), __LINE__, __FILE__) as $row)
{
$prefs = self::unserialize($row['preference_value']);
if ($names)
{
$prefs = array_intersect_key($prefs, array_flip($names));
}
if (!$prefs) continue; // nothing to change, as nothing set
$row['preference_app'] = $to_app;
unset($row['preference_value']);
if (($values = $this->db->select(self::TABLE, 'preference_value', $row, __LINE__, __FILE__)->fetchColumn()))
{
$prefs = array_merge($values, $prefs);
}
$this->db->insert(self::TABLE, array(
'preference_value' => json_encode($prefs)
), $row, __LINE__, __FILE__);
// update instance-wide cache
if (($cached = egw_cache::getInstance(__CLASS__, $row['prefences_owner'])))
{
$cached[$from_app] = $prefs;
egw_cache::setInstance(__CLASS__, $row['preference_owner'], $cached);
}
}
}
/**
* Save the the preferences to the repository
*