Documentation

Horde_ActiveSync_State_Mongo extends Horde_ActiveSync_State_Base
in package
implements Horde_Mongo_Collection_Index

NoSQL based state management.

Collections used:

  • HAS_state: Holds sync state documents.

  • HAS_device: Holds device and device_user info.

    • _id:
    • device_type: The device's device_type.
    • device_agent: The client's user agent string.
    • device_rwstatus: The current RW status.
    • device_supported: An array of SUPPORTED properties.
    • device_properties: An array of device properties.
    • device_users: An array of each user with a known account on device with each entry containing:
      • device_user:
      • device_policykey:
  • HAS_map: Holds the incoming change (non-mail) map.

    • message_uid: The message's server uid.
    • sync_modtime: The modtime.
    • sync_key: The sync_key in effect when the change was imported.
    • sync_devid: The device_id sending the change.
    • sync_folderid: The folderid of the collection the change belongs to.
    • sync_user: The username.
    • sync_clientid: The client's clientid of incoming new items.
    • sync_deleted: Flag to indicate change was a deletion.
  • HAS_mailmap: Holds the incoming mail change map.

    • message_uid: The message's UID.
    • sync_key: The sync_key in effect when the change was imported.
    • sync_devid: The device_id sending the change.
    • sync_folderid: The folderid of the collection the change belongs to.
    • sync_user: The username.
    • sync_read: Flag to indicate change is a change in the /seen flag.
    • sync_flagged: Flag to indicate change is a change to the flagged status.
    • sync_deleted: Flag to indicate change is a message deletion.
  • HAS_cache: Holds the sync cache.

    • cache_user:
    • cache_devid:
    • cache_data: An object containing:
      • confirmed_synckeys: Array to hold synckeys for confirmation.
      • lasthbsyncstarted: Timestamp of the start of last heartbeat sync.
      • lastsyncendnormal: Timestamp of the last successfully ended sync.
      • timestamp: Timestamp of cache.
      • wait: Current wait interval.
      • hbinterval: Current heartbeat interval.
      • folders: Array of known folders.
      • hierarchy: Current hierarchy key.
      • collections:
      • pingheartbeat:
Tags
license

http://www.horde.org/licenses/gpl GPLv2

copyright

