From 03dea923a72985f215f6fc5f51ab6fd72a9cd3c4 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Sat, 24 Apr 2010 09:29:57 -0400 Subject: [PATCH] Configuration for new history based state driver. Further clean up. --- .../lib/Horde/ActiveSync/Request/Ping.php | 2 +- .../ActiveSync/lib/Horde/ActiveSync/State/File.php | 6 +++--- .../lib/Horde/ActiveSync/State/History.php | 20 +++++++++----------- .../test/Horde/ActiveSync/FileStateTest.php | 4 ++-- .../test/Horde/ActiveSync/FolderSyncTest.php | Bin 4411 -> 4412 bytes .../{137c3bb0-838d-499a-9f0e-fb6c0761da51}1 | 1 + horde/config/conf.xml | 20 ++++++++++++++++++-- horde/rpc.php | 14 ++++++++++++-- 8 files changed, 46 insertions(+), 21 deletions(-) create mode 100644 framework/ActiveSync/test/Horde/ActiveSync/{137c3bb0-838d-499a-9f0e-fb6c0761da51}1 diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php index 885213ccc..2538bb8b8 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/Request/Ping.php @@ -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; } diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php index 56f576831..904360ff6 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/File.php @@ -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']; } /** diff --git a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php index 03cff0352..fd1f5cb4a 100644 --- a/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php +++ b/framework/ActiveSync/lib/Horde/ActiveSync/State/History.php @@ -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; diff --git a/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php b/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php index 1265440ad..42b682bcc 100644 --- a/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php +++ b/framework/ActiveSync/test/Horde/ActiveSync/FileStateTest.php @@ -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); diff --git a/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php b/framework/ActiveSync/test/Horde/ActiveSync/FolderSyncTest.php index e60189231c13ebb4dfb199ea86c0d647047352d1..02863060f5eefd248120653903d578c98c594aae 100644 GIT binary patch delta 22 dcmdn3v`1;fKSs`!%%arflKi5|&1_7j`~Yk12uJ_` delta 21 ccmdm^v|DMzKSqw?lEji!m&~Hg>`bQo0Aa}ovj6}9 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 index 000000000..fb336b553 --- /dev/null +++ b/framework/ActiveSync/test/Horde/ActiveSync/{137c3bb0-838d-499a-9f0e-fb6c0761da51}1 @@ -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 diff --git a/horde/config/conf.xml b/horde/config/conf.xml index 0411bc07b..c7275dcc1 100644 --- a/horde/config/conf.xml +++ b/horde/config/conf.xml @@ -1982,8 +1982,24 @@ State Storage Settings - /tmp + history + + + horde_activesync_device + horde_activesync_state + horde_activesync_map + + + + + /tmp + + + Logging diff --git a/horde/rpc.php b/horde/rpc.php index 8931a933c..a24a15c80 100644 --- a/horde/rpc.php +++ b/horde/rpc.php @@ -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']; } -- 2.11.0