From: Michael J. Rubinsky Date: Fri, 26 Mar 2010 22:20:45 +0000 (-0400) Subject: Initial refactoring of the GetItemEstimate request handler. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=bb11a32a011ac165e4e50ecc35847abf04087165;p=horde.git Initial refactoring of the GetItemEstimate request handler. This get's the Droid's corporate calendar a little closer... --- diff --git a/framework/ActiveSync/lib/Horde/ActiveSync.php b/framework/ActiveSync/lib/Horde/ActiveSync.php index 88f4d54ce..2867ae7a7 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync.php @@ -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 index 000000000..297f08894 --- /dev/null +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/GetItemEstimate.php @@ -0,0 +1,138 @@ + + * @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; + } + +} diff --git a/framework/ActiveSync/package.xml b/framework/ActiveSync/package.xml index dc090438b..4d9489edf 100644 --- a/framework/ActiveSync/package.xml +++ b/framework/ActiveSync/package.xml @@ -64,6 +64,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> + @@ -116,6 +117,7 @@ http://pear.php.net/dtd/package-2.0.xsd"> +