function _process_sync_init(&$response, &$session) { $sodatabase = new syncml_sodatabase(); $sochannel = new syncml_sochannel(); syncml_logger::get_instance()->log_data("_process_sync_init item", $this->item[0]); $database = $sodatabase->get_database_by_uri($this->item[0]['target']['locuri']); $database_id = $database['database_id']; $owner_id = $database['account_id']; syncml_logger::get_instance()->log("_process_sync_init user {$database_id} {$owner_id} "); $status = $this->validate_database($database_id, $owner_id, $session->account_id); syncml_logger::get_instance()->log("_process_sync_init status {$status} "); if (!$status) { list($channel_id, $device_last, $phpgw_last) = $sochannel->get_channel_by_database_and_device($this->item[0]['target']['locuri'], $session->get_var('device_uri')); $status = $this->validate_channel($device_last); } syncml_logger::get_instance()->log_data("_process_sync_init status", $status); $response->add_status_with_anchor($this->cmdid, $session->msgid, 'Alert', $this->item[0]['target']['locuri'], $this->item[0]['source']['locuri'], $status[0], $this->item[0]['meta']['anchor']['next']); if ($status[0] == SYNCML_STATUS_OK || $status[0] == SYNCML_STATUS_REFRESHREQUIRED) { syncml_logger::get_instance()->log_data("_process_sync_init ok channel ", $channel_id); if (!$channel_id) { $channel_id = $sochannel->insert_channel($database_id, $session->get_var('device_uri')); } syncml_logger::get_instance()->log_data("_process_sync_init channel ", $channel_id); $database = new syncml_database($channel_id); $database->merge_changes(); unset($database); // todo: make iso 8601 instead. $phpgw_next = time(); // save phpgw and device next anchors $session->save_next_device_anchor($channel_id, $this->item[0]['meta']['anchor']['next']); $session->save_next_phpgw_anchor($channel_id, $phpgw_next); // save this suggested sync $session->set_open_channel($this->item[0]['target']['locuri'], $this->item[0]['source']['locuri'], $channel_id, $status[1], min(isset($this->item[0]['meta']['maxobjsize']) ? $this->item[0]['meta']['maxobjsize'] : 0, SYNCML_MAXOBJSIZE)); // output alert with phpgw next anchor $cmdid = $response->add_alert($status[1], array('trg_uri' => $this->item[0]['source']['locuri'], 'src_uri' => $this->item[0]['target']['locuri'], 'meta' => array('last' => empty($phpgw_last) ? NULL : $phpgw_last, 'next' => $phpgw_next, 'maxobjsize' => SYNCML_MAXOBJSIZE)), (bool) $session->get_var(SYNCML_SUPPORTLARGEOBJS)); } }
/** * Merge information about changes from phpgw to the mappings table. * * @param $except_list Array of GUIDs not to merge. * @return int Number of changes merged. */ function merge_changes($except_list = array()) { syncml_logger::get_instance()->log_data("merge_changes : ipc set ", is_object($this->ipc) ? 'true' : 'false'); if (!$this->ipc) { return 0; } $sochannel = new syncml_sochannel(); list(, , , $last_merge) = $sochannel->get_channel($this->channel_id); syncml_logger::get_instance()->log_data("merge_changes last_merge : ", $last_merge); $changed_guids = array_diff($this->ipc->getIdList($last_merge), $except_list); syncml_logger::get_instance()->log_data("merge_changes changed_guids : ", $changed_guids); foreach ($changed_guids as $guid) { syncml_logger::get_instance()->log_data("merge_changes guid : ", $guid); $this->somappings->update_mapping($this->channel_id, NULL, $guid, 1); syncml_logger::get_instance()->log_data("merge_changes update_mapping done for guids : ", $guid); } $sochannel->update_last_merge($this->channel_id); syncml_logger::get_instance()->log("merge_changes update_last_merge done for " . $this->channel_id); }
function commit_anchors() { $next_anchors = $this->get_var('next_anchors'); if (is_array($next_anchors)) { foreach ($next_anchors as $channel_id => $nexts) { $sochannel = new syncml_sochannel(); $sochannel->set_anchors($channel_id, isset($nexts['device']) ? $nexts['device'] : NULL, isset($nexts['phpgw']) ? $nexts['phpgw'] : NULL); } } }