/** * Converts from the old localStorage-based preferences to the new-style * preferences according to the "rules" given. * * `rules` is an object, the keys of which refer to the preference names. * The value tells the converter what to do. The following values are available: * * * `user`: convert to a user-level preference * * `user newkey`: convert to a user-level preference, changing the key to newkey * * Once a key has been converted, it will not be converted again. * * @param {string|Object} clientID ClientID used in the old preferences * @param {Object} rules Rules for conversion (as defined above) * @param {boolean=} isViewState If it is undefined or false, then the preferences * listed in 'rules' are those normal user-editable preferences. Otherwise, * they are view state settings. * @param {function(string)=} prefCheckCallback Optional callback function that * examines each preference key for migration. */ function convertPreferences(clientID, rules, isViewState, prefCheckCallback) { PreferencesImpl.smUserScopeLoading.done(function () { PreferencesImpl.userScopeLoading.done(function () { var prefs = getPreferenceStorage(clientID, null, true); if (!prefs) { return; } var prefsID = getClientID(clientID); if (prefStorage.convertedKeysMap === undefined) { prefStorage.convertedKeysMap = {}; } var convertedKeysMap = prefStorage.convertedKeysMap; prefs.convert(rules, convertedKeysMap[prefsID], isViewState, prefCheckCallback) .done(function (complete, convertedKeys) { prefStorage.convertedKeysMap[prefsID] = convertedKeys; savePreferences(); }); }).fail(function (error) { console.error("Error while converting ", getClientID(clientID)); console.error(error); }); }); }
/** * Converts from the old localStorage-based preferences to the new-style * preferences according to the "rules" given. * * `rules` is an object, the keys of which refer to the preference names. * The value tells the converter what to do. The following values are available: * * * `user`: convert to a user-level preference * * `user newkey`: convert to a user-level preference, changing the key to newkey * * Once a key has been converted, it will not be converted again. * * @param {string|Object} clientID ClientID used in the old preferences * @param {Object} rules Rules for conversion (as defined above) * @param {boolean=} isViewState If it is undefined or false, then the preferences * listed in 'rules' are those normal user-editable preferences. Otherwise, * they are view state settings. * @param {function(string)=} prefCheckCallback Optional callback function that * examines each preference key for migration. */ function convertPreferences(clientID, rules, isViewState, prefCheckCallback) { PreferencesImpl.smUserScopeLoading.done(function () { PreferencesImpl.userScopeLoading.done(function () { if (!clientID || (typeof clientID === "object" && (!clientID.id || !clientID.uri))) { console.error("Invalid clientID"); return; } var prefs = getPreferenceStorage(clientID, null, true); if (!prefs) { return; } var prefsID = typeof clientID === "object" ? getClientID(clientID) : clientID; if (prefStorage.convertedKeysMap === undefined) { prefStorage.convertedKeysMap = {}; } var convertedKeysMap = prefStorage.convertedKeysMap; prefs.convert(rules, convertedKeysMap[prefsID], isViewState, prefCheckCallback) .done(function (complete, convertedKeys) { prefStorage.convertedKeysMap[prefsID] = convertedKeys; savePreferences(); }); }).fail(function (error) { console.error("Error while converting ", typeof clientID === "object" ? getClientID(clientID) : clientID); console.error(error); }); }); }