Esempio n. 1
0
     echo '<script>document.getElementById("sync").submit();</script>';
     die;
 } else {
     $result = $soapclient->call('logout', array('session' => $session));
     update_progress_bar('Total', 100, 100);
     $sync_end_time = $soapclient->call('get_gmt_time', array());
     foreach ($sync_info as $key => $val) {
         $sync_info[$key] = $sync_end_time;
     }
     $sync_info['last_sync' . $sync_module] = $sync_end_time;
     $sync_info['local_last_sync' . $sync_module] = $local_time;
     unset($_SESSION['sync_start_time']);
     require_once 'include/utils/file_utils.php';
     add_to_msg('Storing Sync Info', false);
     write_array_to_file('sync_info', $sync_info, 'modules/Sync/config.php');
     add_to_msg('<b>Sync Complete</b>', false);
     $_REQUEST['do_action'] = 'execute';
     $_REQUEST['repair_silent'] = true;
     global $current_user;
     $current_user->is_admin = '1';
     require_once 'ModuleInstall/ModuleInstaller.php';
     global $mod_strings, $current_language;
     $mod_strings = return_module_language($current_language, 'Administration');
     $mi = new ModuleInstaller();
     $mi->rebuild_all();
     $current_user->is_admin = '0';
     echo '<script>document.getElementById("stop_sync_btn").value="Done"</script>';
     echo '<script>opener.location.href = "index.php?module=Home&action=index";</script>';
     update_progress_bar('Total', sizeof($sync_modules), sizeof($sync_modules));
     //$current_user->setPreference('last_sync'.  $sync_module, $start_time);
     clear_sync_session();
Esempio n. 2
0
function sync_users($soapclient, $session, $clean = false, $is_conversion = false)
{
    $timedate = TimeDate::getInstance();
    global $current_user;
    $last_sync = '1980-07-09 12:00:00';
    $user_id = $soapclient->call('get_user_id', array('session' => $session));
    if ($user_id == '-1') {
        return false;
    }
    if (!$clean && file_exists('modules/Sync/config.php')) {
        require_once 'modules/Sync/config.php';
        if (isset($sync_info['last_syncUsers'])) {
            $last_sync = $sync_info['last_syncUsers'];
        }
    } else {
        clean_for_sync('Users');
        $clean = true;
    }
    $start_time = $timedate->nowDb();
    $GLOBALS['sugar_config']['disable_team_sanity_check'] = true;
    //rrs: bug 27579. This works fine for most installs, but we had a customer in switzerland and the quotes where being
    //removed from the users.id = '<GUID>' in the where clause causing the query to fail.
    $soapclient->charencoding = false;
    $result = $soapclient->call('sync_get_entries', array('session' => $session, 'module_name' => 'Users', 'from_date' => $last_sync, 'to_date' => $start_time, 'offset' => 0, 'max_results' => -99, 'select_fields' => array(), 'query' => "users.id = '{$user_id}'", 'deleted' => 2));
    add_to_msg('Retrieve Current User Record<br>', true, true);
    if (!has_error($result)) {
        //update_progress_bar('records', 55 , 100);
        add_to_msg('Retrieved ' . $result['result_count'] . ' current User Record<br>', true, true);
        $get_entry_list = get_decoded($result['entry_list']);
        //update_progress_bar('records', 65 , 100);
        $done = save_altered('Users', $get_entry_list);
        //update_progress_bar('records', 100 , 100);
        $offset = 0;
        while (true) {
            $result = $soapclient->call('sync_get_entries', array('session' => $session, 'module_name' => 'Users', 'from_date' => $last_sync, 'to_date' => $start_time, 'offset' => $offset, 'max_results' => 50, 'select_fields' => array('user_name', 'id', 'first_name', 'last_name', 'phone_mobile', 'phone_work', 'employee_status', 'reports_to_id', 'title', 'email1', 'email2', 'deleted', 'status'), 'query' => "users.id != '{$user_id}'", 'deleted' => 2));
            if (!has_error($result)) {
                //update_progress_bar('records', 55 , 100);
                add_to_msg('Retrieved ' . $result['result_count'] . ' Records<br>', true, true);
                $get_entry_list = get_decoded($result['entry_list']);
                //update_progress_bar('records', 65 , 100);
                $done = save_altered('Users', $get_entry_list);
                //update_progress_bar('records', 100 , 100);
                add_to_msg('Added ' . $done['add'] . ' Records <br>', true, true);
                add_to_msg('Modified ' . $done['modify'] . ' Records <br>', true, true);
                add_to_msg('Done<br>', true, true);
                if ($result['next_offset'] > $result['total_count']) {
                    break;
                } else {
                    $offset = $result['next_offset'];
                }
            }
        }
        //end while
        restoreUserPassword($user_id);
        require_once 'modules/Sync/config.php';
        $sync_info['last_syncUsers'] = $start_time;
        add_to_msg('Storing Sync Info<BR>', true, true);
        write_array_to_file('sync_info', $sync_info, 'modules/Sync/config.php');
        if ($clean) {
            //now save the admin account/current user back if it's a clean sync just so we can make sure they still exist
            if (empty($current_user->id)) {
                //retrieve the admin user
                $current_user = BeanFactory::getBean('Users', '1');
            }
            $temp_user = BeanFactory::getBean('Users');
            if (!$temp_user->retrieve($current_user->id)) {
                $current_user->new_with_id = true;
                $current_user->team_exists = true;
            }
            unset($current_user->user_preferences);
            //rrs: bug - 32739
            $current_user->default_team = null;
            if (!isset($is_conversion) || $is_conversion == false) {
                $current_user->save(false);
            }
        }
        $GLOBALS['sugar_config']['disable_team_sanity_check'] = false;
        return true;
    }
    if ($clean) {
        //now save the admin account/current user back if it's a clean sync just so we can make sure they still exist
        $temp_user = BeanFactory::getBean('Users');
        if (!$temp_user->retrieve($current_user->id)) {
            $current_user->new_with_id = true;
            $current_user->team_exists = true;
        }
        unset($current_user->user_preferences);
        //rrs: bug - 32739
        $current_user->default_team = null;
        if (!isset($is_conversion) || $is_conversion == false) {
            $current_user->save(false);
        }
    }
    $GLOBALS['sugar_config']['disable_team_sanity_check'] = false;
    return false;
}
Esempio n. 3
0
                    // insert a new database row to show the rebuild extensions is done
                    $id = create_guid();
                    $gmdate = TimeDate::getInstance()->nowDb();
                    $date_entered = db_convert("'{$gmdate}'", 'datetime');
                    $query = 'INSERT INTO versions (id, deleted, date_entered, date_modified, modified_user_id, created_by, name, file_version, db_version) ' . "VALUES ('{$id}', '0', {$date_entered}, {$date_entered}, '1', '1', 'Rebuild Extensions', '4.0.0', '4.0.0')";
                    $db->query($query);
                    $current_step++;
                    update_progress_bar('sync_setup', $current_step, $module_steps);
                    add_to_msg('Done updating files<br>');
                    add_to_msg('Updating User Information<br>');
                    $current_step++;
                    update_progress_bar('sync_setup', $current_step, $module_steps);
                    sync_users($soapclient, $session, $_REQUEST['clean_sync']);
                    $current_step++;
                    update_progress_bar('sync_setup', $current_step, $module_steps);
                    add_to_msg('Done Updating User Information<br>');
                }
                //end new sync
                destroy_flow_bar('file_update');
                echo '<script>document.location.href = "index.php?&action=Popup&module=Sync&sync_module_index=0&new_sync=true&clean_sync=' . $_REQUEST['clean_sync'] . '&global_accept_server=' . $_REQUEST['global_accept_server'] . '";</script>';
                die;
            }
        } else {
            add_to_msg('Server and Client must both be running the same flavor of Sugar.');
        }
    } else {
        add_to_msg('Your Offline Client instance has been disabled by your administrator');
    }
} else {
    add_to_msg('Failed to Login<br>');
}