From 14770c3689953aaccec4cb44bcd86e1d9883d8cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Lehrke?= Date: Tue, 17 Nov 2009 21:20:32 +0000 Subject: [PATCH] Fix for 'Enforce Server' during SlowSync --- .../inc/horde/Horde/SyncML/Sync/SlowSync.php | 46 ++++++++++++++++--- .../horde/Horde/SyncML/Sync/TwoWaySync.php | 18 ++++---- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php index f07d7de703..3866f50937 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/SlowSync.php @@ -59,14 +59,14 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->incNumberOfElements(); } - $adds = &$state->getAddedItems($syncType); - Horde::logMessage("SyncML: ".count($adds). ' added items found for '.$syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); - - if(is_array($adds)) { - while($guid = array_shift($adds)) { + $adds =& $state->getAddedItems($syncType); + $conflicts =& $state->getConflictItems($syncType); + Horde::logMessage('SyncML: ' .count($adds). ' added items found for ' .$syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: ' . count($conflicts) . ' items to delete on client found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + if (is_array($adds)) { + while ($guid = array_shift($adds)) { $currentSize = $output->getOutputSize(); - // return if we have to much data if (($maxEntries && ($state->getNumberOfElements() >= $maxEntries) && isset($contentType['mayFragment']) @@ -134,7 +134,39 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->incNumberOfElements(); } } + // handle remote deletes due to conflicts + if (count($conflicts) > 0) { + while ($locid = array_shift($conflicts)) { + $currentSize = $output->getOutputSize(); + // return if we have to much data + if (($maxEntries && ($state->getNumberOfElements() >= $maxEntries) + && isset ($contentType['mayFragment']) + && $contentType['mayFragment']) + || ($maxMsgSize + && (($currentSize +MIN_MSG_LEFT * 2) > $maxMsgSize))) { + // put the item back in the queue + $conflicts[] = $locid; + $state->maxNumberOfElements(); + $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); + return $currentCmdID; + } + 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); + $currentCmdID = $cmd->outputCommand($currentCmdID, $output, 'Delete'); + $state->log('Server-DeletedConflicts'); + $state->removeUID($syncType, $locid); + // moreData split; save in session state and end current message + if ($cmd->hasMoreData()) { + $state->curSyncItem = & $cmd; + $state->setSyncStatus(SERVER_SYNC_DATA_PENDING); + return $currentCmdID; + } + $state->incNumberOfElements(); + } + } Horde::logMessage("SyncML: All items handled for sync $syncType", __FILE__, __LINE__, PEAR_LOG_DEBUG); $state->removeExpiredUID($syncType, $serverAnchorNext); @@ -277,6 +309,6 @@ class Horde_SyncML_Sync_SlowSync extends Horde_SyncML_Sync_TwoWaySync { $state->mergeAddedItems($syncType, $registry->call($hordeType. '/list', array('filter' => $this->_filterExpression))); $this->_syncDataLoaded = TRUE; - return count($state->getAddedItems($syncType)) - $delta_add; + 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 f2d5e29ee3..536c14b0f4 100644 --- a/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php +++ b/phpgwapi/inc/horde/Horde/SyncML/Sync/TwoWaySync.php @@ -77,15 +77,15 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $state->incNumberOfElements(); } - $changes = & $state->getChangedItems($syncType); - $deletes = & $state->getDeletedItems($syncType); - $adds = & $state->getAddedItems($syncType); - $conflicts = & $state->getConflictItems($syncType); + $changes =& $state->getChangedItems($syncType); + $deletes =& $state->getDeletedItems($syncType); + $adds =& $state->getAddedItems($syncType); + $conflicts =& $state->getConflictItems($syncType); - Horde :: logMessage('SyncML: ' . count($changes) . ' changed items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); - Horde :: logMessage('SyncML: ' . count($deletes) . ' deleted items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); - Horde :: logMessage('SyncML: ' . count($conflicts) . ' items to delete on client found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); - Horde :: logMessage('SyncML: ' . count($adds) . ' added items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: ' . count($changes) . ' changed items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: ' . count($deletes) . ' deleted items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: ' . count($conflicts) . ' items to delete on client found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); + Horde::logMessage('SyncML: ' . count($adds) . ' added items found for ' . $syncType, __FILE__, __LINE__, PEAR_LOG_DEBUG); // handle changes if (is_array($changes)) { @@ -441,6 +441,6 @@ class Horde_SyncML_Sync_TwoWaySync extends Horde_SyncML_Sync { $this->_syncDataLoaded = TRUE; - return count($state->getChangedItems($syncType)) - $delta_mod + count($state->getDeletedItems($syncType)) + count($state->getAddedItems($syncType)) - $delta_add +count($state->getConflictItems($syncType)); + return count($state->getChangedItems($syncType)) - $delta_mod + count($state->getDeletedItems($syncType)) + count($state->getAddedItems($syncType)) - $delta_add + count($state->getConflictItems($syncType)); } } \ No newline at end of file