function sync_set_relationships($session, $module_name, $related_module, $from_date, $to_date, $sync_entry_list, $deleted) { global $beanList, $beanFiles; global $current_user; $error = new SoapError(); $output_list = array(); if (!validate_authenticated($session)) { $error->set_error('invalid_login'); return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array()); } if (empty($beanList[$module_name]) || empty($beanList[$related_module])) { $error->set_error('no_module'); return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array()); } require_once 'modules/Sync/SyncController.php'; if (!check_modules_access($current_user, $module_name, 'write') && !in_array($module_name, $read_only_override) || !check_modules_access($current_user, $related_module, 'write') && !in_array($related_module, $read_only_override)) { $error->set_error('no_access'); return array('result_count' => -1, 'entry_list' => array(), 'error' => $error->get_soap_array()); } $entry_list = get_decoded($sync_entry_list); $done = server_save_relationships($entry_list, $from_date, $to_date); $conflicts = array(); $con_enc = get_encoded($conflicts); return array('conflicts' => $con_enc, 'status' => 'success', 'ids' => $done['ids'], 'error' => $error->get_soap_array()); }
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; }
update_progress_bar('records', 0, 100); $next_off = $rel_offset + $rel_max; add_to_msg('Retrieving Server Relationships - ' . $related . "[{$rel_offset} - {$next_off}] <br>", false); if ($clean_sync == 1) { $result = $soapclient->call('get_quick_sync_data', array('session' => $session, 'module_name' => $sync_module, 'related_module_name' => $related, 'start' => $rel_offset, 'count' => $rel_max, 'db_type' => $sugar_config['dbconfig']['db_type'], 'deleted' => 2)); } else { $result = $soapclient->call('sync_get_relationships', array('session' => $session, 'module_name' => $sync_module, 'related_module' => $related, 'from_date' => $last_sync, 'to_date' => $start_time, 'offset' => $rel_offset, 'max_results' => $rel_max, 'deleted' => 2)); } if (!has_error($result)) { update_progress_bar('records', 50, 100); if ($clean_sync == 1) { $result_arr = unserialize(base64_decode($result['result'])); execute_query($sync_module, $result_arr['data']); execute_query($sync_module, $result_arr['cstm']); } else { $list = get_decoded($result['entry_list']); $done = client_save_relationships($list); add_to_msg('Retrieved ' . $result['result_count'] . ' Records<br>', false); add_to_msg('Added ' . $done['add'] . ' Records <br>', false); add_to_msg('Modified ' . $done['modify'] . ' Records <br>', false); } $total_count = $result['total_count']; if ($result['next_offset'] < $result['total_count']) { store_msg(); echo '<input type="hidden" name="sync_module_index" value="' . $sync_module_index . '">'; echo "<input type='hidden' id='rel_offset' name='rel_offset' value='" . $result['next_offset'] . "'>"; echo "<input type='hidden' id='rel_count' name='rel_count' value='" . $result['total_count'] . "'>"; echo "<input type='hidden' id='rel_index' name='rel_index' value='" . $ri . "'>"; echo '<script>document.getElementById("sync").submit();</script>'; sugar_cleanup(true); } else {