PHP Class Horde_ActiveSync_State_Base, horde

Author: Michael J Rubinsky ([email protected])
显示文件 Open project: horde/horde Class Usage Examples

Protected Properties

Property Type Description
$_backend The backend driver
$_changes array (Will remain null until getChanges() is called)
$_collection array 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
$_deviceInfo Horde_ActiveSync_Device Device object.
$_folder Caches the current state(s) in memory
$_folderUidMap array A map of backend folderids to UIDs
$_lastSyncStamp timestamp The timestamp for the last syncKey
$_logger Horde_Log_Logger Logger instance
$_params array Configuration parameters
$_procid integer 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.

Public Methods

Method Description
RowCmp ( $a, $b ) : unknown_type Helper function for the _diff method
__construct ( array $params = [] ) Const'r
checkCollision ( string $syncKey ) : boolean Check for the (rare) possibility of a synckey collision between collections.
connect ( ) (Re)open backend storage connection.
deleteSyncCache ( string $devid, string $user ) Delete a complete sync cache
deviceExists ( string $devId, string $user = null ) : boolean Check that a given device id is known to the server. This is regardless of Provisioning status.
disconnect ( ) Close the underlying backend storage connection.
generatePolicyKey ( ) : integer Generate a random 10 digit policy key
getChangeCount ( ) : integer Get the number of server changes.
getChanges ( array $options = [] ) : array Get all items that have changed since the last sync time
getCurrentSyncKey ( ) : string Get the current synckey
getDeviceRWStatus ( string $devId, boolean $refresh = false ) : integer Return a device wipe status
getFolderUidForBackendId ( string $serverid ) : string | boolean Get a EAS Folder Uid for the given backend server id.
getFolderUidToBackendIdMap ( ) : array Return the mapping of folder uids to backend folderids.
getKnownFolders ( ) : array 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 ( ) : integer Get the last time the currently loaded device issued a SYNC request.
getLatestSynckeyForCollection ( string $collection_id ) : string | integer Return the most recently seen synckey for the given collection.
getNewSyncKey ( string $syncKey ) : 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 $syncKey ) : string Non-static wrapper for getNewSyncKey.
getPolicyKey ( string $devId ) : integer Obtain the current policy key, if it exists.
getSyncCache ( string $devid, string $user, array $fields = null ) : array Return the sync cache.
getSyncKeyCounter ( string $syncKey ) : mixed Return the counter for the specified syncKey.
getSyncKeyUid ( string $syncKey ) : string Return the UID portion of a synckey.
isConflict ( array $stat, string $type ) : boolean 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 $id ) : string Check and see that we didn't already see the incoming change from the client.
listDevices ( ) : array List all devices that we know about.
loadDeviceInfo ( $device, string $user = null, array $params = [] ) : Horde_ActiveSync_Device Obtain the device object.
loadState ( array $collection, string $syncKey, string $type = null, string $id = null ) Load and initialize the sync state
removeState ( array $options ) Explicitly remove a state from storage.
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.
save ( ) Save the current syncstate to storage
saveSyncCache ( array $cache, string $devid, string $user, array $dirty = [] ) Save the provided sync_cache.
setBackend ( Horde_ActiveSync_Driver_Base $backend ) : void Set the backend driver (should really only be called by a backend object when passing this object to client code)
setDeviceInfo ( Horde_ActiveSync_Device $data, array $dirty = [] ) Set new device info
setDeviceProperties ( array $data, string $deviceId ) Set the device's properties as sent by a SETTINGS request.
setDeviceRWStatus ( string $devId, string $status ) Set a new remotewipe status for the device
setLogger ( Horde_Log_Logger $logger ) Set the logger instance for this object.
setNewSyncKey ( string $newKey ) Update the $oldKey syncState to $newKey.
setPolicyKey ( string $devId, integer $key ) Save a new device policy key to storage.
updateState ( string $type, array $change, integer $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, string $user = null, string $clientid = '' ) Update the state to reflect changes
updateSyncStamp ( ) Update the syncStamp in the collection state, outside of any other changes.

Protected Methods

Method Description
_getCutOffDate ( integer $restrict ) : integer Returns the timestamp of the earliest modification time to consider
_getDiff ( array $old, array $new ) : unknown_type Helper function that performs the actual diff between client state and server state FOLDERSYNC arrays.
_getFolderChanges ( ) Get folder changes. Populates $this->_changes with an array of change entries each containing 'type', 'id' and possibly 'flags'.
_getMailMapChanges ( array $changes ) : array Return all available mailMap changes for the current folder.
_havePIMChanges ( ) : boolean Check for the existence of ANY entries in the map table for this device and user.
_loadState ( ) Load the state represented by $syncKey from storage.

Method Details

RowCmp() public static method

Helper function for the _diff method
public static RowCmp ( $a, $b ) : unknown_type
$a
$b
return unknown_type

