improved handling of slowsync and twowaysync

This commit is contained in:
Lars Kneschke 2006-07-09 07:27:23 +00:00
parent 8f5467044a
commit 46b151baa4
2 changed files with 173 additions and 172 deletions

View File

@ -19,29 +19,20 @@ include_once 'Horde/SyncML/Sync/TwoWaySync.php';
* @package Horde_SyncML
*/
class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
function handleSync($currentCmdID, $hordeType, $syncType,&$output, $refts)
{
function handleSync($currentCmdID, $hordeType, $syncType,&$output, $refts) {
global $registry;
$history = $GLOBALS['phpgw']->contenthistory;
$history = $GLOBALS['egw']->contenthistory;
$state = &$_SESSION['SyncML.state'];
$adds = &$state->getAddedItems($hordeType);
#if($adds === FALSE)
#{
# Horde::logMessage("SyncML: reading added items from database", __FILE__, __LINE__, PEAR_LOG_DEBUG);
# $state->setAddedItems($hordeType, $registry->call($hordeType. '/list', array()));
# $adds = &$state->getAddedItems($hordeType);
#}
Horde::logMessage("SyncML: ".count($adds). ' added items found for '.$hordeType , __FILE__, __LINE__, PEAR_LOG_DEBUG);
$serverAnchorNext = $state->getServerAnchorNext($syncType);
$counter = 0;
while($guid = array_shift($adds))
{
if(is_array($adds)) {
while($guid = array_shift($adds)) {
#$guid_ts = max($history->getTSforAction($guid, 'add'),$history->getTSforAction($guid, 'modify'));
$sync_ts = $state->getChangeTS($syncType, $guid);
#Horde::logMessage("SyncML: slowsync timestamp add: $guid sync_ts: $sync_ts anchorNext: ". $serverAnchorNext.' / '.time(), __FILE__, __LINE__, PEAR_LOG_DEBUG);
@ -67,7 +58,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
$cmd = &new Horde_SyncML_Command_Sync_ContentSyncElement();
$c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType));
#Horde::logMessage("SyncML: slowsync add to server $c", __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage("SyncML: slowsync add to client $c", __FILE__, __LINE__, PEAR_LOG_DEBUG);
if (!is_a($c, 'PEAR_Error')) {
// Item in history but not in database. Strange, but
// can happen.
@ -76,6 +67,7 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
if($hordeType == 'sifcalendar' || $hordeType == 'sifcontacts' || $hordeType == 'siftasks') {
$cmd->setContentFormat('b64');
}
$cmd->setContentType($contentType['ContentType']);
$cmd->setSourceURI($guid);
$currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Add');
@ -89,6 +81,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
}
}
}
}
#Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->clearSync($syncType);

View File

@ -19,14 +19,13 @@ include_once 'Horde/SyncML/Command/Sync/ContentSyncElement.php';
* @package Horde_SyncML
*/
class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
function endSync($currentCmdID, &$output)
{
function endSync($currentCmdID, &$output) {
global $registry;
$state = &$_SESSION['SyncML.state'];
$syncType = $this->_targetLocURI;
$hordeType = str_replace('./','',$syncType);
$refts = $state->getServerAnchorLast($syncType);
@ -35,6 +34,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
$syncType,
$output,
$refts);
if ($syncType == 'calendar' && $state->handleTasksInCalendar()) {
Horde::logMessage("SyncML: handling tasks in calendar sync", __FILE__, __LINE__, PEAR_LOG_DEBUG);
@ -63,6 +63,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
Horde::logMessage("SyncML: ".count($deletes).' deleted items found for '.$hordeType, __FILE__, __LINE__, PEAR_LOG_DEBUG);
Horde::logMessage("SyncML: ".count($adds). ' added items found for '.$hordeType , __FILE__, __LINE__, PEAR_LOG_DEBUG);
// handle changes
if(is_array($changes)) {
while($guid = array_shift($changes)) {
$guid_ts = $history->getTSforAction($guid, 'modify');
$sync_ts = $state->getChangeTS($syncType, $guid);
@ -112,11 +114,12 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
}
}
}
}
Horde::logMessage("SyncML: handling sync (changes done) ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG);
// deletes
while($guid = array_shift($deletes))
{
// handle deletes
if(is_array($deletes)) {
while($guid = array_shift($deletes)) {
$guid_ts = $history->getTSforAction($guid, 'delete');
$sync_ts = $state->getChangeTS($syncType, $guid);
Horde::logMessage("SyncML: timestamp delete guid_ts: $guid_ts sync_ts: $sync_ts", __FILE__, __LINE__, PEAR_LOG_DEBUG);
@ -126,6 +129,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
Horde::logMessage("SyncML: delete $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG);
continue;
}
$locid = $state->getLocID($syncType, $guid);
if (!$locid) {
Horde::logMessage("SyncML: unable to create delete for $guid: locid not found in map", __FILE__, __LINE__, PEAR_LOG_WARNING);
@ -147,9 +151,10 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
return $currentCmdID;
}
}
}
#Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG);
// Get adds.
// handle missing adds.
if(count($missedAdds) > 0) {
Horde::logMessage("SyncML: add missed changes as adds ".count($adds).' / '.$missedAdds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->setAddedItems($hordeType, array_merge($adds, $missedAdds));
@ -157,6 +162,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
Horde::logMessage("SyncML: merged adds counter ".count($adds).' / '.$adds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG);
}
if(is_array($adds)) {
while($guid = array_shift($adds)) {
$guid_ts = $history->getTSforAction($guid, 'add');
$sync_ts = $state->getChangeTS($syncType, $guid);
@ -212,6 +218,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync {
}
}
}
}
Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->clearSync($syncType);