Refactor the Exporter/Streamer/Importer/HierarchyCache mess....
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 31 Mar 2010 21:43:53 +0000 (17:43 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 31 Mar 2010 21:43:53 +0000 (17:43 -0400)
Rename a bunch of classes and combine a few to better reflect what is happening here.
As a bonus, cleans up the main directory of the package a bit.

15 files changed:
framework/ActiveSync/lib/Horde/ActiveSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php [new file with mode: 0644]
framework/ActiveSync/lib/Horde/ActiveSync/Connector/Importer.php [new file with mode: 0644]
framework/ActiveSync/lib/Horde/ActiveSync/Connector/NullImporter.php [new file with mode: 0644]
framework/ActiveSync/lib/Horde/ActiveSync/ContentsCache.php [deleted file]
framework/ActiveSync/lib/Horde/ActiveSync/Driver/Base.php
framework/ActiveSync/lib/Horde/ActiveSync/HierarchyCache.php [deleted file]
framework/ActiveSync/lib/Horde/ActiveSync/Importer.php [deleted file]
framework/ActiveSync/lib/Horde/ActiveSync/Request/FolderSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php
framework/ActiveSync/lib/Horde/ActiveSync/Streamer.php [deleted file]
framework/ActiveSync/lib/Horde/ActiveSync/Sync.php
framework/ActiveSync/package.xml
framework/ActiveSync/test/Horde/ActiveSync/HordeDriverTest.php

index 3a919b9..dd65991 100644 (file)
@@ -1549,6 +1549,7 @@ class Horde_ActiveSync
             $device->userAgent = $this->_request->getHeader('User-Agent');
             $device->deviceType = !empty($get['DeviceType']) ? $get['DeviceType'] : '';
             $device->policykey = 0;
+            $device->rwstatus = 0;
             $state->setDeviceInfo($devId, $device);
         }
 
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php b/framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter.php
new file mode 100644 (file)
index 0000000..89e77ca
--- /dev/null
@@ -0,0 +1,154 @@
+<?php
+/**
+ * File      :   streamimporter.php
+ * Project   :   Z-Push
+ * Descr     :   Stream import classes
+ *
+ * Created   :   01.10.2007
+ *
+ * � Zarafa Deutschland GmbH, www.zarafaserver.de
+ * This file is distributed under GPL v2.
+ * Consult LICENSE file for details
+ */
+
+/**
+ *
+ *
+ */
+class Horde_ActiveSync_Connector_Exporter
+{
+    protected $_encoder;
+    protected $_type;
+    protected $_seenObjects;
+    
+    public $changed = array();
+    public $deleted = array();
+    public $count = 0;
+
+    /**
+     * Const'r
+     *
+     * @param Horde_ActiveSync_Wbxml_Encoder $encoder
+     * @param string $class  The collection class
+     *
+     * @return Horde_ActiveSync_Connector_Exporter
+     */
+    public function __construct($encoder = null, $class = null)
+    {
+        $this->_encoder = $encoder;
+        $this->_type = $class;
+        $this->_seenObjects = array();
+    }
+
+    /**
+     *
+     * @param $id
+     * @param $message
+     * @return unknown_type
+     */
+    public function messageChange($id, $message)
+    {
+        if ($message->getClass() != $this->_type) {
+            return true; // ignore other types
+        }
+
+        // prevent sending the same object twice in one request
+        if (in_array($id, $this->_seenObjects)) {
+               return true;
+        }
+
+        $this->_seenObjects[] = $id;
+        if ($message->flags === false || $message->flags === SYNC_NEWMESSAGE) {
+            $this->_encoder->startTag(SYNC_ADD);
+        } else {
+            $this->_encoder->startTag(SYNC_MODIFY);
+        }
+
+        $this->_encoder->startTag(SYNC_SERVERENTRYID);
+        $this->_encoder->content($id);
+        $this->_encoder->endTag();
+        $this->_encoder->startTag(SYNC_DATA);
+        $message->encodeStream($this->_encoder);
+        $this->_encoder->endTag();
+        $this->_encoder->endTag();
+
+        return true;
+    }
+
+    /**
+     *
+     * @param $id
+     * @return unknown_type
+     */
+    public function messageDeletion($id)
+    {
+        $this->_encoder->startTag(SYNC_REMOVE);
+        $this->_encoder->startTag(SYNC_SERVERENTRYID);
+        $this->_encoder->content($id);
+        $this->_encoder->endTag();
+        $this->_encoder->endTag();
+
+        return true;
+    }
+
+    /**
+     *
+     * @param $id
+     * @param $flags
+     * @return unknown_type
+     */
+    public function messageReadFlag($id, $flags)
+    {
+        if ($this->_type != "syncmail") {
+            return true;
+        }
+        $this->_encoder->startTag(SYNC_MODIFY);
+        $this->_encoder->startTag(SYNC_SERVERENTRYID);
+        $this->_encoder->content($id);
+        $this->_encoder->endTag();
+        $this->_encoder->startTag(SYNC_DATA);
+        $this->_encoder->startTag(SYNC_POOMMAIL_READ);
+        $this->_encoder->content($flags);
+        $this->_encoder->endTag();
+        $this->_encoder->endTag();
+        $this->_encoder->endTag();
+
+        return true;
+    }
+
+    /**
+     *
+     * @param $message
+     * @return unknown_type
+     */
+    function messageMove($message)
+    {
+        return true;
+    }
+
+    /**
+     *
+     * @param <type> $folder
+     * @return <type>
+     */
+    public function FolderChange($folder)
+    {
+        array_push($this->changed, $folder);
+        $this->count++;
+
+        return true;
+    }
+
+    /**
+     *
+     * @param <type> $id
+     * @return <type> 
+     */
+    public function FolderDeletion($id)
+    {
+        array_push($this->deleted, $id);
+        $this->count++;
+
+        return true;
+    }
+}
\ No newline at end of file
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Connector/Importer.php b/framework/ActiveSync/lib/Horde/ActiveSync/Connector/Importer.php
new file mode 100644 (file)
index 0000000..15212e9
--- /dev/null
@@ -0,0 +1,262 @@
+<?php
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+class Horde_ActiveSync_Connector_Importer
+{
+    /**
+     *
+     * @var Horde_ActiveSync_StateMachine_Base
+     */
+    protected $_stateMachine;
+
+    /**
+     *
+     * @var Horde_ActiveSync_Driver_Base
+     */
+    protected $_backend;
+
+    /**
+     * Sync key for current request
+     *
+     * @var string
+     */
+    protected $_syncKey;
+
+    /**
+     * @TODO
+     * @var <type>
+     */
+    protected $_flags;
+
+    /**
+     * The server specific folder id
+     *
+     * @var string
+     */
+    protected $_folderId;
+
+    protected $_logger;
+
+    /**
+     * Const'r
+     *
+     * @param Horde_ActiveSync_Driver_Base $backend
+     * @param Horde_ActiveSync_StateMachine_Base $stateMachine
+     * @param <type> $syncKey
+     * @param <type> $flags
+     */
+    public function __construct(Horde_ActiveSync_Driver_Base $backend)
+    {
+        $this->_backend = $backend;
+    }
+
+    public function init(Horde_ActiveSync_State_Base &$stateMachine,
+                         $folderId, $syncKey, $flags = 0)
+    {
+        $this->_stateMachine = &$stateMachine;
+        $this->_syncKey = $syncKey;
+        $this->_flags = $flags;
+        $this->_folderId = $folderId;
+    }
+
+    public function setLogger($logger)
+    {
+        $this->_logger = $logger;
+    }
+
+    /**
+     *
+     * @param mixed $id                                A server message id or
+     *                                                 false if a new message
+     * @param Horde_ActiveSync_Message_Base $message   A message object
+     *
+     * @return mixed The server message id or false
+     */
+    public function ImportMessageChange($id, $message)
+    {
+        //do nothing if it is in a dummy folder
+        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
+            return false;
+        }
+
+        if ($id) {
+            // See if there's a conflict
+            $conflict = $this->_isConflict('change', $this->_folderId, $id);
+
+            // Update client state if this is an update
+            $change = array();
+            $change['id'] = $id;
+            $change['mod'] = 0; // dummy, will be updated later if the change succeeds
+            $change['parent'] = $this->_folderId;
+            $change['flags'] = (isset($message->read)) ? $message->read : 0;
+            $this->_stateMachine->updateState('change', $change);
+
+            if ($conflict && $this->_flags == SYNC_CONFLICT_OVERWRITE_PIM) {
+                return true;
+            }
+        }
+
+        $stat = $this->_backend->ChangeMessage($this->_folderId, $id, $message);
+        // @TODO: Isn't this an error?
+        if (!is_array($stat)) {
+            return $stat;
+        }
+
+        // Record the state of the message
+        $this->_stateMachine->updateState('change', $stat);
+
+        return $stat['id'];
+    }
+
+    /**
+     * Import a deletion. This may conflict if the local object has been
+     * modified.
+     *
+     * @param string $id  Server message id
+     */
+    public function ImportMessageDeletion($id)
+    {
+        //do nothing if it is in a dummy folder
+        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
+            return true;
+        }
+
+        // See if there's a conflict
+        $conflict = $this->_isConflict('delete', $this->_folderId, $id);
+
+        // Update client state
+        $change = array();
+        $change['id'] = $id;
+        $this->_stateMachine->updateState('delete', $change);
+
+        // If there is a conflict, and the server 'wins', then return OK without
+        // performing the change this will cause the exporter to 'see' the
+        // overriding item as a change, and send it back to the PIM
+        if ($conflict && $this->_flags == SYNC_CONFLICT_OVERWRITE_PIM) {
+            return true;
+        }
+
+        $this->_backend->DeleteMessage($this->_folderId, $id);
+
+        return true;
+    }
+
+    /**
+     * Import a change in 'read' flags .. This can never conflict
+     *
+     * @param string $id  Server message id
+     * @param ??  $flags  The read flags to set
+     */
+    public function ImportMessageReadFlag($id, $flags)
+    {
+        //do nothing if it is a dummy folder
+        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
+            return true;
+        }
+
+        // Update client state
+        $change = array();
+        $change['id'] = $id;
+        $change['flags'] = $flags;
+        $this->_stateMachine->updateState('flags', $change);
+        $this->_backend->SetReadFlag($this->_folderId, $id, $flags);
+
+        return true;
+    }
+
+    /**
+     * Not supported/todo?
+     *
+     * @param <type> $id
+     * @param <type> $newfolder
+     * @return <type>
+     */
+    public function ImportMessageMove($id, $newfolder)
+    {
+        return true;
+    }
+
+    /**
+     *
+     * @param $id
+     * @param $parent
+     * @param $displayname
+     * @param $type
+     * @return unknown_type
+     */
+    public function ImportFolderChange($id, $parent, $displayname, $type)
+    {
+        //do nothing if it is a dummy folder
+        if ($parent == SYNC_FOLDER_TYPE_DUMMY) {
+            return false;
+        }
+
+        if ($id) {
+            $change = array();
+            $change['id'] = $id;
+            $change['mod'] = $displayname;
+            $change['parent'] = $parent;
+            $change['flags'] = 0;
+            $this->_stateMachine->updateState('change', $change);
+        }
+
+        // @TODO: ChangeFolder did not exist in ZPush's code??
+        $stat = $this->_backend->ChangeFolder($parent, $id, $displayname, $type);
+        if ($stat) {
+            $this->_stateMachine->updateState('change', $stat);
+        }
+
+        return $stat['id'];
+    }
+
+    /**
+     *
+     * @param $id
+     * @param $parent
+     * @return unknown_type
+     */
+    public function ImportFolderDeletion($id, $parent)
+    {
+        //do nothing if it is a dummy folder
+        if ($parent == SYNC_FOLDER_TYPE_DUMMY) {
+            return false;
+        }
+
+        $change = array();
+        $change['id'] = $id;
+
+        $this->_stateMachine->updateState('delete', $change);
+        $this->_backend->DeleteFolder($parent, $id);
+
+        return true;
+    }
+
+    /**
+     *  Returns TRUE if the given ID conflicts with the given operation.
+     *  This is only true in the following situations:
+     *
+     *    Changed here and changed there
+     *    Changed here and deleted there
+     *    Deleted here and changed there
+     *
+     * Any other combination of operations can be done
+     * (e.g. change flags & move or move & delete)
+     */
+    protected function _isConflict($type, $folderid, $id)
+    {
+        $stat = $this->_backend->StatMessage($folderid, $id);
+        if (!$stat) {
+            // Message is gone
+            if ($type == 'change') {
+                return true;
+            } else {
+                return false; // all other remote changes still result in a delete (no conflict)
+            }
+        }
+
+        return $this->_stateMachine->isConflict($stat, $type);
+    }
+
+}
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Connector/NullImporter.php b/framework/ActiveSync/lib/Horde/ActiveSync/Connector/NullImporter.php
new file mode 100644 (file)
index 0000000..2d8f1d3
--- /dev/null
@@ -0,0 +1,11 @@
+<?php
+/**
+ * 
+ */
+class Horde_ActiveSync_Connector_NullImporter
+{
+    public function ImportMessageChange($id, $message) { return true; }
+    public function ImportMessageDeletion($id) { return true; }
+    public function ImportMessageReadFlag($id, $flags) { return true; }
+    public function ImportMessageMove($id, $newfolder) { return true; }
+}
\ No newline at end of file
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/ContentsCache.php b/framework/ActiveSync/lib/Horde/ActiveSync/ContentsCache.php
deleted file mode 100644 (file)
index 4c01b1a..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-<?php
-/**
- * @TODO: Can't figure out what this was meant to do, and in fact the
- * original Z-Push code that instantiates the Z-Push version of this class
- * called methods that don't exist here.
- *
- *  Looks like it's just a sort of placeholder class??
- */
-class Horde_ActiveSync_ContentsCache
-{
-    public function ImportMessageChange($message) { return true; }
-    public function ImportMessageDeletion($message) { return true; }
-    public function ImportMessageReadFlag($message) { return true; }
-    public function ImportMessageMove($message) { return true; }
-}
\ No newline at end of file
index 717d759..7dbdc4e 100644 (file)
@@ -344,12 +344,11 @@ abstract class Horde_ActiveSync_Driver_Base
 
     /**
      * @TODO: This will replace the above two methods
-     * @return Horde_ActiveSync_Importer
+     * @return Horde_ActiveSync_Connector_Importer
      */
     public function getImporter()
     {
-        $importer = new Horde_ActiveSync_Importer($this);
-        //$importer->setLogger($this->_logger);
+        $importer = new Horde_ActiveSync_Connector_Importer($this);
         return $importer;
     }
 
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/HierarchyCache.php b/framework/ActiveSync/lib/Horde/ActiveSync/HierarchyCache.php
deleted file mode 100644 (file)
index 123b543..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-<?php
-/**
- * This simply collects all changes so that they can be retrieved later, for
- * statistics gathering for example
- */
-/**
- * File      :   memimporter.php
- * Project   :   Z-Push
- * Descr     :   Classes that collect changes
- *
- * Created   :   01.10.2007
- *
- * © Zarafa Deutschland GmbH, www.zarafaserver.de
- * This file is distributed under GPL v2.
- * Consult LICENSE file for details
- */
-class Horde_ActiveSync_HierarchyCache
-{
-    public $changed;
-    public $deleted;
-    public $count;
-
-    public function __construct()
-    {
-        $this->changed = array();
-        $this->deleted = array();
-        $this->count = 0;
-
-        return true;
-    }
-
-    public function FolderChange($folder)
-    {
-        array_push($this->changed, $folder);
-        $this->count++;
-
-        return true;
-    }
-
-    public function FolderDeletion($id)
-    {
-        array_push($this->deleted, $id);
-        $this->count++;
-
-        return true;
-    }
-}
\ No newline at end of file
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Importer.php b/framework/ActiveSync/lib/Horde/ActiveSync/Importer.php
deleted file mode 100644 (file)
index 913c2ce..0000000
+++ /dev/null
@@ -1,261 +0,0 @@
-<?php
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-class Horde_ActiveSync_Importer
-{
-    /**
-     *
-     * @var Horde_ActiveSync_StateMachine_Base
-     */
-    protected $_stateMachine;
-
-    /**
-     *
-     * @var Horde_ActiveSync_Driver_Base
-     */
-    protected $_backend;
-
-    /**
-     * Sync key for current request
-     *
-     * @var string
-     */
-    protected $_syncKey;
-
-    /**
-     * @TODO
-     * @var <type>
-     */
-    protected $_flags;
-
-    /**
-     * The server specific folder id
-     *
-     * @var string
-     */
-    protected $_folderId;
-
-    protected $_logger;
-
-    /**
-     * Const'r
-     *
-     * @param Horde_ActiveSync_Driver_Base $backend
-     * @param Horde_ActiveSync_StateMachine_Base $stateMachine
-     * @param <type> $syncKey
-     * @param <type> $flags
-     */
-    public function __construct(Horde_ActiveSync_Driver_Base $backend)
-    {
-        $this->_backend = $backend;
-    }
-
-    public function init(Horde_ActiveSync_State_Base &$stateMachine,
-                         $folderId, $syncKey, $flags = 0)
-    {
-        $this->_stateMachine = &$stateMachine;
-        $this->_syncKey = $syncKey;
-        $this->_flags = $flags;
-        $this->_folderId = $folderId;
-    }
-
-    public function setLogger($logger)
-    {
-        $this->_logger = $logger;
-    }
-
-    /**
-     *
-     * @param mixed $id                                A server message id or
-     *                                                 false if a new message
-     * @param Horde_ActiveSync_Message_Base $message   A message object
-     *
-     * @return mixed The server message id or false
-     */
-    public function ImportMessageChange($id, $message)
-    {
-        //do nothing if it is in a dummy folder
-        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
-            return false;
-        }
-
-        if ($id) {
-            // See if there's a conflict
-            $conflict = $this->_isConflict('change', $this->_folderId, $id);
-
-            // Update client state if this is an update
-            $change = array();
-            $change['id'] = $id;
-            $change['mod'] = 0; // dummy, will be updated later if the change succeeds
-            $change['parent'] = $this->_folderId;
-            $change['flags'] = (isset($message->read)) ? $message->read : 0;
-            $this->_stateMachine->updateState('change', $change);
-
-            if ($conflict && $this->_flags == SYNC_CONFLICT_OVERWRITE_PIM) {
-                return true;
-            }
-        }
-
-        $stat = $this->_backend->ChangeMessage($this->_folderId, $id, $message);
-        // @TODO: Isn't this an error?
-        if (!is_array($stat)) {
-            return $stat;
-        }
-
-        // Record the state of the message
-        $this->_stateMachine->updateState('change', $stat);
-
-        return $stat['id'];
-    }
-
-    /**
-     * Import a deletion. This may conflict if the local object has been
-     * modified.
-     *
-     * @param string $id  Server message id
-     */
-    public function ImportMessageDeletion($id)
-    {
-        //do nothing if it is in a dummy folder
-        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
-            return true;
-        }
-
-        // See if there's a conflict
-        $conflict = $this->_isConflict('delete', $this->_folderId, $id);
-
-        // Update client state
-        $change = array();
-        $change['id'] = $id;
-        $this->_stateMachine->updateState('delete', $change);
-
-        // If there is a conflict, and the server 'wins', then return OK without
-        // performing the change this will cause the exporter to 'see' the
-        // overriding item as a change, and send it back to the PIM
-        if ($conflict && $this->_flags == SYNC_CONFLICT_OVERWRITE_PIM) {
-            return true;
-        }
-
-        $this->_backend->DeleteMessage($this->_folderId, $id);
-
-        return true;
-    }
-
-    /**
-     * Import a change in 'read' flags .. This can never conflict
-     *
-     * @param string $id  Server message id
-     * @param ??  $flags  The read flags to set
-     */
-    public function ImportMessageReadFlag($id, $flags)
-    {
-        //do nothing if it is a dummy folder
-        if ($this->_folderId == SYNC_FOLDER_TYPE_DUMMY) {
-            return true;
-        }
-
-        // Update client state
-        $change = array();
-        $change['id'] = $id;
-        $change['flags'] = $flags;
-        $this->_stateMachine->updateState('flags', $change);
-        $this->_backend->SetReadFlag($this->_folderId, $id, $flags);
-
-        return true;
-    }
-
-    /**
-     * Not supported/todo?
-     *
-     * @param <type> $id
-     * @param <type> $newfolder
-     * @return <type>
-     */
-    public function ImportMessageMove($id, $newfolder)
-    {
-        return true;
-    }
-
-    /**
-     *
-     * @param $id
-     * @param $parent
-     * @param $displayname
-     * @param $type
-     * @return unknown_type
-     */
-    public function ImportFolderChange($id, $parent, $displayname, $type)
-    {
-        //do nothing if it is a dummy folder
-        if ($parent == SYNC_FOLDER_TYPE_DUMMY) {
-            return false;
-        }
-
-        if ($id) {
-            $change = array();
-            $change['id'] = $id;
-            $change['mod'] = $displayname;
-            $change['parent'] = $parent;
-            $change['flags'] = 0;
-            $this->_stateMachine->updateState('change', $change);
-        }
-
-        // @TODO: ChangeFolder did not exist in ZPush's code??
-        $stat = $this->_backend->ChangeFolder($parent, $id, $displayname, $type);
-        if ($stat) {
-            $this->_stateMachine->updateState('change', $stat);
-        }
-
-        return $stat['id'];
-    }
-
-    /**
-     *
-     * @param $id
-     * @param $parent
-     * @return unknown_type
-     */
-    public function ImportFolderDeletion($id, $parent)
-    {
-        //do nothing if it is a dummy folder
-        if ($parent == SYNC_FOLDER_TYPE_DUMMY) {
-            return false;
-        }
-
-        $change = array();
-        $change['id'] = $id;
-
-        $this->_stateMachine->updateState('delete', $change);
-        $this->_backend->DeleteFolder($parent, $id);
-
-        return true;
-    }
-
-    /**
-     *  Returns TRUE if the given ID conflicts with the given operation.
-     *  This is only true in the following situations:
-     *
-     *    Changed here and changed there
-     *    Changed here and deleted there
-     *    Deleted here and changed there
-     *
-     * Any other combination of operations can be done
-     * (e.g. change flags & move or move & delete)
-     */
-    protected function _isConflict($type, $folderid, $id)
-    {
-        $stat = $this->_backend->StatMessage($folderid, $id);
-        if (!$stat) {
-            // Message is gone
-            if ($type == 'change') {
-                return true;
-            } else {
-                return false; // all other remote changes still result in a delete (no conflict)
-            }
-        }
-
-        return $this->_stateMachine->isConflict($stat, $type);
-    }
-}
\ No newline at end of file
index 3f08993..92ad9f8 100644 (file)
@@ -146,12 +146,12 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
         // this is not done when sync'ing messages - we let the exporter write
         // directly to WBXML.
         // TODO: Combine all these import caches into a single Class