__construct() public method

Const'r
public __construct ( array $params = [] )
$params array All configuration parameters.

_getCutOffDate() protected static method

Returns the timestamp of the earliest modification time to consider
protected static _getCutOffDate ( integer $restrict ) : integer
$restrict integer The time period to restrict to
return integer

_getDiff() protected method

Helper function that performs the actual diff between client state and server state FOLDERSYNC arrays.
protected _getDiff ( array $old, array $new ) : unknown_type
$old array The client state
$new array The current server state
return unknown_type

_getFolderChanges() protected method

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

_getMailMapChanges() protected method

Return all available mailMap changes for the current folder.
protected _getMailMapChanges ( array $changes ) : array
$changes array The chagnes array
return array 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() protected method

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.
protected _havePIMChanges ( ) : boolean
return boolean

_loadState() protected method

Load the state represented by $syncKey from storage.
protected _loadState ( )

checkCollision() public method

Check for the (rare) possibility of a synckey collision between collections.
public checkCollision ( string $syncKey ) : boolean
$syncKey string The synckey to check.
return boolean True if there was a collision.

connect() abstract public method

(Re)open backend storage connection.
abstract public connect ( )

deleteSyncCache() abstract public method

Delete a complete sync cache
abstract public deleteSyncCache ( string $devid, string $user )
$devid string The device id
$user string The user name.

deviceExists() abstract public method

Check that a given device id is known to the server. This is regardless of Provisioning status.
abstract public deviceExists ( string $devId, string $user = null ) : boolean
$devId string The device id to check
$user string The device should be owned by this user.
return boolean

disconnect() abstract public method

To be used during PING or looping SYNC operations.
abstract public disconnect ( )

generatePolicyKey() public method

Generate a random 10 digit policy key
public generatePolicyKey ( ) : integer
return integer

getChangeCount() public method

Get the number of server changes.
public getChangeCount ( ) : integer
return integer

getChanges() public method

Get all items that have changed since the last sync time
public getChanges ( array $options = [] ) : array
$options array An options array: - ping: (boolean) Only detect if there is a change, do not build any messages. DEFAULT: false (Build full change array).
return array 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() public method

Get the current synckey
public getCurrentSyncKey ( ) : string
return string The synkey we last retrieved state for

getDeviceRWStatus() public method

Return a device wipe status
public getDeviceRWStatus ( string $devId, boolean $refresh = false ) : integer
$devId string
$refresh boolean If true, reload the device's rwstatus flag. @since 2.31.0
return integer

getFolderUidForBackendId() public method

Get a EAS Folder Uid for the given backend server id.
Deprecation: Use self::getFolderUidToBackendIdMap() instead.
Since: 2.4.0
public getFolderUidForBackendId ( string $serverid ) : string | boolean
$serverid string The backend server id. E.g., 'INBOX'.
return string | boolean The EAS UID for the requested serverid, or false if it is not found.

getFolderUidToBackendIdMap() public method

Return the mapping of folder uids to backend folderids.
Since: 2.9.0
public getFolderUidToBackendIdMap ( ) : array
return array An array of backend folderids -> uids.

getKnownFolders() public method

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
return array An array of folder uids.

getLastSyncTimestamp() abstract public method

Get the last time the currently loaded device issued a SYNC request.
abstract public getLastSyncTimestamp ( ) : integer
return integer The timestamp of the last sync, regardless of collection

getLatestSynckeyForCollection() public method

Return the most recently seen synckey for the given collection.
public getLatestSynckeyForCollection ( string $collection_id ) : string | integer
$collection_id string The activesync collection id.
return string | integer The synckey or 0 if none found.

getNewSyncKey() public static method

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
$syncKey string The old syncKey
return string The new synckey

getNewSyncKeyWrapper() public method

Non-static wrapper for getNewSyncKey.
public getNewSyncKeyWrapper ( string $syncKey ) : string
$syncKey string The old syncKey
return string The new synckey

getPolicyKey() public method

Obtain the current policy key, if it exists.
public getPolicyKey ( string $devId ) : integer
$devId string The device id to obtain policy key for.
return integer The current policy key for this device, or 0 if none exists.

getSyncCache() abstract public method

Return the sync cache.
abstract public getSyncCache ( string $devid, string $user, array $fields = null ) : array
$devid string The device id.
$user string The user id.
$fields array An array of fields to return. Default is to return the full cache. @since 2.9.0
return array The current sync cache for the user/device combination.

getSyncKeyCounter() public static method

Return the counter for the specified syncKey.
public static getSyncKeyCounter ( string $syncKey ) : mixed
$syncKey string The synckey to obtain the counter for.
return mixed integer|boolean The increment counter or false if failed.

getSyncKeyUid() public static method

