/** * upgradeUserPreferences * This method updates the user_preferences table and sets the pages/dashlets for users * which have ACL access to Trackers so that the Tracker dashlets are set in their user perferences * */ function upgradeUserPreferences() { global $sugar_config, $sugar_version; $uw_strings = return_module_language($GLOBALS['current_language'], 'UpgradeWizard'); $localization = new Localization(); $localeCoreDefaults = $localization->getLocaleConfigDefaults(); // check the current system wide default_locale_name_format and add it to the list if it's not there if (empty($sugar_config['name_formats'])) { $sugar_config['name_formats'] = $localeCoreDefaults['name_formats']; if (!rebuildConfigFile($sugar_config, $sugar_version)) { $errors[] = $uw_strings['ERR_UW_CONFIG_WRITE']; } } $currentDefaultLocaleNameFormat = $sugar_config['default_locale_name_format']; if ($localization->isAllowedNameFormat($currentDefaultLocaleNameFormat)) { upgradeLocaleNameFormat($currentDefaultLocaleNameFormat); } else { $sugar_config['default_locale_name_format'] = $localeCoreDefaults['default_locale_name_format']; if (!rebuildConfigFile($sugar_config, $sugar_version)) { $errors[] = $uw_strings['ERR_UW_CONFIG_WRITE']; } $localization->createInvalidLocaleNameFormatUpgradeNotice(); } $db =& DBManagerFactory::getInstance(); $result = $db->query("SELECT id FROM users where deleted = '0'"); while ($row = $db->fetchByAssoc($result)) { $current_user = new User(); $current_user->retrieve($row['id']); // get the user's name locale format, check if it's in our list, add it if it's not, keep it as user's default $currentUserNameFormat = $current_user->getPreference('default_locale_name_format'); if ($localization->isAllowedNameFormat($currentUserNameFormat)) { upgradeLocaleNameFormat($currentUserNameFormat); } else { $current_user->setPreference('default_locale_name_format', 's f l', 0, 'global'); $current_user->savePreferencesToDB(); } $changed = false; if (!$current_user->getPreference('calendar_publish_key')) { // set publish key if not set already $current_user->setPreference('calendar_publish_key', create_guid()); $changed = true; } // we need to force save the changes to disk, otherwise we lose them. if ($changed) { $current_user->savePreferencesToDB(); } } //while }