From 729c7cb3628a14f007e3a85959198ca3d1d35ce0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Sat, 19 Jun 2010 15:30:28 +0000 Subject: [PATCH] Fix SlowSync timestamp issue (#2663) --- phpgwapi/inc/horde/Horde/SyncML/Sync.php | 62 +++++++++---------- .../inc/horde/Horde/SyncML/Sync/SlowSync.php | 28 +++++---- 2 files changed, 47 insertions(+), 43 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync.php index 128a08dc69..b826742bef 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync.php @@ -208,16 +208,16 @@ class Horde_SyncML_Sync { foreach($syncElementItems as $syncItem) { $guid = false; + $locURI = $syncItem->getLocURI(); if (is_a($command, 'Horde_SyncML_Command_Sync_Add')) { if ($sync_conflicts > CONFLICT_RESOLVED_WITH_DUPLICATE) { // We enforce the client not to change anything if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { // 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); - $state->addConflictItem($type, $syncItem->getLocURI()); + $state->addConflictItem($type, $locURI); } else { Horde::logMessage('SyncML: Server RO! ' . 'REJECT all client changes', @@ -232,22 +232,22 @@ class Horde_SyncML_Sync { if (!is_a($guid, 'PEAR_Error') && $guid != false) { $ts = $state->getSyncTSforAction($guid, 'add'); - $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); + $state->setUID($type, $locURI, $guid, $ts); $state->log('Client-Add'); - Horde::logMessage('SyncML: added client entry as ' - . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: added client entry $locURI as $guid", + __FILE__, __LINE__, PEAR_LOG_DEBUG); } else { $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); } } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Delete')) { - $guid = $state->removeUID($type, $syncItem->getLocURI()); + $guid = $state->removeUID($type, $locURI); if (!$guid) { // the entry is no longer on the server $state->log('Client-DeleteFailure'); - Horde::logMessage('SyncML: Failure deleting client entry, ' - . 'gone already on server!', + Horde::logMessage('SyncML: Failure deleting client entry ' . $locURI + . ', gone on server already!', __FILE__, __LINE__, PEAR_LOG_ERR); continue; } @@ -292,28 +292,28 @@ class Horde_SyncML_Sync { if (!is_a($guid, 'PEAR_Error') && $guid != false) { $registry->call($hordeType . '/delete', array($guid)); $ts = $state->getSyncTSforAction($guid, 'delete'); - $state->setUID($type, $syncItem->getLocURI(), $guid, $ts, 1); + $state->setUID($type, $locURI, $guid, $ts, 1); $state->log('Client-Delete'); Horde::logMessage('SyncML: deleted entry ' . $guid . ' due to client request', __FILE__, __LINE__, PEAR_LOG_DEBUG); } else { $state->log('Client-DeleteFailure'); - Horde::logMessage('SyncML: Failure deleting client entry, ' - . 'maybe gone already on server. msg: ' + Horde::logMessage('SyncML: Failure deleting client entry ' . $locURI + . ', maybe gone on server already: ' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); } } elseif (is_a($command, 'Horde_SyncML_Command_Sync_Replace')) { - $guid = $state->getGlobalUID($type, $syncItem->getLocURI()); + $guid = $state->getGlobalUID($type, $locURI); $replace = true; $ok = false; $merge = false; 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)) { - 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) { case CONFLICT_CLIENT_WINNING: @@ -321,7 +321,7 @@ class Horde_SyncML_Sync { break; case CONFLICT_SERVER_WINNING: Horde::logMessage('SyncML: REJECT client change for locuri ' . - $syncItem->getLocURI() . ' guid ' . $guid , + $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); $ok = true; $replace = false; @@ -329,7 +329,7 @@ class Horde_SyncML_Sync { break; case CONFLICT_MERGE_DATA: Horde::logMessage('SyncML: Merge server and client data for locuri ' . - $syncItem->getLocURI() . ' guid ' . $guid , + $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); $merge = true; break; @@ -338,17 +338,17 @@ class Horde_SyncML_Sync { break; case CONFLICT_CLIENT_CHANGES_IGNORED: Horde::logMessage('SyncML: Server RO! REJECT client change for locuri ' . - $syncItem->getLocURI() . ' guid ' . $guid , + $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); $ok = true; $replace = false; $ts = $state->getSyncTSforAction($guid, 'modify'); - $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); + $state->setUID($type, $locURI, $guid, $ts); $state->log('Client-AddReplaceIgnored'); break; default: // We enforce our data on client Horde::logMessage('SyncML: Server RO! UNDO client change for locuri ' . - $syncItem->getLocURI() . ' guid ' . $guid , + $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); $state->pushChangedItem($type, $guid); $ok = true; @@ -358,7 +358,7 @@ class Horde_SyncML_Sync { elseif ($sync_conflicts == CONFLICT_MERGE_DATA) { Horde::logMessage('SyncML: Merge server and client data for locuri ' . - $syncItem->getLocURI() . ' guid ' . $guid , + $locURI . ' guid ' . $guid , __FILE__, __LINE__, PEAR_LOG_WARNING); $merge = true; } @@ -372,15 +372,15 @@ class Horde_SyncML_Sync { if (!is_a($ok, 'PEAR_Error') && $ok != false) { $ts = $state->getSyncTSforAction($guid, 'modify'); - $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); + $state->setUID($type, $locURI, $guid, $ts); 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); } 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); } $state->log('Client-Replace'); @@ -401,7 +401,7 @@ class Horde_SyncML_Sync { // We enforce the client not to change anything if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { // 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); $state->addConflictItem($type, $syncItem->getLocURI()); } else { @@ -411,7 +411,7 @@ class Horde_SyncML_Sync { continue; } Horde::logMessage('SyncML: try to add contentype ' - . $contentType . ' for locuri ' . $syncItem->getLocURI(), + . $contentType . ' for locuri ' . $locURI, __FILE__, __LINE__, PEAR_LOG_DEBUG); //continue; $oguid = $guid; @@ -421,22 +421,22 @@ class Horde_SyncML_Sync { if ($oguid != $guid) { // We add a new entry $ts = $state->getSyncTSforAction($guid, 'add'); - Horde::logMessage('SyncML: added entry ' + Horde::logMessage('SyncML: added entry ' . $locURI . ' guid ' . $guid . ' from client', __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->log('Client-Add'); } else { // We replaced an entry $ts = $state->getSyncTSforAction($guid, 'modify'); - Horde::logMessage('SyncML: replaced entry ' + Horde::logMessage('SyncML: replaced entry ' . $locURI . ' guid ' . $guid . ' from client', __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->log('Client-Replace'); } - $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); + $state->setUID($type, $locURI, $guid, $ts); } else { Horde::logMessage('SyncML: Error in replacing/' - . 'add client entry:' . $guid->message, + . 'add client entry ' . $locURI . ' : ' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); $state->log('Client-AddFailure'); } diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php index 0a48dde77b..143aae2639 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php @@ -227,8 +227,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } $guid = false; + $locURI = $syncItem->getLocURI(); - $oguid = $state->getGlobalUID($type, $syncItem->getLocURI()); + $oguid = $state->getGlobalUID($type, $locURI); $guid = $registry->call($hordeType . '/search', array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType, $oguid, $type)); @@ -247,10 +248,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } } else { # Entry exists in database already. Just update the mapping - Horde::logMessage('SyncML: adding mapping for locuri:' - . $syncItem->getLocURI() . ' and guid:' . $guid, + Horde::logMessage("SyncML: adding mapping for locuri: $locURI and guid: $guid", __FILE__, __LINE__, PEAR_LOG_DEBUG); - $state->setUID($type, $syncItem->getLocURI(), $guid); + $state->setUID($type, $locURI, $guid); $state->log("Client-Map"); continue; } @@ -259,9 +259,9 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { // We enforce the client not to change anything if ($sync_conflicts > CONFLICT_CLIENT_CHANGES_IGNORED) { // delete this item from client - Horde::logMessage('SyncML: Server RO! REMOVE ' . $syncItem->getLocURI() - . ' from client', __FILE__, __LINE__, PEAR_LOG_WARNING); - $state->addConflictItem($type, $syncItem->getLocURI()); + Horde::logMessage("SyncML: Server RO! REMOVE $locURI from client", + __FILE__, __LINE__, PEAR_LOG_WARNING); + $state->addConflictItem($type, $locURI); } else { Horde::logMessage('SyncML: Server RO! REJECT all client changes', __FILE__, __LINE__, PEAR_LOG_WARNING); @@ -272,18 +272,22 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } // Add entry to the database. - $state->removeUID($type, $syncItem->getLocURI()); - Horde::logMessage('SyncML: try to add contentype ' . $contentType .' to '. $hordeType, + $state->removeUID($type, $locURI); + Horde::logMessage("SyncML: try to add $locURI with contentype $contentType to $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); $guid = $registry->call($hordeType . '/import', array($state->convertClient2Server($syncItem->getContent(), $contentType), $contentType)); 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"); - Horde::logMessage('SyncML: replaced/added client entry as ' . $guid, + Horde::logMessage("SyncML: replaced/added client entry $locURI as $guid", __FILE__, __LINE__, PEAR_LOG_DEBUG); } 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); $state->log("Client-AddFailure"); }