diff --git a/mail/setup/default_records.inc.php b/mail/setup/default_records.inc.php index e51c394d1f..613a776f48 100644 --- a/mail/setup/default_records.inc.php +++ b/mail/setup/default_records.inc.php @@ -27,4 +27,22 @@ 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'); \ No newline at end of file +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', +)); \ No newline at end of file diff --git a/phpgwapi/inc/class.preferences.inc.php b/phpgwapi/inc/class.preferences.inc.php index 45b1da1a91..ddf919be52 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -801,6 +801,50 @@ 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) + { + //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 *