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)); } }
function execute(&$response) { $session = new syncml_session(); // process every command in message for ($i = 0, $c = count($this->commands); $i < $c; $i++) { $this->commands[$i]->execute($response, $session); } // output modifications in form of SYNC commands, but only when // client has sent all its modifications first if ($session->get_var(SYNCML_NOMOREMODIFICATIONS)) { $open_channels = $session->get_open_channels(); $response->set_final(TRUE); foreach ($open_channels as $open_channel) { $database = new syncml_database($open_channel['channel_id']); if (!$open_channel['server_modifications_sent']) { /* This code is run *after* all modifications from client are sent and *before* any modfifications are sent by the server. */ // LUIDs modified by the *client* during this session $all_modified_luids = $session->get_all_modified_luids($open_channel['channel_id']); // GUIDs modified by the *client* during this session $all_modified_guids = $session->get_all_modified_guids($open_channel['channel_id']); // Bring all changed items from phpgw $database->merge_changes($all_modified_guids); switch ($open_channel['type']) { case SYNCML_ALERT_SLOWSYNC: $this->prepare_slowsync($open_channel['channel_id'], $all_modified_luids); break; case SYNCML_ALERT_REFRESHFROMSERVER: case SYNCML_ALERT_REFRESHFROMSERVERBYSERVER: $somappings->delete_mapping($open_channel['channel_id'], NULL, NULL, NULL); break; case SYNCML_ALERT_REFRESHFROMCLIENT: case SYNCML_ALERT_REFRESHFROMCLIENTBYSERVER: $this->finish_client_refresh($open_channel['channel_id'], $all_client_modified_luids, $database); break; } } if (!$open_channel['all_server_modifications_sent']) { $more_to_send = $this->_send_modifications($response, $session, $open_channel, $database); $session->set_open_channel_property($open_channel['source'], $open_channel['target'], 'server_modifications_sent', TRUE); if ($more_to_send) { // there's more to send from this channel. we // continue with that in next message. $response->set_final(FALSE); break; } else { $session->set_open_channel_property($open_channel['source'], $open_channel['target'], 'all_server_modifications_sent', TRUE); } } } } // do we have to send a ALERT for more messages? if ($response->status_commands_only() && !$response->is_final()) { $cmdid = $response->add_alert(SYNCML_ALERT_NEXTMESSAGE, array()); } // save the anchors if this is last message in session if ($response->status_commands_only()) { $session->commit_anchors(); } $session->commit(); }