$collection['synckey'] == '0') {
$collection['newsynckey'] = Horde_ActiveSync_State_Base::getNewSyncKey(($this->_statusCode == self::STATUS_KEYMISM) ? 0 : $collection['synckey']);
- // @TODO: Need to reset the state??
+ if ($collection['synckey'] != 0) {
+ $state = &$this->_driver->getStateObject($collection);
+ $state->removeState($collection['synckey']);
+ }
}
$this->_encoder->startTag(Horde_ActiveSync::SYNC_FOLDER);
abstract public function setDeviceInfo($devId, $data);
/**
+ * Explicitly remove a state from storage.
+ *
+ * @param string $synckey
+ */
+ abstract public function removeState($synckey);
+
+ /**
* Set the backend driver
* (should really only be called by a backend object when passing this
* object to client code)
}
/**
+ * Explicitly remove a specific state. Normally used if a request results in
+ * a synckey mismatch. This isn't strictly needed, but helps keep the state
+ * storage clean.
+ *
+ */
+ public function removeState($syncKey)
+ {
+ $this->_gc($syncKey, true);
+ }
+
+ /**
* Garbage collector - clean up from previous sync
* requests.
*
* @return boolean
* @throws Horde_ActiveSync_Exception
*/
- private function _gc($syncKey)
+ private function _gc($syncKey, $all = false)
{
if (!preg_match('/^s{0,1}\{([0-9A-Za-z-]+)\}([0-9]+)$/', $syncKey, $matches)) {
return false;
}
while ($entry = readdir($dir)) {
if (preg_match('/^s{0,1}\{([0-9A-Za-z-]+)\}([0-9]+)$/', $entry, $matches)) {
- if ($matches[1] == $guid && $matches[2] < $n) {
+ if ($matches[1] == $guid && ((!$all && $matches[2] < $n) || $all)) {
unlink($this->_stateDir . '/' . $this->_backend->getUser() . '/' . $entry);
}
}