From d8ee864991de4ab05d9513a1ae82f335990a3293 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Fri, 20 Nov 2009 07:24:00 +0000 Subject: [PATCH] SyncML filter handling improved, code cleanup --- .../SyncML/Sync/RefreshFromServerSync.php | 26 ++++--- .../inc/horde/Horde/SyncML/Sync/SlowSync.php | 36 +++++++--- .../horde/Horde/SyncML/Sync/TwoWaySync.php | 67 ++++++++++++------- 3 files changed, 85 insertions(+), 44 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php index 3e37a43345..1eb07c795b 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/RefreshFromServerSync.php @@ -73,7 +73,8 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy } if ($locID = $state->getLocID($syncType, $guid)) { - Horde::logMessage("SyncML: RefreshFromServerSync add to client: $guid ignored, already at client($locID)", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: RefreshFromServerSync add to client: $guid ignored, already at client($locID)", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } @@ -81,14 +82,16 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy if ($guid_ts > $serverAnchorNext) { // Change was made after we started this sync. // Don't sent this now to the client. - Horde::logMessage("SyncML: RefreshFromServerSync add $guid is in our future", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: RefreshFromServerSync add $guid is in our future", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } $contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI, $this->_targetLocURI); $c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType)); if (is_a($c, 'PEAR_Error')) { - Horde::logMessage("SyncML: refresh failed to export guid $guid:\n" . print_r($c, true), __FILE__, __LINE__, PEAR_LOG_WARNING); + Horde::logMessage("SyncML: refresh failed to export guid $guid:\n" . print_r($c, true), + __FILE__, __LINE__, PEAR_LOG_WARNING); $state->log("Server-ExportFailed"); continue; } @@ -97,7 +100,8 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy // return if we have to much data if ($maxMsgSize && !$deviceInfo['supportLargeObjs']) { if (($size + MIN_MSG_LEFT * 2) > $maxMsgSize) { - Horde::logMessage("SyncML: refresh failed to export guid $guid due to size $size", __FILE__, __LINE__, PEAR_LOG_ERROR); + Horde::logMessage("SyncML: refresh failed to export guid $guid due to size $size", + __FILE__, __LINE__, PEAR_LOG_ERROR); $state->log("Server-ExportFailed"); continue; } @@ -109,7 +113,8 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy } } - Horde::logMessage("SyncML: refresh add $guid to client\n$c", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: refresh add $guid to client\n$c", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $cmd = new Horde_SyncML_Command_Sync_ContentSyncElement(); $cmd->setContent($c); @@ -134,7 +139,8 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy } } - Horde::logMessage("SyncML: All items handled for sync $syncType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: All items handled for sync $syncType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->removeExpiredUID($syncType, $serverAnchorNext); $state->clearSync($syncType); @@ -152,14 +158,18 @@ class Horde_SyncML_Sync_RefreshFromServerSync extends Horde_SyncML_Sync_TwoWaySy $future = $state->getServerAnchorNext($syncType); $delta_add = 0; - Horde::logMessage("SyncML: reading added items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: reading added items from database for $hordeType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); + /* The items, which now match the filter criteria are show here, too $state->setAddedItems($syncType, $registry->call($hordeType. '/listBy', array('action' => 'add', 'timestamp' => $future, 'type' => $syncType, 'filter' => $this->_filterExpression))); $delta_add = count($state->getAddedItems($hordeType)); - $state->setAddedItems($syncType, $registry->call($hordeType. '/list', array('filter' => $this->_filterExpression))); + */ + $state->mergeAddedItems($syncType, $registry->call($hordeType. '/list',array('filter' => $this->_filterExpression))); + $this->_syncDataLoaded = TRUE; return count($state->getAddedItems($syncType)) - $delta_add; diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php index 3866f50937..d91c05274b 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php @@ -80,7 +80,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } if ($locID = $state->getLocID($syncType, $guid)) { - Horde::logMessage("SyncML: slowsync add to client: $guid ignored, already at client($locID)", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: slowsync add to client: $guid ignored, already at client($locID)", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } @@ -88,14 +89,16 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { if ($guid_ts > $serverAnchorNext) { // Change was made after we started this sync. // Don't sent this now to the client. - Horde::logMessage("SyncML: slowsync add $guid is in our future", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: slowsync add $guid is in our future", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } $contentType = $state->getPreferedContentTypeClient($this->_sourceLocURI, $this->_targetLocURI); $c = $registry->call($hordeType . '/export', array('guid' => $guid, 'contentType' => $contentType)); if (is_a($c, 'PEAR_Error')) { - Horde::logMessage("SyncML: slowsync failed to export guid $guid:\n" . print_r($c, true), __FILE__, __LINE__, PEAR_LOG_WARNING); + Horde::logMessage("SyncML: slowsync failed to export guid $guid:\n" . print_r($c, true), + __FILE__, __LINE__, PEAR_LOG_WARNING); continue; } @@ -103,7 +106,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { // return if we have to much data if ($maxMsgSize && !$deviceInfo['supportLargeObjs']) { if (($size + MIN_MSG_LEFT * 2) > $maxMsgSize) { - Horde::logMessage("SyncML: slowsync failed to export guid $guid due to size $size", __FILE__, __LINE__, PEAR_LOG_ERROR); + Horde::logMessage("SyncML: slowsync failed to export guid $guid due to size $size", + __FILE__, __LINE__, PEAR_LOG_ERROR); continue; } if (($currentSize + $size + MIN_MSG_LEFT * 2) > $maxMsgSize) { @@ -114,7 +118,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } } - Horde::logMessage("SyncML: slowsync add guid $guid to client\n$c", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: slowsync add guid $guid to client\n$c", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $cmd = new Horde_SyncML_Command_Sync_ContentSyncElement(); $cmd->setContent($c); $cmd->setContentType($contentType['ContentType']); @@ -150,7 +155,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); return $currentCmdID; } - Horde :: logMessage("SyncML: delete client locid: $locid", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: delete client locid: $locid", + __FILE__, __LINE__, PEAR_LOG_DEBUG); // Create a Delete request for client. $cmd = new Horde_SyncML_Command_Sync_ContentSyncElement(); $cmd->setLocURI($locid); @@ -167,7 +173,8 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->incNumberOfElements(); } } - Horde::logMessage("SyncML: All items handled for sync $syncType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: All items handled for sync $syncType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->removeExpiredUID($syncType, $serverAnchorNext); $state->clearSync($syncType); @@ -270,7 +277,8 @@ 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, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: try to add 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 != false) { @@ -280,9 +288,11 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { } $state->setUID($type, $syncItem->getLocURI(), $guid, $ts); $state->log("Client-AddReplace"); - Horde::logMessage('SyncML: r/ added client entry as ' . $guid, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: r/ added client entry as ' . $guid, + __FILE__, __LINE__, PEAR_LOG_DEBUG); } else { - Horde::logMessage('SyncML: Error in replacing/add client entry:' . $guid->message, __FILE__, __LINE__, PEAR_LOG_ERR); + Horde::logMessage('SyncML: Error in replacing/add client entry:' . $guid->message, + __FILE__, __LINE__, PEAR_LOG_ERR); $state->log("Client-AddFailure"); } } @@ -300,13 +310,17 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $future = $state->getServerAnchorNext($syncType); $delta_add = 0; - Horde::logMessage("SyncML: reading added items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: reading added items from database for $hordeType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); + /* The items, which now match the filter criteria are show here, too $delta_add = count($registry->call($hordeType. '/listBy', array('action' => 'add', 'timestamp' => $future, 'type' => $syncType, 'filter' => $this->_filterExpression))); + */ $state->mergeAddedItems($syncType, $registry->call($hordeType. '/list', array('filter' => $this->_filterExpression))); + $this->_syncDataLoaded = TRUE; return count($state->getAddedItems($syncType)) - $delta_add + count($state->getConflictItems($syncType)); diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php index 536c14b0f4..9c0352422d 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php @@ -40,9 +40,6 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { // array of Items which got modified, but got never send to the client before $missedAdds = array (); - // array of Items which the client wanted to add, but must be deleted due to - // user's sync policy - $remoteDeletes = array (); $history = $GLOBALS['egw']->contenthistory; $state = & $_SESSION['SyncML.state']; @@ -107,24 +104,28 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $guid_ts = $state->getSyncTSforAction($guid, 'modify'); $sync_ts = $state->getChangeTS($syncType, $guid); - Horde :: logMessage("SyncML: timestamp modify $guid guid_ts: $guid_ts sync_ts: $sync_ts", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: timestamp modify $guid guid_ts: $guid_ts sync_ts: $sync_ts", + __FILE__, __LINE__, PEAR_LOG_DEBUG); if ($sync_ts && $sync_ts == $guid_ts) { // Change was done by us upon request of client. // Don't mirror that back to the client. - Horde :: logMessage("SyncML: change: $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: change: $guid ignored, came from client", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } if ($guid_ts > $serverAnchorNext) { // Change was made after we started this sync. // Don't sent this now to the client. - Horde :: logMessage("SyncML: change $guid is in our future: $serverAnchorNext", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: change $guid is in our future: $serverAnchorNext", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } $locid = $state->getLocID($syncType, $guid); if (!$locid) { // somehow we missed to add, lets store the uid, so we add this entry later $missedAdds[] = $guid; - Horde :: logMessage("SyncML: unable to create change for $guid: locid not found in map", __FILE__, __LINE__, PEAR_LOG_WARNING); + Horde :: logMessage("SyncML: unable to create change for $guid: locid not found in map", + __FILE__, __LINE__, PEAR_LOG_WARNING); continue; } @@ -136,19 +137,21 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { )); if (is_a($c, 'PEAR_Error')) { // Item in history but not in database. Strange, but can happen. - Horde :: logMessage("SyncML: change: export of guid $guid failed:\n" . print_r($c, true), __FILE__, __LINE__, PEAR_LOG_WARNING); + Horde :: logMessage("SyncML: change: export of guid $guid failed:\n" . print_r($c, true), + __FILE__, __LINE__, PEAR_LOG_WARNING); continue; } $size = strlen($c); // return if we have to much data if ($maxMsgSize && !$deviceInfo['supportLargeObjs']) { - if (($size +MIN_MSG_LEFT * 2) > $maxMsgSize) { - Horde :: logMessage("SyncML: change: export of guid $guid failed due to size $size", __FILE__, __LINE__, PEAR_LOG_ERROR); + if (($size + MIN_MSG_LEFT * 2) > $maxMsgSize) { + Horde :: logMessage("SyncML: change: export of guid $guid failed due to size $size", + __FILE__, __LINE__, PEAR_LOG_ERROR); $state->log('Server-ExportFailed'); continue; } - if (($currentSize + $size +MIN_MSG_LEFT * 2) > $maxMsgSize) { + if (($currentSize + $size + MIN_MSG_LEFT * 2) > $maxMsgSize) { // put the item back in the queue $changes[] = $guid; $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); @@ -156,7 +159,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { } } - Horde :: logMessage("SyncML: change: export guid $guid, content:\n$c", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: change: export guid $guid, content:\n$c", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $cmd = new Horde_SyncML_Command_Sync_ContentSyncElement(); # LK $cmd->setContent($state->convertServer2Client($c, $contentType)); $cmd->setContent($c); @@ -177,7 +181,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $state->incNumberOfElements(); } } - Horde :: logMessage("SyncML: handling sync (changes done) " . $currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: handling sync (changes done) " . $currentCmdID, + __FILE__, __LINE__, PEAR_LOG_DEBUG); // handle deletes if (is_array($deletes)) { @@ -188,7 +193,7 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { && isset ($contentType['mayFragment']) && $contentType['mayFragment']) || ($maxMsgSize - && (($currentSize +MIN_MSG_LEFT * 2) > $maxMsgSize))) { + && (($currentSize + MIN_MSG_LEFT * 2) > $maxMsgSize))) { // put the item back in the queue $deletes[] = $guid; $state->maxNumberOfElements(); @@ -276,13 +281,15 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $state->incNumberOfElements(); } } - #Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); + // Horde::logMessage("SyncML: handling sync ".$currentCmdID, __FILE__, __LINE__, PEAR_LOG_DEBUG); // handle missing adds. if (count($missedAdds) > 0) { - Horde :: logMessage("SyncML: add missed changes as adds " . count($adds) . ' / ' . $missedAdds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: add missed changes as adds " . count($adds) . ' / ' . $missedAdds[0], + __FILE__, __LINE__, PEAR_LOG_DEBUG); $adds = array_merge($adds, $missedAdds); - Horde :: logMessage("SyncML: merged adds counter " . count($adds) . ' / ' . $adds[0], __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: merged adds counter " . count($adds) . ' / ' . $adds[0], + __FILE__, __LINE__, PEAR_LOG_DEBUG); } if (is_array($adds)) { @@ -311,13 +318,15 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { if ($sync_ts && $sync_ts == $guid_ts) { // Change was done by us upon request of client. // Don't mirror that back to the client. - Horde :: logMessage("SyncML: add: $guid ignored, came from client", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: add: $guid ignored, came from client", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } if ($guid_ts > $serverAnchorNext && !in_array($guid, $conflicts)) { // Change was made after we started this sync. // Don't sent this now to the client. - Horde :: logMessage("SyncML: add $guid is in our future: $serverAnchorNext", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: add $guid is in our future: $serverAnchorNext", + __FILE__, __LINE__, PEAR_LOG_DEBUG); continue; } @@ -343,7 +352,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { if (is_a($c, 'PEAR_Error')) { // Item in history but not in database. Strange, but can happen. - Horde :: logMessage("SyncML: add: export of guid $guid failed:\n" . print_r($c, true), __FILE__, __LINE__, PEAR_LOG_WARNING); + Horde :: logMessage("SyncML: add: export of guid $guid failed:\n" . print_r($c, true), + __FILE__, __LINE__, PEAR_LOG_WARNING); continue; } @@ -363,7 +373,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { } } - Horde :: logMessage("SyncML: add guid $guid to client\n$c", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: add guid $guid to client\n$c", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $cmd = new Horde_SyncML_Command_Sync_ContentSyncElement(); $cmd->setContent($c); $cmd->setContentType($contentType['ContentType']); @@ -383,7 +394,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $state->incNumberOfElements(); } } - Horde::logMessage("SyncML: All items handled for sync $syncType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage("SyncML: All items handled for sync $syncType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->removeExpiredUID($syncType, time()); $state->clearSync($syncType); @@ -403,7 +415,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $delta_mod = 0; $delta_add = 0; - Horde :: logMessage("SyncML: reading changed items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: reading changed items from database for $hordeType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $delta_mod = count($registry->call($hordeType . '/listBy', array ( 'action' => 'modify', 'timestamp' => $future, @@ -417,7 +430,8 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { 'filter' => $this->_filterExpression ))); - Horde :: logMessage("SyncML: reading deleted items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: reading deleted items from database for $hordeType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->setDeletedItems($syncType, $registry->call($hordeType . '/listBy', array ( 'action' => 'delete', 'timestamp' => $refts, @@ -425,13 +439,16 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { 'filter' => $this->_filterExpression ))); - Horde :: logMessage("SyncML: reading added items from database for $hordeType", __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde :: logMessage("SyncML: reading added items from database for $hordeType", + __FILE__, __LINE__, PEAR_LOG_DEBUG); + /* The items, which now match the filter criteria are show here, too $delta_add = count($registry->call($hordeType . '/listBy', array ( 'action' => 'add', 'timestamp' => $future, 'type' => $syncType, 'filter' => $this->_filterExpression ))); + */ $state->mergeAddedItems($syncType, $registry->call($hordeType . '/listBy', array ( 'action' => 'add', 'timestamp' => $refts,