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

r47848: fixe PHP Fatal error in preferences::copy_preferences() in mail install
This commit is contained in:
Ralf Becker 2014-07-22 16:53:27 +00:00
parent 6dfd8c616b
commit 650d271fc0
2 changed files with 63 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 // change common/default_app pref to mail, if it was felamimail
preferences::change_preference('common', 'default_app', 'mail', '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,50 @@ class preferences
self::change_preference($app, $name, null, null, $type); 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)
{
//error_log(__METHOD__."('$from_app', '$to_app', ".array2string($names).')');
$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 = $db->select(self::TABLE, 'preference_value', $row, __LINE__, __FILE__)->fetchColumn()))
{
$prefs = array_merge(self::unserialize($values), $prefs);
}
//error_log(__LINE__.': '.__METHOD__."() inserting app=$row[preference_app], owner=$row[preference_owner]: ".array2string($prefs));
$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 * Save the the preferences to the repository
* *