Skip to content

Commit

Permalink
Merge branch 'EAS16'
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Aug 31, 2016
2 parents 228fd52 + dea8bae commit 1e18a4c
Show file tree
Hide file tree
Showing 22 changed files with 1,242 additions and 388 deletions.
6 changes: 5 additions & 1 deletion framework/ActiveSync/doc/Horde/ActiveSync/TODO
Expand Up @@ -80,6 +80,9 @@ BC BREAKING (i.e., Horde 6).
living in the RPC layer (sending back certain headers, etc...) into this
class.

- Split out code for sending response in Sync.php to it's own class, or at the
very least, it's own method. ??

- Implement a Horde_ActiveSync_Change_Filter class/interface. Used to implement
workarounds for broken clients. E.g., filter out the ADD commands sent in
response to MOVEITEMS for Outlook clients. Use a similar pattern for other
Expand Down Expand Up @@ -112,7 +115,8 @@ BC BREAKING (i.e., Horde 6).
and transporting the various collection options/bodyprefs around.

- Likewise, implement a collection object instead of using an array to define
each collection.
each collection and have it be responsible for providing some of the return
objects/values (See comments in Sync.php).

- Implement Horde_ActiveSync_SyncKey.

Expand Down
4 changes: 2 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/Collections.php
Expand Up @@ -708,10 +708,10 @@ public function getHierarchyChanges()
* Validate and perform some sanity checks on the hierarchy changes before
* being sent to the client.
*
* @param Horde_ActiveSync_Connector_Exporter $exporter The exporter.
* @param Horde_ActiveSync_Connector_Exporter_FolderSync $exporter The exporter.
* @param array $seenFolders An array of folders.
*/
public function validateHierarchyChanges(Horde_ActiveSync_Connector_Exporter $exporter, array $seenFolders)
public function validateHierarchyChanges(Horde_ActiveSync_Connector_Exporter_FolderSync $exporter, array $seenFolders)
{
if ($this->_as->device->version < Horde_ActiveSync::VERSION_TWELVEONE ||
count($exporter->changed)) {
Expand Down
104 changes: 104 additions & 0 deletions framework/ActiveSync/lib/Horde/ActiveSync/Connector/Exporter/Base.php
@@ -0,0 +1,104 @@
<?php
/**
* Horde_ActiveSync_Connector_Exporter_Base::
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2009-2016 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*/
/**
* Horde_ActiveSync_Connector_Exporter_Base:: Base class contains common
* code for outputing common blocks of WBXML data in server responses.
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2009-2016 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*/
abstract class Horde_ActiveSync_Connector_Exporter_Base
{
/**
* The wbxml encoder
*
* @var Horde_ActiveSync_Wbxml_Encoder
*/
protected $_encoder;

/**
* Local cache of changes to send.
*
* @var array
*/
protected $_changes = array();

/**
* Counter of changes sent.
*
* @var integer
*/
protected $_step = 0;

/**
* The ActiveSync server object.
*
* @var Horde_ActiveSync
*/
protected $_as;

/**
* Process id for logging.
*
* @var integer
*/
protected $_procid;

/**
* Const'r
*
* @param Horde_ActiveSync $as The ActiveSync server.
* @param Horde_ActiveSync_Wbxml_Encoder $encoder The encoder
*
* @return Horde_ActiveSync_Connector_Exporter
*/
public function __construct(
Horde_ActiveSync $as,
Horde_ActiveSync_Wbxml_Encoder $encoder = null)
{
$this->_as = $as;
$this->_encoder = $encoder;
$this->_logger = $as->logger;
$this->_procid = getmypid();
}

/**
* Set the changes to send to the client.
*
* @param array $changes The changes array returned from the collection
* handler.
* @param array $collection The collection we are currently syncing.
*/
public function setChanges($changes, $collection = null)
{
$this->_changes = $changes;
$this->_seenObjects = array();
$this->_step = 0;
}

/**
* Sends the next change in the set to the client.
*
* @return boolean|Horde_Exception True if more changes can be sent false if
* all changes were sent, Horde_Exception if
* there was an error sending an item.
*/
abstract public function sendNextChange();
}
@@ -0,0 +1,136 @@
<?php
/**
* Horde_ActiveSync_Connector_Exporter_FolderSync::
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2009-2016 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*/
/**
* Horde_ActiveSync_Connector_Exporter_FolderSync:: Responsible for outputing
* blocks of WBXML responses in FOLDER_SYNC responses.
*
* @license http://www.horde.org/licenses/gpl GPLv2
* NOTE: According to sec. 8 of the GENERAL PUBLIC LICENSE (GPL),
* Version 2, the distribution of the Horde_ActiveSync module in or
* to the United States of America is excluded from the scope of this
* license.
* @copyright 2009-2016 Horde LLC (http://www.horde.org)
* @author Michael J Rubinsky <mrubinsk@horde.org>
* @package ActiveSync
*/
class Horde_ActiveSync_Connector_Exporter_FolderSync extends Horde_ActiveSync_Connector_Exporter_Base
{

/**
* Array of folder objects that have changed.
* Used when exporting folder structure changes since they are not streamed
* from this object.
*
* @var array
*/
public $changed = array();

/**
* Array of folder ids that have been deleted on the server.
*
* @var array
*/
public $deleted = array();

/**
* Tracks the total number of folder changes
*
* @var integer
*/
public $count = 0;

/**
* Sends the next change in the set to the client.
*
* @return boolean|Horde_Exception True if more changes can be sent false if
* all changes were sent, Horde_Exception if
* there was an error sending an item.
*/
public function sendNextChange()
{
return $this->_sendNextFolderSyncChange();
}

/**
* Sends the next folder change to the client.
*
* @return @see self::sendNextChange()
*/
protected function _sendNextFolderSyncChange()
{
if ($this->_step < count($this->_changes)) {
$change = $this->_changes[$this->_step];
switch($change['type']) {
case Horde_ActiveSync::CHANGE_TYPE_CHANGE:
// Folder add/change.
if ($folder = $this->_as->driver->getFolder($change['serverid'])) {
// @TODO BC HACK. Need to ensure we have a _serverid here.
// REMOVE IN H6.
if (empty($folder->_serverid)) {
$folder->_serverid = $folder->serverid;
}
$stat = $this->_as->driver->statFolder(
$change['id'],
$folder->parentid,
$folder->displayname,
$folder->_serverid,
$folder->type);
$this->folderChange($folder);
} else {
$this->_logger->err(sprintf(
'[%s] Error stating %s: ignoring.',
$this->_procid, $change['id']));
$stat = array('id' => $change['id'], 'mod' => $change['id'], 0);
}
// Update the state.
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_FOLDERSYNC, $stat);
break;

case Horde_ActiveSync::CHANGE_TYPE_DELETE:
$this->folderDeletion($change['id']);
$this->_as->state->updateState(
Horde_ActiveSync::CHANGE_TYPE_DELETE, $change);
break;
}
$this->_step++;
return true;
} else {
return false;
}
}

/**
* Add a folder change to the cache (used during FolderSync requests).
*
* @param Horde_ActiveSync_Message_Folder $folder
*/
public function folderChange(Horde_ActiveSync_Message_Folder $folder)
{
$this->changed[] = $folder;
$this->count++;
}

/**
* Add a folder deletion to the cache (used during FolderSync Requests).
*
* @param string $id The folder id
*/
public function folderDeletion($id)
{
$this->deleted[] = $id;
$this->count++;
}

}

0 comments on commit 1e18a4c

Please sign in to comment.