Skip to content

Commit

Permalink
Send server changes first, as specified by the specs.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 29, 2014
1 parent a4d483c commit 1fc87b4
Showing 1 changed file with 34 additions and 33 deletions.
67 changes: 34 additions & 33 deletions framework/ActiveSync/lib/Horde/ActiveSync/Request/Sync.php
Expand Up @@ -476,6 +476,40 @@ protected function _handle()

$ensure_sent = array();
if ($statusCode == self::STATUS_SUCCESS) {

// Send server changes to PIM
if ($statusCode == self::STATUS_SUCCESS &&
empty($forceChanges) &&
(!empty($collection['getchanges']) ||
(!isset($collection['getchanges']) && !empty($collection['synckey'])))) {

if ((!empty($changecount) && $changecount > $collection['windowsize']) ||
($cnt_global + $changecount > $this->_collections->getDefaultWindowSize())) {

$this->_logger->info(sprintf(
'[%s] Sending MOREAVAILABLE. $changecount = %d, $cnt_global = %d',
$this->_procid, $changecount, $cnt_global));
$this->_encoder->startTag(Horde_ActiveSync::SYNC_MOREAVAILABLE, false, true);
}

if (!empty($changecount)) {
$exporter->setChanges($this->_collections->getCollectionChanges(false, $ensure_sent), $collection);
$this->_encoder->startTag(Horde_ActiveSync::SYNC_COMMANDS);
$cnt_collection = 0;
while ($cnt_collection < $collection['windowsize'] &&
$cnt_global < $this->_collections->getDefaultWindowSize() &&
$progress = $exporter->sendNextChange()) {

if ($progress === true) {
++$cnt_collection;
++$cnt_global;
}
}

$this->_encoder->endTag();
}
}

if (!empty($collection['clientids']) || !empty($collection['fetchids'])
|| !empty($collection['missing']) || !empty($collection['importfailures'])) {

Expand Down Expand Up @@ -590,39 +624,6 @@ protected function _handle()
$this->_encoder->endTag();
}

// Send server changes to PIM
if ($statusCode == self::STATUS_SUCCESS &&
empty($forceChanges) &&
(!empty($collection['getchanges']) ||
(!isset($collection['getchanges']) && !empty($collection['synckey'])))) {

if ((!empty($changecount) && $changecount > $collection['windowsize']) ||
($cnt_global + $changecount > $this->_collections->getDefaultWindowSize())) {

$this->_logger->info(sprintf(
'[%s] Sending MOREAVAILABLE. $changecount = %d, $cnt_global = %d',
$this->_procid, $changecount, $cnt_global));
$this->_encoder->startTag(Horde_ActiveSync::SYNC_MOREAVAILABLE, false, true);
}

if (!empty($changecount)) {
$exporter->setChanges($this->_collections->getCollectionChanges(false, $ensure_sent), $collection);
$this->_encoder->startTag(Horde_ActiveSync::SYNC_COMMANDS);
$cnt_collection = 0;
while ($cnt_collection < $collection['windowsize'] &&
$cnt_global < $this->_collections->getDefaultWindowSize() &&
$progress = $exporter->sendNextChange()) {

if ($progress === true) {
++$cnt_collection;
++$cnt_global;
}
}

$this->_encoder->endTag();
}
}

// Save the sync state for the next time
if (!empty($collection['newsynckey'])) {
if (!empty($sync) || !empty($importer) || $collection['synckey'] == 0) {
Expand Down

0 comments on commit 1fc87b4

Please sign in to comment.