Configuration for new history based state driver. Further clean up.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 24 Apr 2010 13:29:57 +0000 (09:29 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 24 Apr 2010 16:22:44 +0000 (12:22 -0400)
framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php
framework/ActiveSync/lib/Horde/ActiveSync/State/File.php
framework/ActiveSync/lib/Horde/ActiveSync/State/History.php
framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php
framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php
framework/ActiveSync/test/Horde/ActiveSync/{137c3bb0-838d-499a-9f0e-fb6c0761da51}1 [new file with mode: 0644]
horde/config/conf.xml
horde/rpc.php

index 885213c..2538bb8 100644 (file)
@@ -170,7 +170,7 @@ class Horde_ActiveSync_Request_Ping extends Horde_ActiveSync_Request_Base
                         $sync->init($this->_state, null, $collection);
                     } catch (Horde_ActiveSync_Exception $e) {
                         /* Stop ping if exporter cannot be configured */
-                        $this->_logger->err('Ping error: Exporter can not be configured. Waiting 30 seconds before ping is retried.');
+                        $this->_logger->err('Ping error: Exporter can not be configured. ' . $e->getMessage() . ' Waiting 30 seconds before ping is retried.');
                         sleep(30);
                         break;
                     }
index 56f5768..904360f 100644 (file)
@@ -66,7 +66,7 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
     /**
      * Const'r
      *
-     * @param array  $params   Must contain 'stateDir' entry
+     * @param array  $params   Must contain 'directory' entry
      *
      * @return Horde_ActiveSync_StateMachine_File
      */
@@ -74,11 +74,11 @@ class Horde_ActiveSync_State_File extends Horde_ActiveSync_State_Base
     {
         parent::__construct($params);
 
-        if (empty($this->_params['stateDir'])) {
+        if (empty($this->_params['directory'])) {
             throw new InvalidArgumentException('Missing required "stateDir" parameter.');
         }
 
-        $this->_stateDir = $this->_params['stateDir'];
+        $this->_stateDir = $this->_params['directory'];
     }
 
     /**
index 03cff03..fd1f5cb 100644 (file)
@@ -64,10 +64,10 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
      */
     protected $_db;
 
-    /* TODO - config these */
-    protected $_syncStateTable = 'horde_activesync_state';
-    protected $_syncMapTable = 'horde_activesync_map';
-    protected $_syncDeviceTable = 'horde_activesync_device';
+    /* Table names */
+    protected $_syncStateTable;
+    protected $_syncMapTable;
+    protected $_syncDeviceTable;
 
     /**
      * Const'r
@@ -89,7 +89,9 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
             throw new InvalidArgumentException('Missing or invalid Horde_Db parameter.');
         }
 
-        $this->_params = $params;
+        $this->_syncStateTable = $params['statetable'];
+        $this->_syncMapTable = $params['maptable'];
+        $this->_syncDeviceTable = $params['devicetable'];
         $this->_db = $params['db'];
     }
 
@@ -291,11 +293,6 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
             $unique_folders[Horde_ActiveSync::FOLDER_TYPE_CONTACT] = Horde_ActiveSync::FOLDER_TYPE_DUMMY;
         }
         /* Storage to SQL? */
-//
-//        if (!file_put_contents($this->_stateDir . '/compat-' . $devId, serialize($unique_folders))) {
-//            $this->logError('_saveFolderData: Data could not be saved!');
-//            throw new Horde_ActiveSync_Exception('Folder data could not be saved');
-//        }
     }
 
     /**
@@ -362,7 +359,7 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
          }
 
          /* Need to get the last sync time for this collection */
-         return $this->_pingState['collections'];
+         return !empty($this->_pingState['collections']);
     }
 
     /**
@@ -408,6 +405,7 @@ class Horde_ActiveSync_State_History extends Horde_ActiveSync_State_Base
             $this->_deviceInfo->userAgent = '';
             $this->_deviceInfo->id = $devId;
             $this->setDeviceInfo($devId, $this->_deviceInfo);
+            $this->resetPingState();
         }
 
         return $this->_deviceInfo;
index 1265440..42b682b 100644 (file)
@@ -29,7 +29,7 @@ class Horde_ActiveSync_FileStateTest extends Horde_Test_Case
                 ->method('contacts_getActionTimestamp')
                 ->will($this->returnValue($fixture['contacts_getActionTimestamp']));
 
-        $state = new Horde_ActiveSync_State_File(array('stateDir' => './'));
+        $state = new Horde_ActiveSync_State_File(array('directory' => './'));
         $driver = new Horde_ActiveSync_Driver_Horde(array('connector' => $connector,
                                                           'state_basic' => $state));
 
@@ -60,7 +60,7 @@ class Horde_ActiveSync_FileStateTest extends Horde_Test_Case
 
         /* ...and check that it contains the serialized state data
          *  by reading it into a new object and performing another diff */
