Skip to content

Commit

Permalink
Fix dirty property tracking for SyncCache.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 13, 2013
1 parent 8e6ff03 commit 883c0c5
Showing 1 changed file with 58 additions and 41 deletions.
99 changes: 58 additions & 41 deletions framework/ActiveSync/lib/Horde/ActiveSync/SyncCache.php
Expand Up @@ -262,21 +262,21 @@ public function setPingableCollection($id)
throw new InvalidArgumentException('Collection does not exist');
}
$this->_data['collections'][$id]['pingable'] = true;
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}

/**
* Set a collection as non-PINGable.
*
* @param string $collectionid The collection id.
*/
public function removePingableCollection($collectionid)
public function removePingableCollection($id)
{
if (empty($this->_data['collections'][$collectionid])) {
if (empty($this->_data['collections'][$id])) {
throw new InvalidArgumentException('Collection does not exist');
}
$this->_data['collections'][$collectionid]['pingable'] = false;
$this->_dirty['collections'][$collectionid] = true;
$this->_data['collections'][$id]['pingable'] = false;
$this->_markCollectionsDirty($id);
}

/**
Expand Down Expand Up @@ -307,7 +307,7 @@ public function setPingChangeFlag($id)
}

$this->_data['collections'][$id]['pingchange'] = true;
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}

/**
Expand All @@ -333,7 +333,7 @@ public function hasPingChangeFlag($collectionid)
public function resetPingChangeFlag($id)
{
$this->_data['collections'][$id]['pingchange'] = false;
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}

/**
Expand All @@ -352,7 +352,7 @@ public function refreshCollections()
$cache_collection['id'] = $id;
$cache_collection['synckey'] = $cache_collection['lastsynckey'];
$this->_data['collections'][$id] = $cache_collection;
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}
$this->_logger->info(sprintf(
'[%s] SyncCache collections refreshed.', getmypid()));
Expand All @@ -368,7 +368,7 @@ public function save()
if (!empty($collection['synckey'])) {
$collection['lastsynckey'] = $collection['synckey'];
unset($collection['synckey']);
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}
}
$this->timestamp = time();
Expand Down Expand Up @@ -401,7 +401,7 @@ public function addCollection(array $collection)
'bodyprefs' => isset($collection['bodyprefs']) ? $collection['bodyprefs'] : null,
'serverid' => isset($collection['serverid']) ? $collection['serverid'] : $collection['id']
);
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}

/**
Expand All @@ -418,7 +418,7 @@ public function removeCollection($id, $purge = true)
$this->_dirty['collections'] = true;
} elseif (!empty($this->_data['collections'][$id])) {
$this->_data['collections'][$id]['synckey'] = '0';
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}
}

Expand All @@ -431,7 +431,7 @@ public function removeCollection($id, $purge = true)
public function updateWindowSize($id, $windowsize)
{
$this->_data['collections'][$id]['windowsize'] = $windowsize;
$this->_dirty['collections'][$id] = true;
$this->_markCollectionsDirty($id);
}

/**
Expand All @@ -443,7 +443,7 @@ public function clearCollectionKeys()
foreach ($this->_data['collections'] as $id => &$c) {
unset($c['synckey']);
}
$this->_dirty['collections'][$id] = true;
$this->_dirty['collections'] = true;
}

/**
Expand Down Expand Up @@ -489,66 +489,66 @@ public function updateCollection(array $collection, array $options = array())
if (!empty($collection['id'])) {
if ($options['newsynckey']) {
$this->_data['collections'][$collection['id']]['synckey'] = $collection['newsynckey'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
} elseif (isset($collection['synckey'])) {
$this->_data['collections'][$collection['id']]['synckey'] = $collection['synckey'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['class'])) {
$this->_data['collections'][$collection['id']]['class'] = $collection['class'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['windowsize'])) {
$this->_data['collections'][$collection['id']]['windowsize'] = $collection['windowsize'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['deletesasmoves'])) {
$this->_data['collections'][$collection['id']]['deletesasmoves'] = $collection['deletesasmoves'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['filtertype'])) {
$this->_data['collections'][$collection['id']]['filtertype'] = $collection['filtertype'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['truncation'])) {
$this->_data['collections'][$collection['id']]['truncation'] = $collection['truncation'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['rtftruncation'])) {
$this->_data['collections'][$collection['id']]['rtftruncation'] = $collection['rtftruncation'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['mimesupport'])) {
$this->_data['collections'][$collection['id']]['mimesupport'] = $collection['mimesupport'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['mimetruncation'])) {
$this->_data['collections'][$collection['id']]['mimetruncation'] = $collection['mimetruncation'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['conflict'])) {
$this->_data['collections'][$collection['id']]['conflict'] = $collection['conflict'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['bodyprefs'])) {
$this->_data['collections'][$collection['id']]['bodyprefs'] = $collection['bodyprefs'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['pingable'])) {
$this->_data['collections'][$collection['id']]['pingable'] = $collection['pingable'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if (isset($collection['serverid'])) {
$this->_data['collections'][$collection['id']]['serverid'] = $collection['serverid'];
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if ($options['unsetChanges']) {
unset($this->_data['collections'][$collection['id']]['getchanges']);
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
if ($options['unsetPingChangeFlag']) {
unset($this->_data['collections'][$collection['id']]['pingchange']);
$this->_dirty['collections'][$collection['id']] = true;
$this->_markCollectionsDirty($collection['id']);
}
} else {
$this->_logger->info(sprintf(
Expand All @@ -569,39 +569,39 @@ public function validateCollectionsFromCache(&$collections)
foreach ($collections as $key => $values) {
if (!isset($values['class']) && isset($this->_data['folders'][$values['id']]['class'])) {
$collections[$key]['class'] = $this->_data['folders'][$values['id']]['class'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (!isset($values['filtertype']) && isset($this->_data['collections'][$values['id']]['filtertype'])) {
$collections[$key]['filtertype'] = $this->_data['collections'][$values['id']]['filtertype'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (!isset($values['mimesupport']) && isset($this->_data['collections'][$values['id']]['mimesupport'])) {
$collections[$key]['mimesupport'] = $this->_data['collections'][$values['id']]['mimesupport'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (empty($values['bodyprefs']) && isset($this->_data['collections'][$values['id']]['bodyprefs'])) {
$collections[$key]['bodyprefs'] = $this->_data['collections'][$values['id']]['bodyprefs'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (empty($values['truncation']) && isset($this->_data['collections'][$values['id']]['truncation'])) {
$collections[$key]['truncation'] = $this->_data['collections'][$values['id']]['truncation'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (empty($values['mimetruncation']) && isset($this->_data['collections'][$values['id']]['mimetruncation'])) {
$collections[$key]['mimetruncation'] = $this->_data['collections'][$values['id']]['mimetruncation'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
if (empty($values['serverid']) && isset($this->_data['collections'][$values['id']]['serverid'])) {
$collections[$key]['serverid'] = $this->_data['collections'][$values['id']]['serverid'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}

if (!isset($values['windowsize'])) {
$collections[$key]['windowsize'] =
isset($this->_data['collections'][$values['id']]['windowsize'])
? $this->_data['collections'][$values['id']]['windowsize']
: 100;
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}

// in case the maxitems (windowsize) is above 512 or 0 it should be
Expand All @@ -610,7 +610,7 @@ public function validateCollectionsFromCache(&$collections)
$collections[$key]['windowsize'] == 0) {

$collections[$key]['windowsize'] = self::MAX_WINDOW_SIZE;
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}

if (isset($values['synckey']) &&
Expand All @@ -619,12 +619,12 @@ public function validateCollectionsFromCache(&$collections)
$this->_data['collections'][$values['id']]['synckey'] != '0') {

unset($this->_data['collections'][$values['id']]['synckey']);
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}

if (!isset($values['pingable']) && isset($this->_data['collections'][$values['id']]['pingable'])) {
$collections[$key]['pingable'] = $this->_data['collections'][$values['id']]['pingable'];
$this->_dirty['collections'][$key] = true;
$this->_markCollectionsDirty($key);
}
}
}
Expand Down Expand Up @@ -689,7 +689,8 @@ public function deleteFolder($folder)
{
unset($this->_data['folders'][$folder]);
unset($this->_data['collections'][$folder]);
$this->_dirty['folders'] = $this->_dirty['collections'][$folder] = true;
$this->_dirty['folders'] = true;
$this->_markCollectionsDirty($folder);
}

/**
Expand All @@ -714,4 +715,20 @@ public function delete()
$this->_dirty = array();
}

/**
* Mark specific collection as dirty, but only if the entire collection
* data is not already marked dirty.
*
* @param boolean $id The collection to mark dirty.
*/
protected function _markCollectionsDirty($id)
{
if (isset($this->_dirty['collections']) && is_array($this->_dirty['collections'])) {
$this->_dirty['collections'][$id] = true;
} elseif (!isset($this->_dirty['collections']) || $this->_dirty['collections'] !== true) {
$this->_dirty['collections'] = array();
$this->_markCollectionsDirty($id);
}
}

}

0 comments on commit 883c0c5

Please sign in to comment.