allow removing all of a devices state without knowing a synckey
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 29 Apr 2010 19:24:09 +0000 (15:24 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 29 Apr 2010 19:24:09 +0000 (15:24 -0400)
framework/ActiveSync/lib/Horde/ActiveSync/State/Base.php
framework/ActiveSync/lib/Horde/ActiveSync/State/File.php
framework/ActiveSync/lib/Horde/ActiveSync/State/History.php

index f48e8b8..7c5a0d3 100644 (file)
@@ -546,9 +546,12 @@ abstract class Horde_ActiveSync_State_Base
     /**
      * Explicitly remove a state from storage.
      *
-     * @param string $synckey
+     * @param string $synckey  The specific state to remove
+     * @param string $devId    Remove all state for this device (ignores synckey)
+     *
+     * @throws Horde_ActiveSyncException
      */
-    abstract public function removeState($synckey);
+    abstract public function removeState($synckey = null, $devId = null);
 
     /**
      * Return the heartbeat interval, or zero if we have no existing state
index 2f8f240..8752834 100644 (file)
@@ -588,8 +588,11 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
      * storage clean.
      *
      */
-    public function removeState($syncKey)
+    public function removeState($syncKey = null, $devId = null)
     {
+        if ($devId) {
+            throw new Horde_ActiveSync_Exception('Not implemented.');
+        }
         $this->_gc($syncKey, true);
     }
 
index d688740..b3cfa38 100644 (file)
@@ -757,17 +757,29 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
      * Explicitly remove a state from storage.
      *
      * @param string $synckey  The specific state to remove
+     * @param string $devId    Remove all state for this device (ignores synckey)
      *
      * @throws Horde_ActiveSyncException
      */
-    public function removeState($synckey)
+    public function removeState($synckey = null, $devId = null)
     {
-        $this->_logger->debug('[' . $this->_devId . '] Removing device state.');
-        $state_query = 'DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_key = ?';
-        $map_query = 'DELETE FROM ' . $this->_syncMapTable . ' WHERE sync_key = ?';
+        $state_query = 'DELETE FROM ' . $this->_syncStateTable . ' WHERE';
+        $map_query = 'DELETE FROM ' . $this->_syncMapTable . ' WHERE';
+        if ($devId) {
+            $state_query .= ' sync_devid = ?';
+            $map_query .= ' sync_devid = ?';
+            $values = array($devId);
+            $this->_logger->debug('[' . $devId . '] Removing device state.');
+        } else {
+            $state_query .= ' sync_key = ?';
+            $map_query .= ' sync_key = ?';
+            $values = array($synckey);
+            $this->_logger->debug('[' . $this->_devId . '] Removing device state.');
+        }
+
         try {
-            $this->_db->delete($state_query, array($synckey));
-            $this->_db->delete($map_query, array($synckey));
+            $this->_db->delete($state_query, $values);
+            $this->_db->delete($map_query, $values);
         } catch (Horde_Db_Exception $e) {
             throw new Horde_ActiveSync_Exception($e);
         }