From f2ca4d2762de095be09ea866ca41f9997c9911c2 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Tue, 22 Jul 2014 14:57:23 +0000 Subject: [PATCH] copy felamimail preferences to new mail app, if they still exist there --- mail/setup/default_records.inc.php | 20 +++++++++++- phpgwapi/inc/class.preferences.inc.php | 42 ++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 1 deletion(-) 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..127475e776 100644 --- a/phpgwapi/inc/class.preferences.inc.php +++ b/phpgwapi/inc/class.preferences.inc.php @@ -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 *