protected function createUser($userData)
 {
     $user = new User();
     $user->user_name = $userData['email'];
     $user->email = $userData['email'];
     $user->email1 = $userData['email'];
     $user->first_name = $userData['first_name'];
     $user->last_name = $userData['last_name'];
     $user->status = 'Active';
     $user->is_admin = 0;
     $user->external_auth_only = 1;
     $user->system_generated_password = 0;
     $user->authenticate_id = $userData['remote_id'];
     $user->receive_notifications = 0;
     if (!empty($userData['photo'])) {
         $picid = create_guid();
         if (copy($userData['photo'], "upload://{$picid}")) {
             $user->picture = $picid;
         }
     }
     $user->id = 'rmt-' . md5($userData['remote_id']);
     $user->new_with_id = true;
     $user->save();
     $user->setPreference('ut', 1);
     $user->savePreferencesToDB();
     return $user->id;
 }
예제 #2
0
 /**
  *  Create a user in the seed data.
  */
 function _create_seed_user($id, $last_name, $first_name, $user_name, $title, $is_admin, $reports_to, $reports_to_name, $email)
 {
     $u = new User();
     $u->id = $id;
     $u->new_with_id = true;
     $u->last_name = $last_name;
     $u->first_name = $first_name;
     $u->user_name = $user_name;
     $u->title = $title;
     $u->status = 'Active';
     $u->employee_status = 'Active';
     $u->is_admin = $is_admin;
     $u->is_group = 0;
     //$u->user_password = $u->encrypt_password($user_name);
     $u->user_hash = User::getPasswordHash($user_name);
     $u->reports_to_id = $reports_to;
     $u->reports_to_name = $reports_to_name;
     //$u->email1 = $email;
     $u->emailAddress->addAddress($email, true);
     $u->emailAddress->addAddress("reply." . $email, false, true);
     $u->emailAddress->addAddress("alias." . $email);
     // bug 15371 tyoung set a user preference so that Users/DetailView.php can find something without repeatedly querying the db in vain
     $u->setPreference('max_tabs', '7');
     $u->savePreferencesToDB();
     $u->picture = $this->_copy_user_image($id);
     $u->save();
     if ($id == "seed_jim_id") {
         // add to Sales Administrator Role
         $acl_roles = new ACLRole();
         $arrRoles = $acl_roles->getAllRoles(true);
         foreach ($arrRoles as $role) {
             if ($role['name'] == "Sales Administrator") {
                 $u->load_relationship('aclroles');
                 $u->aclroles->add($role['id']);
                 // re-save user manually. otherwise the relation to role set will not be saved
                 // because One2MBeanRelationship::add() doesn't call SugarRelationship::addToResaveList()
                 // in workflow and during installation
                 $u->save();
                 break;
             }
         }
     }
 }
예제 #3
0
/**
 * 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
}
예제 #4
0
 /**
  * Method removes module from global search configurations
  *
  * return bool
  */
 public function uninstall_global_search()
 {
     if (empty($this->installdefs['beans'])) {
         return true;
     }
     if (is_file('custom/modules/unified_search_modules_display.php') == false) {
         return true;
     }
     $user = new User();
     $users = get_user_array();
     $unified_search_modules_display = array();
     require 'custom/modules/unified_search_modules_display.php';
     foreach ($this->installdefs['beans'] as $beanDefs) {
         if (array_key_exists($beanDefs['module'], $unified_search_modules_display) == false) {
             continue;
         }
         unset($unified_search_modules_display[$beanDefs['module']]);
         foreach ($users as $userId => $userName) {
             if (empty($userId)) {
                 continue;
             }
             $user->retrieve($userId);
             $prefs = $user->getPreference('globalSearch', 'search');
             if (array_key_exists($beanDefs['module'], $prefs) == false) {
                 continue;
             }
             unset($prefs[$beanDefs['module']]);
             $user->setPreference('globalSearch', $prefs, 0, 'search');
             $user->savePreferencesToDB();
         }
     }
     if (write_array_to_file("unified_search_modules_display", $unified_search_modules_display, 'custom/modules/unified_search_modules_display.php') == false) {
         global $app_strings;
         $msg = string_format($app_strings['ERR_FILE_WRITE'], array('custom/modules/unified_search_modules_display.php'));
         $GLOBALS['log']->error($msg);
         throw new Exception($msg);
         return false;
     }
     return true;
 }
예제 #5
0
 /**
  *  Create a user in the seed data.
  */
 function _create_seed_user($id, $last_name, $first_name, $user_name, $title, $is_admin, $reports_to, $reports_to_name, $email)
 {
     $u = new User();
     $u->id = $id;
     $u->new_with_id = true;
     $u->last_name = $last_name;
     $u->first_name = $first_name;
     $u->user_name = $user_name;
     $u->title = $title;
     $u->status = 'Active';
     $u->employee_status = 'Active';
     $u->is_admin = $is_admin;
     //$u->user_password = $u->encrypt_password($user_name);
     $u->user_hash = User::getPasswordHash($user_name);
     $u->reports_to_id = $reports_to;
     $u->reports_to_name = $reports_to_name;
     //$u->email1 = $email;
     $u->emailAddress->addAddress($email, true);
     $u->emailAddress->addAddress("reply." . $email, false, true);
     $u->emailAddress->addAddress("alias." . $email);
     // bug 15371 tyoung set a user preference so that Users/DetailView.php can find something without repeatedly querying the db in vain
     $u->setPreference('max_tabs', '7');
     $u->savePreferencesToDB();
     $u->picture = $this->_copy_user_image($id);
     $u->save();
 }
예제 #6
0
 public function testsavePreferencesToDB()
 {
     //unset and reconnect Db to resolve mysqli fetch exeception
     global $db;
     unset($db->database);
     $db->checkConnection();
     $user = new User();
     $user->retrieve(1);
     //execute the method and test if it works and does not throws an exception.
     try {
         $user->savePreferencesToDB();
         $this->assertTrue(true);
     } catch (Exception $e) {
         $this->fail();
     }
 }
예제 #7
0
/**
 * 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
}