public function testValidateTimestamps() { $cache = new Horde_ActiveSync_SyncCache($this->_state, 'devid', 'userone'); $this->assertEquals(true, $cache->validateTimestamps()); $cache->lasthbsyncstarted = time(); $this->assertEquals(false, $cache->validateTimestamps()); }
/** */ public function display(Horde_Core_Prefs_Ui $ui) { global $injector, $page_output, $prefs, $registry; try { $state = $injector->getInstance('Horde_ActiveSyncState'); } catch (Horde_Exception $e) { return _("ActiveSync not activated."); } $devices = $state->listDevices($registry->getAuth()); $view = new Horde_View(array('templatePath' => array(HORDE_TEMPLATES . '/prefs', HORDE_TEMPLATES . '/activesync'))); $view->addHelper('Tag'); $view->isAdmin = false; $selfurl = $ui->selfUrl(); $view->reset = $selfurl->copy()->add('reset', 1); $devs = array(); $js = array(); $collections = array(); foreach ($devices as $device) { $dev = $state->loadDeviceInfo($device['device_id'], $registry->getAuth()); try { $dev = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('activesync_device_modify', 'horde', array($dev)); } catch (Horde_Exception_HookNotSet $e) { } $js[$dev->id . ':' . $registry->getAuth()] = array('id' => $dev->id, 'user' => $dev->user); $syncCache = new Horde_ActiveSync_SyncCache($state, $dev->id, $dev->user, $injector->getInstance('Horde_Log_Logger')); $dev->hbinterval = $syncCache->hbinterval ? $syncCache->hbinterval : ($syncCache->wait ? $syncCache->wait * 60 : _("Unavailable")); $devs[] = $dev; $collection = array(); foreach ($syncCache->getCollections() as $id => $c) { $collection[] = array(_("Collection id") => $id, _("Class") => $c['class'], _("Server Id") => $c['serverid'], _("Last synckey") => $c['lastsynckey']); } $collections[] = $collection; } $view->collections = $collections; // Identities if (!$prefs->isLocked('activesync_identity')) { $ident = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Identity')->create($registry->getAuth()); $view->identities = $ident->getAll('id'); $view->identities['horde'] = _("Use Horde Default"); $view->default = $prefs->getValue('activesync_identity'); if (is_null($view->default)) { $view->default = $prefs->getValue('default_identity'); } } $page_output->addScriptFile('activesyncprefs.js', 'horde'); $page_output->addInlineJsVars(array('HordeActiveSyncPrefs.devices' => $js)); $view->devices = $devs; return $view->render('activesync'); }
/** * Force reset all collection's PINGABLE flag. Used to force client * to issue a non-empty PING request. * */ public function resetPingCache() { $collections = $this->_cache->getCollections(false); foreach ($collections as $id => $collection) { $this->_logger->info(sprintf('UNSETTING collection %s (%s) PINGABLE flag.', $collection['serverid'], $id)); $this->_cache->removePingableCollection($id); } }
$devices = $state->listDevices(null, array(Horde_Util::getPost('searchBy') => Horde_Util::getPost('searchInput'))); } $view = new Horde_View(array('templatePath' => array(HORDE_TEMPLATES . '/admin', HORDE_TEMPLATES . '/activesync'))); $view->addHelper('Tag'); $selfurl = Horde::selfUrl(); $view->reset = $selfurl->copy()->add('reset', 1); $devs = array(); $js = array(); $collections = array(); foreach (array_values($devices) as $device) { $dev = $state->loadDeviceInfo($device['device_id'], $device['device_user']); try { $dev = $GLOBALS['injector']->getInstance('Horde_Core_Hooks')->callHook('activesync_device_modify', 'horde', array($dev)); } catch (Horde_Exception_HookNotSet $e) { } $syncCache = new Horde_ActiveSync_SyncCache($state, $dev->id, $dev->user, $injector->getInstance('Horde_Log_Logger')); $dev->hbinterval = $syncCache->hbinterval ? $syncCache->hbinterval : ($syncCache->wait ? $syncCache->wait * 60 : _("Unavailable")); $js[$dev->id . ':' . $dev->user] = array('id' => $dev->id, 'user' => $dev->user); $devs[] = $dev; $collection = array(); foreach ($syncCache->getCollections() as $id => $c) { $collection[] = array(_("Collection id") => $id, _("Class") => $c['class'], _("Server Id") => $c['serverid'], _("Last synckey") => $c['lastsynckey']); } $collections[] = $collection; } $view->devices = $devs; $view->collections = $collections; $view->isAdmin = true; $page_output->header(array('title' => _("ActiveSync Administration"))); require HORDE_TEMPLATES . '/admin/menu.inc'; $page_output->addScriptFile('activesyncadmin.js', 'horde');
/** * Reset the sync state for this device, for the specified collection. * * @param string $id The collection to reset. * * @return void * @throws Horde_ActiveSync_Exception */ protected function _resetDeviceState($id) { $this->_logger->info(sprintf('[%s] Resetting device state for device: %s, user: %s, and collection: %s.', $this->_procid, $this->_deviceInfo->id, $this->_deviceInfo->user, $id)); $state_query = 'DELETE FROM ' . $this->_syncStateTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $map_query = 'DELETE FROM ' . $this->_syncMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; $mailmap_query = 'DELETE FROM ' . $this->_syncMailMapTable . ' WHERE sync_devid = ? AND sync_folderid = ? AND sync_user = ?'; try { $this->_db->delete($state_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); $this->_db->delete($map_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); $this->_db->delete($mailmap_query, array($this->_deviceInfo->id, $id, $this->_deviceInfo->user)); } catch (Horde_Db_Exception $e) { throw new Horde_ActiveSync_Exception($e); } // Remove the collection data from the synccache as well. $cache = new Horde_ActiveSync_SyncCache($this, $this->_deviceInfo->id, $this->_deviceInfo->user, $this->_logger); if ($id != Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { $cache->removeCollection($id, false); } else { $this->_logger->notice(sprintf('[%s] Clearing foldersync state from synccache.', $this->_procid)); $cache->clearFolders(); $cache->clearCollections(); $cache->hierarchy = '0'; } $cache->save(); }
/** * Reset the sync state for this device, for the specified collection. * * @param string $id The collection to reset. * * @return void * @throws Horde_ActiveSync_Exception */ protected function _resetDeviceState($id) { $this->_logger->info(sprintf('[%s] Resetting device state for device: %s, user: %s, and collection: %s.', $this->_procid, $this->_deviceInfo->id, $this->_deviceInfo->user, $id)); $query = array(self::SYNC_DEVID => $this->_deviceInfo->id, self::SYNC_FOLDERID => $id, self::SYNC_USER => $this->_deviceInfo->user); try { $this->_db->selectCollection(self::COLLECTION_STATE)->remove($query); $this->_db->selectCollection(self::COLLECTION_MAP)->remove($query); $this->_db->selectCollection(self::COLLECTION_MAILMAP)->remove($query); } catch (Exception $e) { $this->_logger->err($e->getMessage()); throw new Horde_ActiveSync_Exception($e); } // Remove the collection data from the synccache as well. $cache = new Horde_ActiveSync_SyncCache($this, $this->_deviceInfo->id, $this->_deviceInfo->user, $this->_logger); if ($id != Horde_ActiveSync::REQUEST_TYPE_FOLDERSYNC) { $cache->removeCollection($id, false); } else { $this->_logger->notice(sprintf('[%s] Clearing foldersync state from synccache.', $this->_procid)); $cache->clearFolders(); $cache->clearCollections(); $cache->hierarchy = '0'; } $cache->save(); }
/** * Tests initiating a partial sync where 1 collection was passed from * client and 2 others had to be loaded from cache. */ protected function _testMissingCollections() { // Need to prime the cache with a synckey for contacts so we have // another one to load for the test. $col = array('id' => '@Contacts@', 'newsynckey' => '{517541cc-b188-478d-aaaa-fa49c0a8015f}35'); $cache = new Horde_ActiveSync_SyncCache(self::$state, 'dev123', 'mike', self::$logger->getLogger()); $cache->updateCollection($col, array('newsynckey' => true)); $cache->save(); $collections = $this->getCollectionHandler(); $col = array('id' => '519422f1-4c5c-4547-946a-1701c0a8015f', 'windowsize' => 5, 'truncation' => 0, 'mimesupport' => 0, 'mimetruncation' => 8, 'conflict' => 1, 'bodyprefs' => array('wanted' => 2, 2 => array('type' => 2, 'truncationsize' => 300000)), 'synckey' => '{517541cc-b188-478d-9e1a-fa49c0a8015f}3', 'deletesasmoves' => 1, 'filtertype' => 5); $collections->addCollection($col); $collections->initPartialSync(); $this->assertEquals(2, $collections->collectionCount()); }