port some fixes from ZPush regarding synckeys and Nokia devices
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 3 Jun 2010 18:35:27 +0000 (14:35 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 3 Jun 2010 18:35:27 +0000 (14:35 -0400)
Haven't seen this personally, but it's said to affect MfE 3.
see https://developer.berlios.de/mantis/view.php?id=138

framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php

index 649d9f1..34b6ea5 100644 (file)
@@ -82,6 +82,9 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
         $seenfolders = $this->_state->getKnownFolders();
         $this->_logger->debug('[Horde_ActiveSync::handleFolderSync] newSyncKey: ' . $newsynckey);
 
+        /* Track if we have changes or not */
+        $changes = false;
+
         /* Deal with folder hierarchy changes */
         if ($this->_decoder->getElementStartTag(Horde_ActiveSync::FOLDERHIERARCHY_CHANGES)) {
             // Ignore <Count> if present
@@ -116,9 +119,11 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
                 case SYNC_ADD:
                 case SYNC_MODIFY:
                     $serverid = $importer->importFolderChange($folder);
+                $changes = true;
                     break;
                 case SYNC_REMOVE:
                     $serverid = $importer->importFolderDeletion($folder);
+                    $changes = true;
                     break;
                 }
 
@@ -164,7 +169,7 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
         $this->_encoder->endTag();
 
         $this->_encoder->startTag(Horde_ActiveSync::FOLDERHIERARCHY_SYNCKEY);
-        $this->_encoder->content($newsynckey);
+        $this->_encoder->content((($changes || $exporter->count > 0) ? $newsynckey : $synckey));
         $this->_encoder->endTag();
 
         $this->_encoder->startTag(Horde_ActiveSync::FOLDERHIERARCHY_CHANGES);
index 9323a1e..2f842c7 100644 (file)
@@ -377,10 +377,19 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
         $this->_encoder->startTag(Horde_ActiveSync::SYNC_SYNCHRONIZE);
         $this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDERS);
         foreach ($collections as $collection) {
+            /* Get new synckey if needed */
+            $changecount = 0;
+            if (isset($collection['getchanges'])) {
+                $filtertype = isset($collection['filtertype']) ? $collection['filtertype'] : false;
+                $exporter = new Horde_ActiveSync_Connector_Exporter($this->_encoder, $collection['class']);
+                $sync = $this->_driver->getSyncObject();
+                $sync->init($this->_state, $exporter, $collection);
+                $changecount = $sync->getChangeCount();
+            }
 
             /* Get new synckey if needed */
             if (isset($collection['importedchanges']) ||
-                isset($collection['getchanges']) ||
+                $changecount > 0 ||
                 $collection['synckey'] == '0') {
                 try {
                     $collection['newsynckey'] = $this->_state->getNewSyncKey($collection['synckey']);
@@ -454,11 +463,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
 
             /* Send server changes to PIM */
             if (isset($collection['getchanges'])) {
-                $filtertype = isset($collection['filtertype']) ? $collection['filtertype'] : false;
-                $exporter = new Horde_ActiveSync_Connector_Exporter($this->_encoder, $collection['class']);
-                $sync = $this->_driver->getSyncObject();
-                $sync->init($this->_state, $exporter, $collection);
-                $changecount = $sync->getChangeCount();
+                /* Changecount and exporter initialized above */
                 if (!empty($collection['windowsize']) && $changecount > $collection['windowsize']) {
                     $this->_encoder->startTag(Horde_ActiveSync::SYNC_MOREAVAILABLE, false, true);
                 }