2010-2020 Horde LLC (http://www.horde.org/)

author

Michael J Rubinsky mrubinsk@horde.org

Interfaces, Classes, Traits and Enums

Horde_Mongo_Collection_Index

Table of Contents

CACHE_DATA  = 'cache_data'
CACHE_DEVID  = 'cache_devid'
CACHE_USER  = 'cache_user'
COLLECTION_CACHE  = 'HAS_cache'
Collection names *
COLLECTION_DEVICE  = 'HAS_device'
COLLECTION_MAILMAP  = 'HAS_mailmap'
COLLECTION_MAP  = 'HAS_map'
COLLECTION_STATE  = 'HAS_state'
DEVICE_AGENT  = 'device_agent'
DEVICE_ID  = 'device_id'
DEVICE_POLICYKEY  = 'device_policykey'
DEVICE_PROPERTIES  = 'device_properties'
DEVICE_RWSTATUS  = 'device_rwstatus'
DEVICE_SUPPORTED  = 'device_supported'
DEVICE_TYPE  = 'device_type'
DEVICE_USER  = 'device_user'
DEVICE_USERS  = 'device_users'
DEVICE_USERS_POLICYKEY  = 'users.device_policykey'
DEVICE_USERS_USER  = 'users.device_user'
MESSAGE_UID  = 'message_uid'
MONGO_ID  = '_id'
Field names *
SYNC_CHANGED  = 'sync_changed'
SYNC_CLIENTID  = 'sync_clientid'
SYNC_DATA  = 'sync_data'
SYNC_DELETED  = 'sync_deleted'
SYNC_DEVID  = 'sync_devid'
SYNC_FLAGGED  = 'sync_flagged'
SYNC_FOLDERID  = 'sync_folderid'
SYNC_KEY  = 'sync_key'
SYNC_MOD  = 'sync_mod'
SYNC_MODTIME  = 'sync_modtime'
SYNC_PENDING  = 'sync_pending'
SYNC_READ  = 'sync_read'
SYNC_TIMESTAMP  = 'sync_timestamp'
SYNC_USER  = 'sync_user'
$_backend  : mixed
The backend driver
$_changes  : array<string|int, mixed>
Local cache for changes to *send* to client.
$_collection  : array<string|int, mixed>
The collection array for the collection we are currently syncing.
$_db  : MongoDB
Mongo database
$_deviceInfo  : Horde_ActiveSync_Device
Device object.
$_folder  : mixed
Caches the current state(s) in memory
$_folderUidMap  : array<string|int, mixed>
A map of backend folderids to UIDs
$_indexes  : array<string|int, mixed>
Mongo Indexes
$_lastSyncStamp  : timestamp
The timestamp for the last syncKey
$_logger  : Horde_Log_Logger
Logger instance
$_mongo  : MongoClient
Mongo connection
$_params  : array<string|int, mixed>
Configuration parameters
$_procid  : int
The process id (used for logging).
$_propertyMap  : mixed
$_syncKey  : string
The syncKey for the current request.
$_thisSyncStamp  : timestamp
The current sync timestamp
$_type  : string
The type of request we are handling.
__construct()  : Horde_ActiveSync_State_Sql
Const'r
checkCollision()  : bool
Check for the (rare) possibility of a synckey collision between collections.
checkMongoIndices()  : mixed
connect()  : mixed
(Re)open backend storage connection.
createMongoIndices()  : mixed
deleteSyncCache()  : mixed
Delete a complete sync cache
deviceExists()  : int
Check that a given device id is known to the server. This is regardless of Provisioning status. If $user is provided, checks that the device is attached to the provided username.
disconnect()  : mixed
Close the underlying backend storage connection.
generatePolicyKey()  : int
Generate a random 10 digit policy key
getChangeCount()  : int
Get the number of server changes.
getChanges()  : array<string|int, mixed>
Get all items that have changed since the last sync time
getCurrentSyncKey()  : string
Get the current synckey
getDeviceRWStatus()  : int
Return a device wipe status
getFolderUidForBackendId()  : string|bool
Get a EAS Folder Uid for the given backend server id.
getFolderUidToBackendIdMap()  : array<string|int, mixed>
Return the mapping of folder uids to backend folderids.
getKnownFolders()  : array<string|int, mixed>
Return an array of known folders. This is essentially the state for a FOLDERSYNC request. AS uses a seperate synckey for FOLDERSYNC requests also, so need to treat it as any other collection.
getLastSyncTimestamp()  : int
Get the last time the loaded device issued a SYNC request.
getLatestSynckeyForCollection()  : string|int
Return the most recently seen synckey for the given collection.
getNewSyncKey()  : string
Gets the new sync key for a specified sync key. You must save the new sync state under this sync key when done sync'ing by calling setNewSyncKey(), then save().
getNewSyncKeyWrapper()  : string
Non-static wrapper for getNewSyncKey.
getPolicyKey()  : int
Obtain the current policy key, if it exists.
getSyncCache()  : array<string|int, mixed>
Return the sync cache.
getSyncKeyCounter()  : mixed
Return the counter for the specified syncKey.
getSyncKeyUid()  : string
Return the UID portion of a synckey.
isConflict()  : bool
Determines if the server version of the message represented by $stat conflicts with the client version of the message. For this driver, this is true whenever $lastSyncTime is older then $stat['mod']. Method is only called from the Importer during an import of a non-new change from the client.
isDuplicatePIMAddition()  : string
Check and see that we didn't already see the incoming change from the client.
listDevices()  : array<string|int, mixed>
List all devices that we know about.
loadDeviceInfo()  : Horde_ActiveSync_Device
Load the device object.
loadState()  : mixed
Load and initialize the sync state
removeState()  : mixed
Explicitly remove a state from storage.
resetAllPolicyKeys()  : mixed
Reset ALL device policy keys. Used when server policies have changed and you want to force ALL devices to pick up the changes. This will cause all devices that support provisioning to be reprovisioned.
RowCmp()  : unknown_type
Helper function for the _diff method
save()  : mixed
Save the current state to storage
saveSyncCache()  : mixed
Save the provided sync_cache.
setBackend()  : void
Set the backend driver (should really only be called by a backend object when passing this object to client code)
setDeviceInfo()  : mixed
Set new device info
setDeviceProperties()  : mixed
Set the device's properties as sent by a SETTINGS request.
setDeviceRWStatus()  : mixed
Set a new remotewipe status for the device
setLogger()  : mixed
Set the logger instance for this object.
setNewSyncKey()  : mixed
Update the $oldKey syncState to $newKey.
setPolicyKey()  : mixed
Save a new device policy key to storage for the current user.
updateServerIdInState()  : mixed
Update the serverid for a given folder uid in the folder's state object.
updateState()  : mixed
Update the state to reflect changes
updateSyncStamp()  : mixed
Update the syncStamp in the collection state, outside of any other changes.
_checkCollision()  : mixed
_gc()  : mixed
Garbage collector - clean up from previous sync requests.
_getCutOffDate()  : int
Returns the timestamp of the earliest modification time to consider
_getDiff()  : unknown_type
Helper function that performs the actual diff between client state and server state FOLDERSYNC arrays.
_getFolderChanges()  : mixed
Get folder changes. Populates $this->_changes with an array of change entries each containing 'type', 'id' and possibly 'flags'.
_getMailMapChanges()  : array<string|int, mixed>
Return all available mailMap changes for the current folder.
_getPIMChangeTS()  : array<string|int, mixed>
Return an array of timestamps from the map table for the last client-initiated change for the provided uid. Used to avoid mirroring back changes to the client that it sent to the server.
_havePIMChanges()  : bool
Check for the existence of ANY entries in the map table for this device and user.
_loadState()  : mixed
Load the state represented by $syncKey from storage.
_loadStateFromResults()  : mixed
Actually load the state data into the object from the query results.
_resetDeviceState()  : void
Reset the sync state for this device, for the specified collection.

Constants

CACHE_DATA

public mixed CACHE_DATA = 'cache_data'

CACHE_DEVID

public mixed CACHE_DEVID = 'cache_devid'

CACHE_USER

public mixed CACHE_USER = 'cache_user'

COLLECTION_CACHE

Collection names *

public mixed COLLECTION_CACHE = 'HAS_cache'

COLLECTION_DEVICE

public mixed COLLECTION_DEVICE = 'HAS_device'

COLLECTION_MAILMAP

public mixed COLLECTION_MAILMAP = 'HAS_mailmap'

COLLECTION_MAP

public mixed COLLECTION_MAP = 'HAS_map'

COLLECTION_STATE

public mixed COLLECTION_STATE = 'HAS_state'

DEVICE_AGENT

public mixed DEVICE_AGENT = 'device_agent'

DEVICE_ID

public mixed DEVICE_ID = 'device_id'

DEVICE_POLICYKEY

public mixed DEVICE_POLICYKEY = 'device_policykey'

DEVICE_PROPERTIES

public mixed DEVICE_PROPERTIES = 'device_properties'

DEVICE_RWSTATUS

public mixed DEVICE_RWSTATUS = 'device_rwstatus'

DEVICE_SUPPORTED

public mixed DEVICE_SUPPORTED = 'device_supported'

DEVICE_TYPE

public mixed DEVICE_TYPE = 'device_type'

DEVICE_USER

public mixed DEVICE_USER = 'device_user'

DEVICE_USERS

public mixed DEVICE_USERS = 'device_users'

DEVICE_USERS_POLICYKEY

public mixed DEVICE_USERS_POLICYKEY = 'users.device_policykey'

DEVICE_USERS_USER

public mixed DEVICE_USERS_USER = 'users.device_user'

MESSAGE_UID

public mixed MESSAGE_UID = 'message_uid'

MONGO_ID

Field names *

public mixed MONGO_ID = '_id'

SYNC_CHANGED

public mixed SYNC_CHANGED = 'sync_changed'

SYNC_CLIENTID

public mixed SYNC_CLIENTID = 'sync_clientid'

SYNC_DATA

public mixed SYNC_DATA = 'sync_data'

SYNC_DELETED

public mixed SYNC_DELETED = 'sync_deleted'

SYNC_DEVID

public mixed SYNC_DEVID = 'sync_devid'

SYNC_FLAGGED

public mixed SYNC_FLAGGED = 'sync_flagged'

SYNC_FOLDERID

public mixed SYNC_FOLDERID = 'sync_folderid'

SYNC_KEY

public mixed SYNC_KEY = 'sync_key'

SYNC_MOD

public mixed SYNC_MOD = 'sync_mod'

SYNC_MODTIME

public mixed SYNC_MODTIME = 'sync_modtime'

SYNC_PENDING

public mixed SYNC_PENDING = 'sync_pending'

SYNC_READ

public mixed SYNC_READ = 'sync_read'

SYNC_TIMESTAMP

public mixed SYNC_TIMESTAMP = 'sync_timestamp'

SYNC_USER

public mixed SYNC_USER = 'sync_user'

Properties

$_backend

The backend driver

protected mixed $_backend

$_changes

Local cache for changes to *send* to client.

protected array<string|int, mixed> $_changes

(Will remain null until getChanges() is called)

$_collection

The collection array for the collection we are currently syncing.

protected array<string|int, mixed> $_collection

Keys include:

  • class: The collection class Contacts, Calendar etc...
  • synckey: The current synckey
  • newsynckey: The new synckey sent back to the client
  • id: Server folder id
  • filtertype: Filter
  • conflict: Conflicts
  • truncation: Truncation

$_db

Mongo database

protected MongoDB $_db

$_folder

Caches the current state(s) in memory

protected mixed $_folder

Horde_ActiveSync_Folder_Base if request is not a FOLDERSYNC otherwise an array containing all FOLDERSYNC state.

$_folderUidMap

A map of backend folderids to UIDs

protected array<string|int, mixed> $_folderUidMap

$_indexes

Mongo Indexes

protected array<string|int, mixed> $_indexes = array(self::COLLECTION_DEVICE => array('index_id_user' => array(self::MONGO_ID => 1, self::DEVICE_USERS_USER => 1)), self::COLLECTION_STATE => array('index_devid_folderid' => array(self::SYNC_DEVID => 1, self::SYNC_FOLDERID => 1)), self::COLLECTION_MAP => array('index_folder_dev_uid_user' => array(self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::SYNC_FOLDERID => 1, self::MESSAGE_UID => 1), 'index_dev_user_uid_key' => array(self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::MESSAGE_UID => 1, self::SYNC_KEY => 1, self::SYNC_DELETED => 1), 'index_client_user_dev' => array(self::SYNC_CLIENTID => 1, self::SYNC_USER => 1, self::SYNC_DEVID => 1)), self::COLLECTION_MAILMAP => array('index_folder_dev_uid_user' => array(self::SYNC_DEVID => 1, self::SYNC_USER => 1, self::SYNC_FOLDERID => 1, self::MESSAGE_UID => 1)), self::COLLECTION_CACHE => array('index_dev_user' => array(self::CACHE_DEVID => 1, self::CACHE_USER => 1)))

$_lastSyncStamp

The timestamp for the last syncKey

protected timestamp $_lastSyncStamp = 0

$_logger

Logger instance

protected Horde_Log_Logger $_logger

$_mongo

Mongo connection

protected MongoClient $_mongo

$_params

Configuration parameters

protected array<string|int, mixed> $_params

$_procid

The process id (used for logging).

protected int $_procid

$_propertyMap

protected mixed $_propertyMap = array('deviceType' => self::DEVICE_TYPE, 'userAgent' => self::DEVICE_AGENT, 'rwstatus' => self::DEVICE_RWSTATUS, 'supported' => self::DEVICE_SUPPORTED, 'properties' => self::DEVICE_PROPERTIES, 'id' => self::DEVICE_ID)

$_syncKey

The syncKey for the current request.

protected string $_syncKey

$_thisSyncStamp

The current sync timestamp

protected timestamp $_thisSyncStamp = 0

$_type

The type of request we are handling.

protected string $_type

Methods

__construct()

Const'r

public __construct([array<string|int, mixed> $params = array() ]) : Horde_ActiveSync_State_Sql
Parameters
$params : array<string|int, mixed> = array()

Must contain:

  • connection: (Horde_Mongo_Client The Horde_Mongo instance.
Return values
Horde_ActiveSync_State_Sql

checkCollision()

Check for the (rare) possibility of a synckey collision between collections.

public checkCollision(string $syncKey) : bool
Parameters
$syncKey : string

The synckey to check.

Return values
bool

True if there was a collision.

checkMongoIndices()

public checkMongoIndices() : mixed
Return values
mixed

connect()

(Re)open backend storage connection.

public connect() : mixed
Return values
mixed

createMongoIndices()

public createMongoIndices() : mixed
Return values
mixed

deleteSyncCache()

Delete a complete sync cache

public deleteSyncCache(string $devid[, string $user = null ]) : mixed
Parameters
$devid : string

The device id

$user : string = null

The user name.

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

deviceExists()

Check that a given device id is known to the server. This is regardless of Provisioning status. If $user is provided, checks that the device is attached to the provided username.

public deviceExists(string $devId[, string $user = null ]) : int
Parameters
$devId : string

The device id to check.

$user : string = null

The device should be owned by this user.

Return values
int

The numer of device entries found for the give devId, user combination. I.e., 0 == no device exists.

disconnect()

Close the underlying backend storage connection.

public disconnect() : mixed

To be used during PING or looping SYNC operations.

Return values
mixed

generatePolicyKey()

Generate a random 10 digit policy key

public generatePolicyKey() : int
Return values
int

getChangeCount()

Get the number of server changes.

public getChangeCount() : int
Return values
int

getChanges()

Get all items that have changed since the last sync time

public getChanges([array<string|int, mixed> $options = array() ]) : array<string|int, mixed>
Parameters
$options : array<string|int, mixed> = array()

An options array:

  • ping: (boolean) Only detect if there is a change, do not build any messages. DEFAULT: false (Build full change array).
Tags
throws
Horde_ActiveSync_Exception_StaleState
throws
Horde_ActiveSync_Exception_FolderGone
Return values
array<string|int, mixed>

An array of hashes describing each change:

  • id: The id of the item being changed.
  • type: The type of change. a Horde_ActiveSync::CHANGE_TYPE_* constant.
  • flags: Used to transport email message flags when type is Horde_ActiveSync::CHANGE_TYPE_FLAGS or set to Horde_ActiveSync::FLAG_NEWMESSAGE when type is Horde_ActiveSync::CHANGE_TYPE_CHANGE and the message represents a new message, as opposed to a change in an existing message.
  • ignore: Set to true when the change should be ignored, and not sent to the client by the exporter. Usually due to the change being the result of a client originated change.

getCurrentSyncKey()

Get the current synckey

public getCurrentSyncKey() : string
Return values
string

The synkey we last retrieved state for

getDeviceRWStatus()

Return a device wipe status

public getDeviceRWStatus(string $devId[, bool $refresh = false ]) : int
Parameters
$devId : string
$refresh : bool = false

If true, reload the device's rwstatus flag. @since 2.31.0

Return values
int

getFolderUidForBackendId()

Get a EAS Folder Uid for the given backend server id.

public getFolderUidForBackendId(string $serverid) : string|bool
Parameters
$serverid : string

The backend server id. E.g., 'INBOX'.

Tags
since
2.4.0
deprecated

Use self::getFolderUidToBackendIdMap() instead.

Return values
string|bool

The EAS UID for the requested serverid, or false if it is not found.

getFolderUidToBackendIdMap()

Return the mapping of folder uids to backend folderids.

public getFolderUidToBackendIdMap() : array<string|int, mixed>
Tags
since
2.9.0
Return values
array<string|int, mixed>

An array of backend folderids -> uids.

getKnownFolders()

Return an array of known folders. This is essentially the state for a FOLDERSYNC request. AS uses a seperate synckey for FOLDERSYNC requests also, so need to treat it as any other collection.

public getKnownFolders() : array<string|int, mixed>
Return values
array<string|int, mixed>

An array of folder uids.

getLastSyncTimestamp()

Get the last time the loaded device issued a SYNC request.

public getLastSyncTimestamp([string $id = null ][, string $user = null ]) : int
Parameters
$id : string = null

The (optional) devivce id. If empty will use the currently loaded device.

$user : string = null

The (optional) user id. If empty wil use the currently loaded device.

Tags
throws
Horde_ActiveSync_Exception
Return values
int

The timestamp of the last sync, regardless of collection

getLatestSynckeyForCollection()

Return the most recently seen synckey for the given collection.

public getLatestSynckeyForCollection(string $collection_id) : string|int
Parameters
$collection_id : string

The activesync collection id.

Return values
string|int

The synckey or 0 if none found.

getNewSyncKey()

Gets the new sync key for a specified sync key. You must save the new sync state under this sync key when done sync'ing by calling setNewSyncKey(), then save().

public static getNewSyncKey(string $syncKey) : string
Parameters
$syncKey : string

The old syncKey

Tags
throws
Horde_ActiveSync_Exception
Return values
string

The new synckey

getNewSyncKeyWrapper()

Non-static wrapper for getNewSyncKey.

public getNewSyncKeyWrapper(string $syncKey) : string
Parameters
$syncKey : string

The old syncKey

Tags
throws
Horde_ActiveSync_Exception
todo

Remove/replace in H6 with Horde_ActiveSync_SyncKey

Return values
string

The new synckey

getPolicyKey()

Obtain the current policy key, if it exists.

public getPolicyKey(string $devId) : int
Parameters
$devId : string

The device id to obtain policy key for.

Return values
int

The current policy key for this device, or 0 if none exists.

getSyncCache()

Return the sync cache.

public getSyncCache(string $devid, string $user[, array<string|int, mixed> $fields = null ]) : array<string|int, mixed>
Parameters
$devid : string

The device id.

$user : string

The user id.

$fields : array<string|int, mixed> = null

An array of fields to return. Default is to return the full cache. @since 2.9.0

Tags
throws
Horde_ActiveSync_Exception
Return values
array<string|int, mixed>

The current sync cache for the user/device combination.

getSyncKeyCounter()

Return the counter for the specified syncKey.

public static getSyncKeyCounter(string $syncKey) : mixed
Parameters
$syncKey : string

The synckey to obtain the counter for.

Return values
mixed

integer|boolean The increment counter or false if failed.

getSyncKeyUid()

Return the UID portion of a synckey.

public static getSyncKeyUid(string $syncKey) : string
Parameters
$syncKey : string

The synckey

Return values
string

The UID.

isConflict()

Determines if the server version of the message represented by $stat conflicts with the client version of the message. For this driver, this is true whenever $lastSyncTime is older then $stat['mod']. Method is only called from the Importer during an import of a non-new change from the client.

public isConflict(array<string|int, mixed> $stat, string $type) : bool
Parameters
$stat : array<string|int, mixed>

A message stat array

$type : string

The type of change (change, delete, add)

Return values
bool

isDuplicatePIMAddition()

Check and see that we didn't already see the incoming change from the client.

public isDuplicatePIMAddition(string $id) : string

This would happen e.g., if the client failed to receive the server response after successfully importing new messages.

Parameters
$id : string

The client id sent during message addition.

Tags
throws
Horde_ActiveSync_Exception
Return values
string

The UID for the given clientid, null if none found.

listDevices()

List all devices that we know about.

public listDevices([string $user = null ][, array<string|int, mixed> $filter = array() ]) : array<string|int, mixed>
Parameters
$user : string = null

The username to list devices for. If empty, will return all devices.

$filter : array<string|int, mixed> = array()

An array of optional filters where the keys are field names and the values are values to prefix-match.

Tags
throws
Horde_ActiveSync_Exception
Return values
array<string|int, mixed>

An array of device hashes

loadDeviceInfo()

Load the device object.

public loadDeviceInfo(string $devId[, string $user = null ][, array<string|int, mixed> $params = array() ]) : Horde_ActiveSync_Device
Parameters
$devId : string

The device id to obtain

$user : string = null

The user to retrieve user-specific device info for

$params : array<string|int, mixed> = array()

Additional parameters:

  • force: (boolean) If true, reload the device info even if it's already loaded. Used to refresh values such as device_rwstatus that may have changed during a long running PING/SYNC. DEFAULT: false. @since 2.31.0
Tags
throws
Horde_ActiveSync_Exception
Return values
Horde_ActiveSync_Device

The device object

loadState()

Load and initialize the sync state

public loadState(array<string|int, mixed> $collection, string $syncKey[, string $type = null ][, string $id = null ]) : mixed
Parameters
$collection : array<string|int, mixed>

The collection array for the collection, if a FOLDERSYNC, pass an empty array.

$syncKey : string

The synckey of the state to load. If empty will force a reset of the state for the class specified in $id

$type : string = null

The type of state a Horde_ActiveSync::REQUEST_TYPE constant.

$id : string = null

The folder id this state represents. If empty assumed to be a foldersync state.

Tags
throws

Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_StateGone

Return values
mixed

removeState()

Explicitly remove a state from storage.

public removeState(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

An options array containing at least one of:

  • synckey: (string) Remove only the state associated with this synckey. DEFAULT: All synckeys are removed for the specified device.
  • devId: (string) Remove all information for this device. DEFAULT: None. If no device, a synckey is required.
  • user: (string) Restrict to removing data for this user only. DEFAULT: None - all users for the specified device are removed.
  • id: (string) When removing device state, restrict ro removing data only for this collection.
Tags
throws
Horde_ActiveSyncException
Return values
mixed

resetAllPolicyKeys()

Reset ALL device policy keys. Used when server policies have changed and you want to force ALL devices to pick up the changes. This will cause all devices that support provisioning to be reprovisioned.

public resetAllPolicyKeys() : mixed
Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

RowCmp()

Helper function for the _diff method

public static RowCmp( $a,  $b) : unknown_type
Parameters
$a :
$b :
Return values
unknown_type

saveSyncCache()

Save the provided sync_cache.

public saveSyncCache(array<string|int, mixed> $cache, string $devid, string $user[, array<string|int, mixed> $dirty = array() ]) : mixed
Parameters
$cache : array<string|int, mixed>

The cache to save.

$devid : string

The device id.

$user : string

The user id.

$dirty : array<string|int, mixed> = array()

An array of dirty properties. @since 2.9.0

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

setDeviceProperties()

Set the device's properties as sent by a SETTINGS request.

public setDeviceProperties(array<string|int, mixed> $data, string $deviceId) : mixed
Parameters
$data : array<string|int, mixed>

The device settings

$deviceId : string

The device id.

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

setDeviceRWStatus()

Set a new remotewipe status for the device

public setDeviceRWStatus(string $devId, string $status) : mixed
Parameters
$devId : string

The device id.

$status : string

A Horde_ActiveSync::RWSTATUS_* constant.

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

setLogger()

Set the logger instance for this object.

public setLogger(Horde_Log_Logger $logger) : mixed
Parameters
$logger : Horde_Log_Logger
Return values
mixed

setNewSyncKey()

Update the $oldKey syncState to $newKey.

public setNewSyncKey(string $newKey) : mixed
Parameters
$newKey : string
Return values
mixed

setPolicyKey()

Save a new device policy key to storage for the current user.

public setPolicyKey(string $devId, int $key) : mixed
Parameters
$devId : string

The device id

$key : int

The new policy key

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

updateServerIdInState()

Update the serverid for a given folder uid in the folder's state object.

public updateServerIdInState(string $uid, string $serverid) : mixed

Needed when a folder is renamed on a client, but the UID must remain the same.

Parameters
$uid : string

The folder UID.

$serverid : string

The new serverid for this uid.

Tags
throws
Horde_ActiveSync_Exception
since
2.4.0
Return values
mixed

updateState()

Update the state to reflect changes

public updateState(string $type, array<string|int, mixed> $change[, int $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA ][, string $user = null ][, string $clientid = '' ]) : mixed

Notes: If we are importing client changes, need to update the syncMapTable so we don't mirror back the changes on next sync. If we are exporting server changes, we need to track which changes have been sent (by removing them from $this->_changes) so we know which items to send on the next sync if a MOREAVAILBLE response was needed. If this is being called from a FOLDERSYNC command, update state accordingly.

Parameters
$type : string

The type of change (change, delete, flags or foldersync)

$change : array<string|int, mixed>

A stat/change hash describing the change. Contains:

  • id: (mixed) The message uid the change applies to.
  • serverid: (string) The backend server id for the folder.
  • folderuid: (string) The EAS folder UID for the folder.
  • parent: (string) The parent of the current folder, if any.
  • flags: (array) If this is a flag change, the state of the flags.
  • mod: (integer) The modtime of this change.
$origin : int = Horde_ActiveSync::CHANGE_ORIGIN_NA

Flag to indicate the origin of the change: Horde_ActiveSync::CHANGE_ORIGIN_NA - Not applicapble/not important Horde_ActiveSync::CHANGE_ORIGIN_PIM - Change originated from client

$user : string = null

The current sync user, only needed if change origin is CHANGE_ORIGIN_PIM

$clientid : string = ''

client clientid sent when adding a new message.

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

updateSyncStamp()

Update the syncStamp in the collection state, outside of any other changes.

public updateSyncStamp() : mixed

Used to prevent extremely large differences in syncStamps for clients and collections that don't often have changes.

Return values
mixed

_checkCollision()

protected _checkCollision(mixed $guid) : mixed
Parameters
$guid : mixed
Tags
todo
Return values
mixed

_gc()

Garbage collector - clean up from previous sync requests.

protected _gc(string $syncKey) : mixed
Parameters
$syncKey : string

The sync key

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

_getCutOffDate()

Returns the timestamp of the earliest modification time to consider

protected static _getCutOffDate(int $restrict) : int
Parameters
$restrict : int

The time period to restrict to

Return values
int

_getDiff()

Helper function that performs the actual diff between client state and server state FOLDERSYNC arrays.

protected _getDiff(array<string|int, mixed> $old, array<string|int, mixed> $new) : unknown_type
Parameters
$old : array<string|int, mixed>

The client state

$new : array<string|int, mixed>

The current server state

Return values
unknown_type

_getFolderChanges()

Get folder changes. Populates $this->_changes with an array of change entries each containing 'type', 'id' and possibly 'flags'.

protected _getFolderChanges() : mixed
Return values
mixed

_getMailMapChanges()

Return all available mailMap changes for the current folder.

protected _getMailMapChanges(array<string|int, mixed> $changes) : array<string|int, mixed>
Parameters
$changes : array<string|int, mixed>

The chagnes array

Return values
array<string|int, mixed>

An array of hashes, each in the form of {uid} => array( Horde_ActiveSync::CHANGE_TYPE_FLAGS => true|false, Horde_ActiveSync::CHANGE_TYPE_DELETE => true|false )

_getPIMChangeTS()

Return an array of timestamps from the map table for the last client-initiated change for the provided uid. Used to avoid mirroring back changes to the client that it sent to the server.

protected _getPIMChangeTS(array<string|int, mixed> $changes) : array<string|int, mixed>
Parameters
$changes : array<string|int, mixed>

The changes array, containing 'id' and 'type'.

Return values
array<string|int, mixed>

An array of UID -> timestamp of the last client-initiated change for the specified uid, or null if none found.

_havePIMChanges()

Check for the existence of ANY entries in the map table for this device and user.

protected _havePIMChanges() : bool

An extra database query for each sync, but the payoff is that we avoid having to stat every message change we send to the client if there are no client generated changes for this sync period.

Tags
throws
Horde_ActiveSync_Exception
Return values
bool

_loadState()

Load the state represented by $syncKey from storage.

protected _loadState() : mixed
Tags
throws

Horde_ActiveSync_Exception, Horde_ActiveSync_Exception_StateGone

Return values
mixed

_loadStateFromResults()

Actually load the state data into the object from the query results.

protected _loadStateFromResults(array<string|int, mixed> $results) : mixed
Parameters
$results : array<string|int, mixed>

The results array from the state query.

Tags
throws
Horde_ActiveSync_Exception_StateGone
Return values
mixed

_resetDeviceState()

Reset the sync state for this device, for the specified collection.

protected _resetDeviceState(string $id) : void
Parameters
$id : string

The collection to reset.

Tags
throws
Horde_ActiveSync_Exception
Return values
void

Search results