/** * 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 }
/** * 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 = Localization::getObject(); $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(); } if (file_exists($cachedfile = sugar_cached('dashlets/dashlets.php'))) { require $cachedfile; } else { if (file_exists('modules/Dashboard/dashlets.php')) { require 'modules/Dashboard/dashlets.php'; } } $upgradeTrackingDashlets = array('TrackerDashlet' => array('file' => 'modules/Trackers/Dashlets/TrackerDashlet/TrackerDashlet.php', 'class' => 'TrackerDashlet', 'meta' => 'modules/Trackers/Dashlets/TrackerDashlet/TrackerDashlet.meta.php', 'module' => 'Trackers'), 'MyModulesUsedChartDashlet' => array('file' => 'modules/Charts/Dashlets/MyModulesUsedChartDashlet/MyModulesUsedChartDashlet.php', 'class' => 'MyModulesUsedChartDashlet', 'meta' => 'modules/Charts/Dashlets/MyModulesUsedChartDashlet/MyModulesUsedChartDashlet.meta.php', 'module' => 'Trackers'), 'MyTeamModulesUsedChartDashlet' => array('file' => 'modules/Charts/Dashlets/MyTeamModulesUsedChartDashlet/MyTeamModulesUsedChartDashlet.php', 'class' => 'MyTeamModulesUsedChartDashlet', 'meta' => 'modules/Charts/Dashlets/MyTeamModulesUsedChartDashlet/MyTeamModulesUsedChartDashlet.meta.php', 'module' => 'Trackers')); $GLOBALS['mod_strings'] = return_module_language($GLOBALS['current_language'], 'Home'); $ce_to_pro_or_ent = isset($_SESSION['upgrade_from_flavor']) && preg_match('/^SugarCE.*?(Pro|Ent|Corp|Ult)$/', $_SESSION['upgrade_from_flavor']); $db =& DBManagerFactory::getInstance(); $result = $db->query("SELECT id FROM users WHERE " . User::getLicensedUsersWhere()); 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 $changed = false; $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'); $changed = true; } if (!$current_user->getPreference('calendar_publish_key')) { // set publish key if not set already $current_user->setPreference('calendar_publish_key', create_guid()); $changed = true; } //Set the user theme to be 'Sugar' theme since this is run for CE flavor conversions $userTheme = $current_user->getPreference('user_theme', 'global'); //If theme is empty or if theme was set to Classic (Sugar5) or if this is a ce to pro/ent flavor upgrade change to RacerX theme if (empty($userTheme) || $userTheme == 'Sugar5' || $ce_to_pro_or_ent) { $changed = true; $current_user->setPreference('user_theme', 'RacerX', 0, 'global'); } //Set the number of tabs by default to 7 $maxTabs = $current_user->getPreference('max_tabs', 'global'); if (empty($maxTabs)) { $changed = true; $current_user->setPreference('max_tabs', '7', 0, 'global'); } //If preferences have changed, save before proceeding if ($changed) { $current_user->savePreferencesToDB(); } $pages = $current_user->getPreference('pages', 'Home'); if (empty($pages)) { continue; } $changed = false; $empty_dashlets = array(); $dashlets = $current_user->getPreference('dashlets', 'Home'); $dashlets = !empty($dashlets) ? $dashlets : $empty_dashlets; $existingDashlets = array(); foreach ($dashlets as $id => $dashlet) { if (!empty($dashlet['className']) && !is_array($dashlet['className'])) { $existingDashlets[$dashlet['className']] = $dashlet['className']; } } if (ACLController::checkAccess('Trackers', 'view', false, 'Tracker')) { $trackingDashlets = array(); foreach ($upgradeTrackingDashlets as $trackingDashletName => $entry) { if (empty($existingDashlets[$trackingDashletName])) { $trackingDashlets[create_guid()] = array('className' => $trackingDashletName, 'fileLocation' => $entry['file'], 'options' => array()); } } if (empty($trackingDashlets)) { continue; } $trackingColumns = array(); $trackingColumns[0] = array(); $trackingColumns[0]['width'] = '50%'; $trackingColumns[0]['dashlets'] = array(); foreach ($trackingDashlets as $guid => $dashlet) { array_push($trackingColumns[0]['dashlets'], $guid); } //Set the tracker dashlets to user preferences table $dashlets = array_merge($dashlets, $trackingDashlets); $current_user->setPreference('dashlets', $dashlets, 0, 'Home'); //Set the dashlets pages to user preferences table $pageIndex = count($pages); $pages[$pageIndex]['columns'] = $trackingColumns; $pages[$pageIndex]['numColumns'] = '1'; $pages[$pageIndex]['pageTitle'] = $GLOBALS['mod_strings']['LBL_HOME_PAGE_4_NAME']; $current_user->setPreference('pages', $pages, 0, 'Home'); $changed = true; } //if // we need to force save the changes to disk, otherwise we lose them. if ($changed) { $current_user->savePreferencesToDB(); } } //while /* * This section checks to see if the Tracker settings for the corresponding versions have been * disabled and the regular tracker (for breadcrumbs) enabled. If so, then it will also disable * the tracking for the regular tracker. Disabling the tracker (for breadcrumbs) will no longer prevent * breadcrumb tracking. It will instead only track visible entries (see trackView() method in SugarView.php). * This has the benefit of reducing the tracking overhead and limiting it to only visible items. * For the CE version, we are checking to see that there are no entries enabled for PRO/ENT versions * we are checking for Tracker sessions, performance and queries. */ if ($ce_to_pro_or_ent) { //Set tracker settings. Disable tracker session, performance and queries $category = 'tracker'; $value = 1; $key = array('Tracker', 'tracker_sessions', 'tracker_perf', 'tracker_queries'); $admin = new Administration(); foreach ($key as $k) { $admin->saveSetting($category, $k, $value); } } else { $query = "select count(name) as total from config where category = 'tracker' and name = 'Tracker'"; $results = $db->query($query); if (!empty($results)) { $row = $db->fetchByAssoc($results); $total = $row['total']; if ($GLOBALS['sugar_flavor'] == 'PRO' || $GLOBALS['sugar_flavor'] == 'ENT') { //Fix problem with having multiple tracker entries in config table if ($total > 1) { $db->query("DELETE FROM config where category = 'tracker' and name = 'Tracker'"); $db->query("INSERT INTO config (category, name, value) VALUES ('tracker', 'Tracker', '1')"); } } else { //We are assuming if the 'Tracker' setting is not disabled then we will just disable it if ($total == 0) { $db->query("INSERT INTO config (category, name, value) VALUES ('tracker', 'Tracker', '1')"); } } } } //Write the entries to cache/dashlets/dashlets.php if (file_exists($cachedfile = sugar_cached('dashlets/dashlets.php'))) { require $cachedfile; foreach ($upgradeTrackingDashlets as $id => $entry) { if (!isset($dashletsFiles[$id])) { $dashletsFiles[$id] = $entry; } } write_array_to_file("dashletsFiles", $dashletsFiles, $cachedfile); } //if }