Fix SlowSync timestamp issue (#2663)

This commit is contained in:
Jörg Lehrke 2010-06-19 15:31:01 +00:00
parent bdd7bb2c64
commit 0db219ca7d
2 changed files with 47 additions and 43 deletions

View File

@ -208,16 +208,16 @@ class Horde_SyncML_Sync {
foreach($syncElementItems as $syncItem) { foreach($syncElementItems as $syncItem) {
$guid = false; $guid = false;
$locURI = $syncItem->getLocURI();
if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) { if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) {
if ($sync_conflicts > CONFLICT_RESOLVED_WITH_DUPLICATE) { if ($sync_conflicts > CONFLICT_RESOLVED_WITH_DUPLICATE) {
// We enforce the client not to change anything // We enforce the client not to change anything
if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) {
// delete this item from client // delete this item from client
Horde::logMessage('SyncML: Server RO! REMOVE ' Horde::logMessage("SyncML: Server RO! REMOVE $locURI from client",
. $syncItem->getLocURI() . ' from client',
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$state->addConflictItem($type, $syncItem->getLocURI()); $state->addConflictItem($type, $locURI);
} else { } else {
Horde::logMessage('SyncML: Server RO! ' Horde::logMessage('SyncML: Server RO! '
. 'REJECT all client changes', . 'REJECT all client changes',
@ -232,22 +232,22 @@ class Horde_SyncML_Sync {
if (!is_a($guid, 'PEAR_Error') && $guid != false) { if (!is_a($guid, 'PEAR_Error') && $guid != false) {
$ts = $state->getSyncTSforAction($guid, 'add'); $ts = $state->getSyncTSforAction($guid, 'add');
$state->setUID($type, $syncItem->getLocURI(), $guid, $ts); $state->setUID($type, $locURI, $guid, $ts);
$state->log('Client-Add'); $state->log('Client-Add');
Horde::logMessage('SyncML: added client entry as ' Horde::logMessage("SyncML: added client entry $locURI as $guid",
. $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
} else { } else {
$state->log('Client-AddFailure'); $state->log('Client-AddFailure');
Horde::logMessage('SyncML: Error in adding client entry: ' Horde::logMessage('SyncML: Error in adding client entry ' . $locURI . ': '
. $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR);
} }
} elseif (is_a($command, 'Horde_SyncML_Command_Sync_Delete')) { } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Delete')) {
$guid = $state->removeUID($type, $syncItem->getLocURI()); $guid = $state->removeUID($type, $locURI);
if (!$guid) { if (!$guid) {
// the entry is no longer on the server // the entry is no longer on the server
$state->log('Client-DeleteFailure'); $state->log('Client-DeleteFailure');
Horde::logMessage('SyncML: Failure deleting client entry, ' Horde::logMessage('SyncML: Failure deleting client entry ' . $locURI
. 'gone already on server!', . ', gone on server already!',
__FILE__, __LINE__, PEAR_LOG_ERR); __FILE__, __LINE__, PEAR_LOG_ERR);
continue; continue;
} }
@ -292,28 +292,28 @@ class Horde_SyncML_Sync {
if (!is_a($guid, 'PEAR_Error') && $guid != false) { if (!is_a($guid, 'PEAR_Error') && $guid != false) {
$registry->call($hordeType . '/delete', array($guid)); $registry->call($hordeType . '/delete', array($guid));
$ts = $state->getSyncTSforAction($guid, 'delete'); $ts = $state->getSyncTSforAction($guid, 'delete');
$state->setUID($type, $syncItem->getLocURI(), $guid, $ts, 1); $state->setUID($type, $locURI, $guid, $ts, 1);
$state->log('Client-Delete'); $state->log('Client-Delete');
Horde::logMessage('SyncML: deleted entry ' Horde::logMessage('SyncML: deleted entry '
. $guid . ' due to client request', . $guid . ' due to client request',
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
} else { } else {
$state->log('Client-DeleteFailure'); $state->log('Client-DeleteFailure');
Horde::logMessage('SyncML: Failure deleting client entry, ' Horde::logMessage('SyncML: Failure deleting client entry ' . $locURI
. 'maybe gone already on server. msg: ' . ', maybe gone on server already: '
. $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR);
} }
} elseif (is_a($command, 'Horde_SyncML_Command_Sync_Replace')) { } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Replace')) {
$guid = $state->getGlobalUID($type, $syncItem->getLocURI()); $guid = $state->getGlobalUID($type, $locURI);
$replace = true; $replace = true;
$ok = false; $ok = false;
$merge = false; $merge = false;
if ($guid) if ($guid)
{ {
Horde::logMessage('SyncML: locuri '. $syncItem->getLocURI() . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_DEBUG); Horde::logMessage('SyncML: locuri '. $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_DEBUG);
if (($sync_conflicts > CONFLICT_RESOLVED_WITH_DUPLICATE) || in_array($guid, $changes)) if (($sync_conflicts > CONFLICT_RESOLVED_WITH_DUPLICATE) || in_array($guid, $changes))
{ {
Horde::logMessage('SyncML: CONFLICT for locuri '. $syncItem->getLocURI() . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); Horde::logMessage('SyncML: CONFLICT for locuri ' . $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING);
switch ($sync_conflicts) switch ($sync_conflicts)
{ {
case CONFLICT_CLIENT_WINNING: case CONFLICT_CLIENT_WINNING:
@ -321,7 +321,7 @@ class Horde_SyncML_Sync {
break; break;
case CONFLICT_SERVER_WINNING: case CONFLICT_SERVER_WINNING:
Horde::logMessage('SyncML: REJECT client change for locuri ' . Horde::logMessage('SyncML: REJECT client change for locuri ' .
$syncItem->getLocURI() . ' guid ' . $guid , $locURI . ' guid ' . $guid ,
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$ok = true; $ok = true;
$replace = false; $replace = false;
@ -329,7 +329,7 @@ class Horde_SyncML_Sync {
break; break;
case CONFLICT_MERGE_DATA: case CONFLICT_MERGE_DATA:
Horde::logMessage('SyncML: Merge server and client data for locuri ' . Horde::logMessage('SyncML: Merge server and client data for locuri ' .
$syncItem->getLocURI() . ' guid ' . $guid , $locURI . ' guid ' . $guid ,
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$merge = true; $merge = true;
break; break;
@ -338,17 +338,17 @@ class Horde_SyncML_Sync {
break; break;
case CONFLICT_CLIENT_CHANGES_IGNORED: case CONFLICT_CLIENT_CHANGES_IGNORED:
Horde::logMessage('SyncML: Server RO! REJECT client change for locuri ' . Horde::logMessage('SyncML: Server RO! REJECT client change for locuri ' .
$syncItem->getLocURI() . ' guid ' . $guid , $locURI . ' guid ' . $guid ,
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$ok = true; $ok = true;
$replace = false; $replace = false;
$ts = $state->getSyncTSforAction($guid, 'modify'); $ts = $state->getSyncTSforAction($guid, 'modify');
$state->setUID($type, $syncItem->getLocURI(), $guid, $ts); $state->setUID($type, $locURI, $guid, $ts);
$state->log('Client-AddReplaceIgnored'); $state->log('Client-AddReplaceIgnored');
break; break;
default: // We enforce our data on client default: // We enforce our data on client
Horde::logMessage('SyncML: Server RO! UNDO client change for locuri ' . Horde::logMessage('SyncML: Server RO! UNDO client change for locuri ' .
$syncItem->getLocURI() . ' guid ' . $guid , $locURI . ' guid ' . $guid ,
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$state->pushChangedItem($type, $guid); $state->pushChangedItem($type, $guid);
$ok = true; $ok = true;
@ -358,7 +358,7 @@ class Horde_SyncML_Sync {
elseif ($sync_conflicts == CONFLICT_MERGE_DATA) elseif ($sync_conflicts == CONFLICT_MERGE_DATA)
{ {
Horde::logMessage('SyncML: Merge server and client data for locuri ' . Horde::logMessage('SyncML: Merge server and client data for locuri ' .
$syncItem->getLocURI() . ' guid ' . $guid , $locURI . ' guid ' . $guid ,
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$merge = true; $merge = true;
} }
@ -372,15 +372,15 @@ class Horde_SyncML_Sync {
if (!is_a($ok, 'PEAR_Error') && $ok != false) if (!is_a($ok, 'PEAR_Error') && $ok != false)
{ {
$ts = $state->getSyncTSforAction($guid, 'modify'); $ts = $state->getSyncTSforAction($guid, 'modify');
$state->setUID($type, $syncItem->getLocURI(), $guid, $ts); $state->setUID($type, $locURI, $guid, $ts);
if ($merge) if ($merge)
{ {
Horde::logMessage('SyncML: Merged entry due to client request guid: ' . Horde::logMessage('SyncML: Merged entry ' . $locURI . ' due to client request guid: ' .
$guid . ' ts: ' . $ts, __FILE__, __LINE__, PEAR_LOG_DEBUG); $guid . ' ts: ' . $ts, __FILE__, __LINE__, PEAR_LOG_DEBUG);
} }
else else
{ {
Horde::logMessage('SyncML: replaced entry due to client request guid: ' . Horde::logMessage('SyncML: replaced entry ' . $locURI . ' due to client request guid: ' .
$guid . ' ts: ' . $ts, __FILE__, __LINE__, PEAR_LOG_DEBUG); $guid . ' ts: ' . $ts, __FILE__, __LINE__, PEAR_LOG_DEBUG);
} }
$state->log('Client-Replace'); $state->log('Client-Replace');
@ -401,7 +401,7 @@ class Horde_SyncML_Sync {
// We enforce the client not to change anything // We enforce the client not to change anything
if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) {
// delete this item from client // delete this item from client
Horde::logMessage('SyncML: Server RO! REMOVE ' . $syncItem->getLocURI() . ' from client', Horde::logMessage('SyncML: Server RO! REMOVE ' . $locURI . ' from client',
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$state->addConflictItem($type, $syncItem->getLocURI()); $state->addConflictItem($type, $syncItem->getLocURI());
} else { } else {
@ -411,7 +411,7 @@ class Horde_SyncML_Sync {
continue; continue;
} }
Horde::logMessage('SyncML: try to add contentype ' Horde::logMessage('SyncML: try to add contentype '
. $contentType . ' for locuri ' . $syncItem->getLocURI(), . $contentType . ' for locuri ' . $locURI,
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
//continue; //continue;
$oguid = $guid; $oguid = $guid;
@ -421,22 +421,22 @@ class Horde_SyncML_Sync {
if ($oguid != $guid) { if ($oguid != $guid) {
// We add a new entry // We add a new entry
$ts = $state->getSyncTSforAction($guid, 'add'); $ts = $state->getSyncTSforAction($guid, 'add');
Horde::logMessage('SyncML: added entry ' Horde::logMessage('SyncML: added entry ' . $locURI . ' guid '
. $guid . ' from client', . $guid . ' from client',
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->log('Client-Add'); $state->log('Client-Add');
} else { } else {
// We replaced an entry // We replaced an entry
$ts = $state->getSyncTSforAction($guid, 'modify'); $ts = $state->getSyncTSforAction($guid, 'modify');
Horde::logMessage('SyncML: replaced entry ' Horde::logMessage('SyncML: replaced entry ' . $locURI . ' guid '
. $guid . ' from client', . $guid . ' from client',
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->log('Client-Replace'); $state->log('Client-Replace');
} }
$state->setUID($type, $syncItem->getLocURI(), $guid, $ts); $state->setUID($type, $locURI, $guid, $ts);
} else { } else {
Horde::logMessage('SyncML: Error in replacing/' Horde::logMessage('SyncML: Error in replacing/'
. 'add client entry:' . $guid->message, . 'add client entry ' . $locURI . ' : ' . $guid->message,
__FILE__, __LINE__, PEAR_LOG_ERR); __FILE__, __LINE__, PEAR_LOG_ERR);
$state->log('Client-AddFailure'); $state->log('Client-AddFailure');
} }

View File

@ -227,8 +227,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
} }
$guid = false; $guid = false;
$locURI = $syncItem->getLocURI();
$oguid = $state->getGlobalUID($type, $syncItem->getLocURI()); $oguid = $state->getGlobalUID($type, $locURI);
$guid = $registry->call($hordeType . '/search', $guid = $registry->call($hordeType . '/search',
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $oguid, $type)); array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $oguid, $type));
@ -247,10 +248,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
} }
} else { } else {
# Entry exists in database already. Just update the mapping # Entry exists in database already. Just update the mapping
Horde::logMessage('SyncML: adding mapping for locuri:' Horde::logMessage("SyncML: adding mapping for locuri: $locURI and guid: $guid",
. $syncItem->getLocURI() . ' and guid:' . $guid,
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
$state->setUID($type, $syncItem->getLocURI(), $guid); $state->setUID($type, $locURI, $guid);
$state->log("Client-Map"); $state->log("Client-Map");
continue; continue;
} }
@ -259,9 +259,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
// We enforce the client not to change anything // We enforce the client not to change anything
if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) {
// delete this item from client // delete this item from client
Horde::logMessage('SyncML: Server RO! REMOVE ' . $syncItem->getLocURI() Horde::logMessage("SyncML: Server RO! REMOVE $locURI from client",
. ' from client', __FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
$state->addConflictItem($type, $syncItem->getLocURI()); $state->addConflictItem($type, $locURI);
} else { } else {
Horde::logMessage('SyncML: Server RO! REJECT all client changes', Horde::logMessage('SyncML: Server RO! REJECT all client changes',
__FILE__, __LINE__, PEAR_LOG_WARNING); __FILE__, __LINE__, PEAR_LOG_WARNING);
@ -272,18 +272,22 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync {
} }
// Add entry to the database. // Add entry to the database.
$state->removeUID($type, $syncItem->getLocURI()); $state->removeUID($type, $locURI);
Horde::logMessage('SyncML: try to add contentype ' . $contentType .' to '. $hordeType, Horde::logMessage("SyncML: try to add $locURI with contentype $contentType to $hordeType",
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
$guid = $registry->call($hordeType . '/import', $guid = $registry->call($hordeType . '/import',
array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType));
if (!is_a($guid, 'PEAR_Error') && $guid) { if (!is_a($guid, 'PEAR_Error') && $guid) {
$state->setUID($type, $syncItem->getLocURI(), $guid); // first we try the modification timestamp then the creation ts
if (!($ts = $state->getSyncTSforAction($guid, 'modify'))) {
$ts = $state->getSyncTSforAction($guid, 'add');
}
$state->setUID($type, $locURI, $guid, $ts);
$state->log("Client-AddReplace"); $state->log("Client-AddReplace");
Horde::logMessage('SyncML: replaced/added client entry as ' . $guid, Horde::logMessage("SyncML: replaced/added client entry $locURI as $guid",
__FILE__, __LINE__, PEAR_LOG_DEBUG); __FILE__, __LINE__, PEAR_LOG_DEBUG);
} else { } else {
Horde::logMessage('SyncML: Error in replacing/add client entry:' . $guid->message, Horde::logMessage('SyncML: Error in replacing/add client entry ' . $locURI . ': '. $guid->message,
__FILE__, __LINE__, PEAR_LOG_ERR); __FILE__, __LINE__, PEAR_LOG_ERR);
$state->log("Client-AddFailure"); $state->log("Client-AddFailure");
} }