Have the state object be responsible for stating the message if needed.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 22 Apr 2010 14:23:15 +0000 (10:23 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 24 Apr 2010 16:22:41 +0000 (12:22 -0400)
This allows different state drivers to omit the stat if it's not necessary for
determining changes.

framework/ActiveSync/lib/Horde/ActiveSync/State/File.php
framework/ActiveSync/lib/Horde/ActiveSync/Sync.php

index 384c638..2d7f923 100644 (file)
@@ -197,6 +197,14 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
 
         // Change can be a change or an add
         if ($type == 'change') {
+            /* If we are a change and don't already have a mod time, stat the
+             * message. This would only happen when exporting a server side 
+             * change. We need the mod time to track the version of the message
+             * on the PIM.
+             */
+            if (!isset($change['mod'])) {
+                $change = $this->_backend->statMessage($this->_collection['id'], $change['id']);
+            }
             for($i = 0; $i < count($this->_stateCache); $i++) {
                 if($this->_stateCache[$i]['id'] == $change['id']) {
                     $this->_stateCache[$i] = $change;
index 7cc098d..ac5900d 100644 (file)
@@ -178,21 +178,14 @@ class Horde_ActiveSync_Sync
                 switch($change['type']) {
                 case 'change':
                     $truncsize = self::_getTruncSize($this->_truncation);
-                    // Note: because 'parseMessage' and 'statMessage' are two seperate
-                    // calls, we have a chance that the message has changed between both
-                    // calls. This may cause our algorithm to 'double see' changes.
-                    $stat = $this->_backend->statMessage($this->_folderId, $change['id']);
                     if (!$message = $this->_backend->getMessage($this->_folderId, $change['id'], $truncsize)) {
                         return false;
                     }
 
                     // copy the flag to the message
                     $message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
-
-                    if ($stat && $message) {
-                        if ($flags & Horde_ActiveSync::BACKEND_DISCARD_DATA || $this->_exporter->messageChange($change['id'], $message) == true) {
-                            $this->_stateMachine->updateState('change', $stat);
-                        }
+                    if ($flags & Horde_ActiveSync::BACKEND_DISCARD_DATA || $this->_exporter->messageChange($change['id'], $message) == true) {
+                        $this->_stateMachine->updateState('change', $change);
                     }
                     break;