Return the UID portion of a synckey.
public static getSyncKeyUid ( string $syncKey ) : string
$syncKey string The synckey
return string The UID.

isConflict() public method

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 $stat, string $type ) : boolean
$stat array A message stat array
$type string The type of change (change, delete, add)
return boolean

isDuplicatePIMAddition() abstract public method

This would happen e.g., if the client failed to receive the server response after successfully importing new messages.
abstract public isDuplicatePIMAddition ( string $id ) : string
$id string The client id sent during message addition.
return string The UID for the given clientid, null if none found.

listDevices() abstract public method

List all devices that we know about.
abstract public listDevices ( ) : array
return array An array of device hashes

loadDeviceInfo() abstract public method

Obtain the device object.
abstract public loadDeviceInfo ( $device, string $user = null, array $params = [] ) : Horde_ActiveSync_Device
$user string
$params 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 Horde_ActiveSync_Device

loadState() public method

Load and initialize the sync state
public loadState ( array $collection, string $syncKey, string $type = null, string $id = null )
$collection array 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 The type of state a Horde_ActiveSync::REQUEST_TYPE constant.
$id string The folder id this state represents. If empty assumed to be a foldersync state.

removeState() abstract public method

Explicitly remove a state from storage.
abstract public removeState ( array $options )
$options array 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.

resetAllPolicyKeys() abstract public method

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.
abstract public resetAllPolicyKeys ( )

save() abstract public method

Save the current syncstate to storage
abstract public save ( )

saveSyncCache() abstract public method

Save the provided sync_cache.
abstract public saveSyncCache ( array $cache, string $devid, string $user, array $dirty = [] )
$cache array The cache to save.
$devid string The device id.
$user string The userid.
$dirty array An array of dirty properties. @since 2.9.0

setBackend() public method

Set the backend driver (should really only be called by a backend object when passing this object to client code)
public setBackend ( Horde_ActiveSync_Driver_Base $backend ) : void
$backend Horde_ActiveSync_Driver_Base The backend driver
return void

setDeviceInfo() abstract public method

Set new device info
abstract public setDeviceInfo ( Horde_ActiveSync_Device $data, array $dirty = [] )
$data Horde_ActiveSync_Device The device information
$dirty array Array of dirty properties. @since 2.9.0

setDeviceProperties() abstract public method

Set the device's properties as sent by a SETTINGS request.
abstract public setDeviceProperties ( array $data, string $deviceId )
$data array The device settings
$deviceId string The device id.

setDeviceRWStatus() abstract public method

Set a new remotewipe status for the device
abstract public setDeviceRWStatus ( string $devId, string $status )
$devId string The device id.
$status string A Horde_ActiveSync::RWSTATUS_* constant.

setLogger() public method

Set the logger instance for this object.
public setLogger ( Horde_Log_Logger $logger )
$logger Horde_Log_Logger

setNewSyncKey() public method

Update the $oldKey syncState to $newKey.
public setNewSyncKey ( string $newKey )
$newKey string

setPolicyKey() abstract public method

Save a new device policy key to storage.
abstract public setPolicyKey ( string $devId, integer $key )
$devId string The device id
$key integer The new policy key

updateState() abstract public method

Update the state to reflect changes
abstract public updateState ( string $type, array $change, integer $origin = Horde_ActiveSync::CHANGE_ORIGIN_NA, string $user = null, string $clientid = '' )
$type string The type of change (change, delete, flags or foldersync)
$change array 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 integer 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 The current sync user, only needed if change origin is CHANGE_ORIGIN_PIM
$clientid string client clientid sent when adding a new message

updateSyncStamp() public method

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

Property Details

$_backend protected_oe property

The backend driver
protected $_backend

$_changes protected_oe property

(Will remain null until getChanges() is called)
protected array $_changes
return array

$_collection protected_oe property

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
protected array $_collection
return array

$_deviceInfo protected_oe property

Device object.
protected Horde_ActiveSync_Device $_deviceInfo
return Horde_ActiveSync_Device

$_folder protected_oe property

Caches the current state(s) in memory
protected $_folder

$_folderUidMap protected_oe property

A map of backend folderids to UIDs
protected array $_folderUidMap
return array

$_lastSyncStamp protected_oe property

The timestamp for the last syncKey
protected timestamp $_lastSyncStamp
return timestamp

$_logger protected_oe property

Logger instance
protected Horde_Log_Logger $_logger
return Horde_Log_Logger

$_params protected_oe property

Configuration parameters
protected array $_params
return array

$_procid protected_oe property

The process id (used for logging).
protected int $_procid
return integer

$_syncKey protected_oe property

The syncKey for the current request.
protected string $_syncKey
return string

$_thisSyncStamp protected_oe property

The current sync timestamp
protected timestamp $_thisSyncStamp
return timestamp

$_type protected_oe property

The type of request we are handling.
protected string $_type
return string