-        $newstate = new Horde_ActiveSync_State_File(array('stateDir' => './'));
+        $newstate = new Horde_ActiveSync_State_File(array('directory' => './'));
         $newstate->init(array('id' => 'Contacts',
                            'class' => 'Contacts'));
         $newstate->setBackend($driver);
index e601892..0286306 100644 (file)
Binary files a/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php and b/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php differ
diff --git a/framework/ActiveSync/test/Horde/ActiveSync/{137c3bb0-838d-499a-9f0e-fb6c0761da51}1 b/framework/ActiveSync/test/Horde/ActiveSync/{137c3bb0-838d-499a-9f0e-fb6c0761da51}1
new file mode 100644 (file)
index 0000000..fb336b5
--- /dev/null
@@ -0,0 +1 @@
+a:1:{i:0;a:3:{s:2:"id";s:52:"20070112030611.62g1lg5nry80@test.theupstairsroom.com";s:3:"mod";i:0;s:5:"flags";i:1;}}
\ No newline at end of file
index 0411bc0..c7275dc 100644 (file)
     <case name="true" desc="Enabled">
      <configsection name="state">
       <configheader>State Storage Settings</configheader>
-      <configstring name="directory" desc="Directory to hold state files (this
-      directory should be writeable by the webserver):">/tmp</configstring>
+      <configswitch name="driver" desc="Choose the state driver to use.">history
+       <case name="history" desc="Native Horde history driver">
+         <configsection name="params">
+          <configstring name="devicetable" desc="Name of table to hold device
+          information:">horde_activesync_device</configstring>
+          <configstring name="statetable" desc="Name of table to hold state
+          data:">horde_activesync_state</configstring>
+          <configstring name="maptable" desc="Name of table to hold mapping data
+          for device-sent changes.">horde_activesync_map</configstring>
+         </configsection>
+       </case>
+       <case name="file" desc="Generic file based driver">
+        <configsection name="params">
+         <configstring name="directory" desc="Directory to hold state files (this
+         directory should be writeable by the webserver):">/tmp</configstring>
+        </configsection>
+       </case>
+      </configswitch>
      </configsection>
      <configheader>Logging</configheader>
      <configsection name="logging">
index 8931a93..a24a15c 100644 (file)
@@ -43,7 +43,7 @@ if ((!empty($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'appli
     /* Check if we are even enabled for AS */
     if (!empty($GLOBALS['conf']['activesync']['enabled'])) {
         $request = new Horde_Controller_Request_Http(array('session_control' => $session_control));
-        if ($conf['activesync']['logging']['type'] == 'custom') {
+        if ($GLOBALS['conf']['activesync']['logging']['type'] == 'custom') {
             $params['logger'] = new Horde_Log_Logger(new Horde_Log_Handler_Stream(fopen($conf['activesync']['logging']['path'], 'a')));
         } else {
             $params['logger'] = $GLOBALS['injector']->getInstance('Horde_Log_Logger');
@@ -53,11 +53,21 @@ if ((!empty($_SERVER['CONTENT_TYPE']) && strpos($_SERVER['CONTENT_TYPE'], 'appli
         /* TODO: Probably want to bind a factory to injector for this? */
         $params['registry'] = $GLOBALS['registry'];
         $connector = new Horde_ActiveSync_Driver_Horde_Connector_Registry($params);
-        $stateMachine = new Horde_ActiveSync_State_File(array('stateDir' => $GLOBALS['conf']['activesync']['state']['directory']));
+        switch ($GLOBALS['conf']['activesync']['state']['driver']) {
+        case 'file':
+            $stateMachine = new Horde_ActiveSync_State_File($GLOBALS['conf']['activesync']['state']['params']);
+            break;
+        case 'history':
+            $state_params = $GLOBALS['conf']['activesync']['state']['params'];
+            $state_params['db'] = $GLOBALS['injector']->getInstance('Horde_Db_Adapter_Base');
+            $stateMachine = new Horde_ActiveSync_State_History($state_params);
+        }
+        
         $driver_params = array('connector' => $connector,
                                'state_basic' => $stateMachine,
                                'mail' => $mailer,
                                'ping' => $GLOBALS['conf']['activesync']['ping']);
+
         if ($params['provisioning'] = $GLOBALS['conf']['activesync']['securitypolicies']['provisioning']) {
             $driver_params['policies'] = $GLOBALS['conf']['activesync']['securitypolicies'];
         }