-        $importer = new Horde_ActiveSync_HierarchyCache();
-        $exporter = $this->_driver->GetSyncObject();
-        $exporter->init($state, $importer, array('synckey' => $synckey));
+        $connector = new Horde_ActiveSync_Connector_Exporter();
+        $sync = $this->_driver->GetSyncObject();
+        $sync->init($state, $connector, array('synckey' => $synckey));
 
         /* Perform the actual sync operation */
-        while(is_array($exporter->syncronize()));
+        while(is_array($sync->syncronize()));
 
         // Output our WBXML reply now
         $this->_encoder->StartWBXML();
@@ -169,11 +169,11 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
         $this->_encoder->startTag(SYNC_FOLDERHIERARCHY_CHANGES);
 
         $this->_encoder->startTag(SYNC_FOLDERHIERARCHY_COUNT);
-        $this->_encoder->content($importer->count);
+        $this->_encoder->content($connector->count);
         $this->_encoder->endTag();
 
-        if (count($importer->changed) > 0) {
-            foreach ($importer->changed as $folder) {
+        if (count($connector->changed) > 0) {
+            foreach ($connector->changed as $folder) {
                 if (isset($folder->serverid) && in_array($folder->serverid, $seenfolders)) {
                     $this->_encoder->startTag(SYNC_FOLDERHIERARCHY_UPDATE);
                 } else {
@@ -184,8 +184,8 @@ class Horde_ActiveSync_Request_FolderSync extends Horde_ActiveSync_Request_Base
             }
         }
 
-        if (count($importer->deleted) > 0) {
-            foreach ($importer->deleted as $folder) {
+        if (count($connector->deleted) > 0) {
+            foreach ($connector->deleted as $folder) {
                 $this->_encoder->startTag(SYNC_FOLDERHIERARCHY_REMOVE);
                 $this->_encoder->startTag(SYNC_FOLDERHIERARCHY_SERVERENTRYID);
                 $this->_encoder->content($folder);
index e8bc880..c407bbf 100644 (file)
@@ -130,7 +130,7 @@ class Horde_ActiveSync_Request_GetItemEstimate extends Horde_ActiveSync_Request_
             $this->_encoder->endTag();
             $this->_encoder->startTag(SYNC_GETITEMESTIMATE_ESTIMATE);
 
-            $importer = new Horde_ActiveSync_ContentsCache();
+            $importer = new Horde_ActiveSync_Connector_NullImporter();
             $state = $this->_driver->getStateObject($collection);
             $state->loadState($collection['synckey']);
             $exporter = $this->_driver->getSyncObject();
index f443578..0e0883f 100644 (file)
@@ -435,10 +435,10 @@ 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;
-                $streamer = new Horde_ActiveSync_Streamer($this->_encoder, $collection['class']);
-                $exporter = $this->_driver->getSyncObject();
-                $exporter->init($state, $streamer, $collection);
-                $changecount = $exporter->getChangeCount();
+                $exporter = new Horde_ActiveSync_Connector_Exporter($this->_encoder, $collection['class']);
+                $sync = $this->_driver->getSyncObject();
+                $sync->init($state, $exporter, $collection);
+                $changecount = $sync->getChangeCount();
                 if (!empty($collection['windowsize']) && $changecount > $collection['windowsize']) {
                     $this->_encoder->startTag(SYNC_MOREAVAILABLE, false, true);
                 }
@@ -449,7 +449,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
                 // Stream the changes to the PDA
                 $n = 0;
                 while (1) {
-                    $progress = $exporter->syncronize();
+                    $progress = $sync->syncronize();
                     if (!is_array($progress)) {
                         break;
                     }
@@ -467,7 +467,7 @@ class Horde_ActiveSync_Request_Sync extends Horde_ActiveSync_Request_Base
 
             /* Save the sync state for the next time */
             if (isset($collection['newsynckey'])) {
-                if (!empty($exporter) || !empty($importer) || !empty($streamer) || $collection['synckey'] == 0)  {
+                if (!empty($sync) || !empty($importer) || !empty($exporter) || $collection['synckey'] == 0)  {
                     $state->setNewSyncKey($collection['newsynckey']);
                     $state->save();
                 } else {
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Streamer.php b/framework/ActiveSync/lib/Horde/ActiveSync/Streamer.php
deleted file mode 100644 (file)
index 19f3cca..0000000
+++ /dev/null
@@ -1,124 +0,0 @@
-<?php
-/**
- * File      :   streamimporter.php
- * Project   :   Z-Push
- * Descr     :   Stream import classes
- *
- * Created   :   01.10.2007
- *
- * � Zarafa Deutschland GmbH, www.zarafaserver.de
- * This file is distributed under GPL v2.
- * Consult LICENSE file for details
- */
-
-/**
- *
- *
- */
-class Horde_ActiveSync_Streamer
-{
-    protected $_encoder;
-    protected $_type;
-    protected $_seenObjects;
-
-    /**
-     * Const'r
-     *
-     * @param Horde_ActiveSync_Wbxml_Encoder $encoder
-     * @param string $class  The collection class
-     *
-     * @return Horde_ActiveSync_Streamer
-     */
-    public function __construct(&$encoder, $class)
-    {
-        $this->_encoder = &$encoder;
-        $this->_type = $class;
-        $this->_seenObjects = array();
-    }
-
-    /**
-     *
-     * @param $id
-     * @param $message
-     * @return unknown_type
-     */
-    public function messageChange($id, $message)
-    {
-        if ($message->getClass() != $this->_type) {
-            return true; // ignore other types
-        }
-
-        // prevent sending the same object twice in one request
-        if (in_array($id, $this->_seenObjects)) {
-               return true;
-        }
-
-        $this->_seenObjects[] = $id;
-        if ($message->flags === false || $message->flags === SYNC_NEWMESSAGE) {
-            $this->_encoder->startTag(SYNC_ADD);
-        } else {
-            $this->_encoder->startTag(SYNC_MODIFY);
-        }
-
-        $this->_encoder->startTag(SYNC_SERVERENTRYID);
-        $this->_encoder->content($id);
-        $this->_encoder->endTag();
-        $this->_encoder->startTag(SYNC_DATA);
-        $message->encodeStream($this->_encoder);
-        $this->_encoder->endTag();
-        $this->_encoder->endTag();
-
-        return true;
-    }
-
-    /**
-     *
-     * @param $id
-     * @return unknown_type
-     */
-    public function messageDeletion($id)
-    {
-        $this->_encoder->startTag(SYNC_REMOVE);
-        $this->_encoder->startTag(SYNC_SERVERENTRYID);
-        $this->_encoder->content($id);
-        $this->_encoder->endTag();
-        $this->_encoder->endTag();
-
-        return true;
-    }
-
-    /**
-     *
-     * @param $id
-     * @param $flags
-     * @return unknown_type
-     */
-    public function messageReadFlag($id, $flags)
-    {
-        if ($this->_type != "syncmail") {
-            return true;
-        }
-        $this->_encoder->startTag(SYNC_MODIFY);
-        $this->_encoder->startTag(SYNC_SERVERENTRYID);
-        $this->_encoder->content($id);
-        $this->_encoder->endTag();
-        $this->_encoder->startTag(SYNC_DATA);
-        $this->_encoder->startTag(SYNC_POOMMAIL_READ);
-        $this->_encoder->content($flags);
-        $this->_encoder->endTag();
-        $this->_encoder->endTag();
-        $this->_encoder->endTag();
-
-        return true;
-    }
-
-    /**
-     *
-     * @param $message
-     * @return unknown_type
-     */
-    function messageMove($message)
-    {
-        return true;
-    }
-}
\ No newline at end of file
index 8a77e2a..78dab1b 100644 (file)
@@ -102,9 +102,9 @@ class Horde_ActiveSync_Sync
     /**
      * The change streamer
      *
-     * @var Horde_ActiveSync_Streamer
+     * @var Horde_ActiveSync_Connector_Exporter
      */
-    protected $_streamer;
+    protected $_exporter;
 
     protected $_logger;
 
@@ -119,11 +119,11 @@ class Horde_ActiveSync_Sync
     }
 
     public function init(Horde_ActiveSync_State_Base &$stateMachine,
-                         $streamer,
+                         $exporter,
                          $collection = array())
     {
         $this->_stateMachine = &$stateMachine;
-        $this->_streamer = $streamer;
+        $this->_exporter = $exporter;
         $this->_folderId = !empty($collection['id']) ? $collection['id'] : false;
         $this->_changes = $stateMachine->getChanges();
         $this->_syncKey = $collection['synckey'];
@@ -158,12 +158,12 @@ class Horde_ActiveSync_Sync
                         return;
                     }
 
-                    if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->FolderChange($folder)) {
+                    if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->FolderChange($folder)) {
                         $this->_stateMachine->updateState('change', $stat);
                     }
                     break;
                 case 'delete':
-                    if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->FolderDeletion($change['id'])) {
+                    if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->FolderDeletion($change['id'])) {
                         $this->_stateMachine->updateState('delete', $change);
                     }
                     break;
@@ -198,26 +198,26 @@ class Horde_ActiveSync_Sync
                     $message->flags = (isset($change['flags'])) ? $change['flags'] : 0;
 
                     if ($stat && $message) {
-                        if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->messageChange($change['id'], $message) == true) {
+                        if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->messageChange($change['id'], $message) == true) {
                             $this->_stateMachine->updateState('change', $stat);
                         }
                     }
                     break;
 
                 case 'delete':
-                    if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->messageDeletion($change['id']) == true) {
+                    if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->messageDeletion($change['id']) == true) {
                         $this->_stateMachine->updateState('delete', $change);
                     }
                     break;
 
                 case 'flags':
-                    if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->messageReadFlag($change['id'], $change['flags']) == true) {
+                    if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->messageReadFlag($change['id'], $change['flags']) == true) {
                         $this->_stateMachine->updateState('flags', $change);
                     }
                     break;
 
                 case 'move':
-                    if ($flags & BACKEND_DISCARD_DATA || $this->_streamer->messageMove($change['id'], $change['parent']) == true) {
+                    if ($flags & BACKEND_DISCARD_DATA || $this->_exporter->messageMove($change['id'], $change['parent']) == true) {
                         $this->_stateMachine->updateState('move', $change);
                     }
                     break;
index 35841ac..3bd4fc1 100644 (file)
@@ -31,6 +31,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <dir name="lib">
     <dir name="Horde">
       <dir name="ActiveSync">
+       <dir name="Connector">
+         <file name="Exporter.php" role="php" />
+         <file name="Importer.php" role="php" />
+         <file name="NullImporter.php" role="php" />
+       </dir>
        <dir name="State">
          <file name="Base.php" role="php" />
          <file name="File.php" role="php" />
@@ -67,14 +72,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
          <file name="GetItemEstimate.php" role="php" />
        </dir>
        <file name="Exception.php" role="php" />
-       <file name="ContentsCache.php" role="php" />
-       <file name="HierarchyCache.php" role="php" />
-       <file name="ImportContentsChangesStream.php" role="php" />
        <file name="Wbxml.php" role="php" />
        <file name="Timezone.php" role="php" />
        <file name="Sync.php" role="php" />
-       <file name="Importer.php" role="php" />
-       <file name="Streamer.php" role="php" />
       </dir> <!-- /lib/Horde/ActiveSync -->
       <file name="ActiveSync.php" role="php" />
     </dir> <!-- /lib/Horde -->
@@ -97,6 +97,9 @@ http://pear.php.net/dtd/package-2.0.xsd">
  </dependencies>
  <phprelease>
   <filelist>
+   <install name="lib/Horde/ActiveSync/Connector/Exporter.php" as="Horde/ActiveSync/Connector/Exporter.php" />
+   <install name="lib/Horde/ActiveSync/Connector/Importer.php" as="Horde/ActiveSync/Connector/Importer.php" />
+   <install name="lib/Horde/ActiveSync/Connector/NullImporter.php" as="Horde/ActiveSync/Connector/NullImporter.php" />
    <install name="lib/Horde/ActiveSync/State/Base.php" as="Horde/ActiveSync/State/Base.php" />
    <install name="lib/Horde/ActiveSync/State/File.php" as="Horde/ActiveSync/State/File.php" />
    <install name="lib/Horde/ActiveSync/Driver/Horde/Connector/Registry.php" as="Horde/ActiveSync/Driver/Horde/Connector/Registry.php" />
@@ -118,15 +121,10 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/ActiveSync/Request/Options.php" as="Horde/ActiveSync/Request/Options.php" />
    <install name="lib/Horde/ActiveSync/Request/Provision.php" as="Horde/ActiveSync/Request/Provision.php" />
    <install name="lib/Horde/ActiveSync/Request/GetItemEstimate.php" as="Horde/ActiveSync/Request/GetItemEstimate.php" />
-   <install name="lib/Horde/ActiveSync/ContentsCache.php" as="Horde/ActiveSync/ContentsCache.php" />
    <install name="lib/Horde/ActiveSync/Exception.php" as="Horde/ActiveSync/Exception.php" />
-   <install name="lib/Horde/ActiveSync/HierarchyCache.php" as="Horde/ActiveSync/HierarchyCache.php" />
-   <install name="lib/Horde/ActiveSync/ImportContentsChangesStream.php" as="Horde/ActiveSync/ImportContentsChangesStream.php" />
    <install name="lib/Horde/ActiveSync/Wbxml.php" as="Horde/ActiveSync/Wbxml.php" />
    <install name="lib/Horde/ActiveSync/Timezone.php" as="Horde/ActiveSync/Timezone.php" />
-   <install name="lib/Horde/ActiveSync/Importer.php" as="Horde/ActiveSync/Importer.php" />
-   <install name="lib/Horde/ActiveSync/Sync.php" as="Horde/ActiveSync/Exporter.php" />
-   <install name="lib/Horde/ActiveSync/Streamer.php" as="Horde/ActiveSync/Streamer.php" />
+   <install name="lib/Horde/ActiveSync/Sync.php" as="Horde/ActiveSync/Sync.php" />
    <install name="lib/Horde/ActiveSync.php" as="Horde/ActiveSync.php" />
   </filelist>
  </phprelease>
index 49512c2..96ee5bd 100644 (file)
@@ -193,6 +193,7 @@ class Horde_ActiveSync_HordeDriverTest extends Horde_Test_Case
     }
     /**
      * Test ChangeMessage:
+     * 
      * This tests converting the contact streamer object to a hash suitable for
      * passing to the contacts/import method. Because it only returns the UID
      * for the newly added/edited entry, we can't check the results here. The