Documentation

Horde_ActiveSync_State_Base
in package

Base class for managing everything related to device state

Tags
license

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

copyright

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

author

Michael J Rubinsky mrubinsk@horde.org

Table of Contents

$_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.
$_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
$_lastSyncStamp  : timestamp
The timestamp for the last syncKey
$_logger  : Horde_Log_Logger
Logger instance
$_params  : array<string|int, mixed>
Configuration parameters
$_procid  : int
The process id (used for logging).
$_syncKey  : string
The syncKey for the current request.
$_thisSyncStamp  : timestamp
The current sync timestamp
$_type  : string
The type of request we are handling.
__construct()  : mixed
Const'r
checkCollision()  : bool
Check for the (rare) possibility of a synckey collision between collections.
connect()  : mixed
(Re)open backend storage connection.
deleteSyncCache()  : mixed
Delete a complete sync cache
deviceExists()  : bool
Check that a given device id is known to the server. This is regardless of Provisioning status.
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 currently 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
Obtain 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 syncstate 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.
updateState()  : mixed
Update the state to reflect changes
updateSyncStamp()  : mixed
Update the syncStamp in the collection state, outside of any other changes.
_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.
_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.

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

$_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

$_lastSyncStamp

The timestamp for the last syncKey

protected timestamp $_lastSyncStamp = 0

$_logger

Logger instance

protected Horde_Log_Logger $_logger

$_params

Configuration parameters

protected array<string|int, mixed> $_params

$_procid

The process id (used for logging).

protected int $_procid

$_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() ]) : mixed
Parameters
$params : array<string|int, mixed> = array()

All configuration parameters.

Return values
mixed

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.

connect()

(Re)open backend storage connection.

public abstract connect() : mixed
Return values
mixed

deleteSyncCache()

Delete a complete sync cache

public abstract deleteSyncCache(string $devid, string $user) : mixed
Parameters
$devid : string

The device id

$user : string

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.

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

The device id to check

$user : string = null

The device should be owned by this user.

Return values
bool

disconnect()

Close the underlying backend storage connection.

public abstract 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 currently loaded device issued a SYNC request.

public abstract getLastSyncTimestamp() : int
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 abstract 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 abstract 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 abstract listDevices() : array<string|int, mixed>
Tags
throws
Horde_ActiveSync_Exception
Return values
array<string|int, mixed>

An array of device hashes

loadDeviceInfo()

Obtain the device object.

public abstract loadDeviceInfo(mixed $device[, string $user = null ][, array<string|int, mixed> $params = array() ]) : Horde_ActiveSync_Device
Parameters
$device : mixed
$user : string = null
$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
Return values
Horde_ActiveSync_Device

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 abstract removeState(array<string|int, mixed> $options) : mixed
Parameters
$options : array<string|int, mixed>

An options array containing:

  • synckey: (string) Remove only the state associated with this synckey.
  • devId: (string) Remove all information for this device.
  • user: (string) When removing device info, restrict to removing data for this user only.
  • 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 abstract 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

save()

Save the current syncstate to storage

public abstract save() : mixed
Return values
mixed

saveSyncCache()

Save the provided sync_cache.

public abstract 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 userid.

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

An array of dirty properties. @since 2.9.0

Tags
throws
Horde_ActiveSync_Exception
Return values
mixed

setDeviceInfo()

Set new device info

public abstract setDeviceInfo(object $data[, array<string|int, mixed> $dirty = array() ]) : mixed
Parameters
$data : object

The device information

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

Array of dirty properties. @since 2.9.0

Return values
mixed

setDeviceProperties()

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

public abstract 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 abstract 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.

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

The device id

$key : int

The new policy key

Return values
mixed

updateState()

Update the state to reflect changes

public abstract updateState(string $type, array<string|int, mixed> $change[, int $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA ][, string $user = null ][, string $clientid = '' ]) : mixed
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: The message uid the change applies to
  • parent: The parent of the message, normally the folder id.
  • flags: If this is a flag change, the state of the read flag.
  • mod: The modtime of this change for collections that use it.
$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

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

_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 )

_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

Search results