Initial refactoring of the GetItemEstimate request handler.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 26 Mar 2010 22:20:45 +0000 (18:20 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Fri, 26 Mar 2010 22:21:37 +0000 (18:21 -0400)
This get's the Droid's corporate calendar a little closer...

framework/ActiveSync/lib/Horde/ActiveSync.php
framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php [new file with mode: 0644]
framework/ActiveSync/package.xml

index 88f4d54..2867ae7 100644 (file)
@@ -1085,124 +1085,6 @@ class Horde_ActiveSync
     }
 
     /**
-     *
-     * @param $protocolversion
-     * @param $devid
-     * @return unknown_type
-     */
-    public function handleGetItemEstimate($protocolversion, $devid)
-    {
-        $collections = array();
-
-        if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE)) {
-            return false;
-        }
-
-        if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERS)) {
-            return false;
-        }
-
-        while ($this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDER)) {
-            $collection = array();
-
-            if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERTYPE)) {
-                return false;
-            }
-
-            $class = $this->_decoder->getElementContent();
-
-            if (!$this->_decoder->getElementEndTag()) {
-                return false;
-            }
-
-            if ($this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERID)) {
-                $collectionid = $this->_decoder->getElementContent();
-
-                if (!$this->_decoder->getElementEndTag()) {
-                    return false;
-                }
-            }
-
-            if (!$this->_decoder->getElementStartTag(SYNC_FILTERTYPE)) {
-                return false;
-            }
-            $filtertype = $this->_decoder->getElementContent();
-
-            if (!$this->_decoder->getElementEndTag()) {
-                return false;
-            }
-
-            if (!$this->_decoder->getElementStartTag(SYNC_SYNCKEY)) {
-                return false;
-            }
-
-            $synckey = $this->_decoder->getElementContent();
-
-            if (!$this->_decoder->getElementEndTag()) {
-                return false;
-            }
-            if (!$this->_decoder->getElementEndTag()) {
-                return false;
-            }
-
-            // compatibility mode - get folderid from the state directory
-            if (!isset($collectionid)) {
-                $collectionid = $this->_stateMachine->getFolderData($devid, $class);
-            }
-
-            $collection = array();
-            $collection['synckey'] = $synckey;
-            $collection['class'] = $class;
-            $collection['filtertype'] = $filtertype;
-            $collection['collectionid'] = $collectionid;
-
-            array_push($collections, $collection);
-        }
-
-        $this->_encoder->startWBXML();
-
-        $this->_encoder->startTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE);
-        foreach ($collections as $collection) {
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_RESPONSE);
-
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_STATUS);
-            $this->_encoder->content(1);
-            $this->_encoder->endTag();
-
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDER);
-
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERTYPE);
-            $this->_encoder->content($collection['class']);
-            $this->_encoder->endTag();
-
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERID);
-            $this->_encoder->content($collection['collectionid']);
-            $this->_encoder->endTag();
-
-            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_ESTIMATE);
-
-            $importer = new Horde_ActiveSync_ContentsCache();
-
-            $syncstate = $this->_stateMachine->loadState($collection['synckey']);
-
-            $exporter = $this->_driver->GetExporter($collection['collectionid']);
-            $exporter->Config($importer, $collection['class'], $collection['filtertype'], $syncstate, 0, 0);
-
-            $this->_encoder->content($exporter->GetChangeCount());
-
-            $this->_encoder->endTag();
-
-            $this->_encoder->endTag();
-
-            $this->_encoder->endTag();
-        }
-
-        $this->_encoder->endTag();
-
-        return true;
-    }
-
-    /**
      * @param $protocolversion
      * @return unknown_type
      */
diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php
new file mode 100644 (file)
index 0000000..297f088
--- /dev/null
@@ -0,0 +1,138 @@
+<?php
+/**
+ * ActiveSync Handler for GetItemEstimate requests
+ *
+ * Copyright 2009 - 2010 The Horde Project (http://www.horde.org)
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ * @package Horde_ActiveSync
+ */
+/**
+ * Zarafa Deutschland GmbH, www.zarafaserver.de
+ * This file is distributed under GPL v2.
+ * Consult LICENSE file for details
+ */
+class Horde_ActiveSync_Request_GetItemEstimate extends Horde_ActiveSync_Request_Base
+{
+    /**
+     * Handle the request
+     *
+     * @return boolean
+     * @throws Horde_ActiveSync_Exception
+     */
+    public function handle(Horde_ActiveSync $activeSync)
+    {
+        $collections = array();
+
+        if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE)) {
+            return false;
+        }
+
+        if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERS)) {
+            return false;
+        }
+
+        while ($this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDER)) {
+
+            if (!$this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERTYPE)) {
+                return false;
+            }
+
+            $class = $this->_decoder->getElementContent();
+
+            if (!$this->_decoder->getElementEndTag()) {
+                return false;
+            }
+
+            if ($this->_decoder->getElementStartTag(SYNC_GETITEMESTIMATE_FOLDERID)) {
+                $collectionid = $this->_decoder->getElementContent();
+
+                if (!$this->_decoder->getElementEndTag()) {
+                    return false;
+                }
+            }
+
+            if (!$this->_decoder->getElementStartTag(SYNC_FILTERTYPE)) {
+                return false;
+            }
+            $filtertype = $this->_decoder->getElementContent();
+
+            if (!$this->_decoder->getElementEndTag()) {
+                return false;
+            }
+
+            if (!$this->_decoder->getElementStartTag(SYNC_SYNCKEY)) {
+                return false;
+            }
+
+            $synckey = $this->_decoder->getElementContent();
+
+            if (!$this->_decoder->getElementEndTag()) {
+                return false;
+            }
+            if (!$this->_decoder->getElementEndTag()) {
+                return false;
+            }
+
+            $collection = array();
+            $collection['synckey'] = $synckey;
+            $collection['class'] = $class;
+            $collection['filtertype'] = $filtertype;
+
+            /* Initialize the state */
+            $state = &$this->_driver->getStateObject($collection);
+            $state->loadState($collection['synckey']);
+
+            // compatibility mode - get folderid from the state directory
+            if (!isset($collectionid)) {
+                $collectionid = $state>getFolderData($this->_devid, $collection['class']);
+            }
+            $collection['id'] = $collectionid;
+
+            array_push($collections, $collection);
+        }
+
+        $this->_encoder->startWBXML();
+
+        $this->_encoder->startTag(SYNC_GETITEMESTIMATE_GETITEMESTIMATE);
+        foreach ($collections as $collection) {
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_RESPONSE);
+
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_STATUS);
+            $this->_encoder->content(1);
+            $this->_encoder->endTag();
+
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDER);
+
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERTYPE);
+            $this->_encoder->content($collection['class']);
+            $this->_encoder->endTag();
+
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_FOLDERID);
+            $this->_encoder->content($collection['id']);
+            $this->_encoder->endTag();
+
+            $this->_encoder->startTag(SYNC_GETITEMESTIMATE_ESTIMATE);
+
+            $importer = new Horde_ActiveSync_ContentsCache();
+
+            $state->loadState($collection['synckey']);
+
+            $exporter = $this->_driver->GetExporter();
+            $exporter->init($state, $importer, $collection);
+
+            $this->_encoder->content($exporter->GetChangeCount());
+
+            $this->_encoder->endTag();
+
+            $this->_encoder->endTag();
+
+            $this->_encoder->endTag();
+        }
+
+        $this->_encoder->endTag();
+
+        return true;
+    }
+
+}
index dc09043..4d9489e 100644 (file)
@@ -64,6 +64,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
          <file name="Ping.php" role="php" />
          <file name="Options.php" role="php" />
          <file name="Provision.php" role="php" />
+         <file name="GetItemEstimate.php" role="php" />
        </dir>
        <file name="Exception.php" role="php" />
        <file name="ContentsCache.php" role="php" />
@@ -116,6 +117,7 @@ http://pear.php.net/dtd/package-2.0.xsd">
    <install name="lib/Horde/ActiveSync/Request/Ping.php" as="Horde/ActiveSync/Request/Ping.php" />
    <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" />