PHP Class Horde_SyncMl_Backend_Horde, horde

Copyright 2005-2016 Horde LLC (http://www.horde.org/) See the enclosed file COPYING for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Author: Karsten Fourmont ([email protected])
Inheritance: extends Horde_SyncMl_Backend
Show file Open project: horde/horde

Protected Properties

Property Type Description
$_db Horde_Db_Adapter_Base A database instance.
$_sessionId string The session ID used in the Horde session.

Public Methods

Method Description
__construct ( array $params ) Constructor.
addEntry ( string $databaseURI, string $content, string $contentType, string $cuid = null ) : array Adds an entry into the server database.
close ( )
createUidMap ( string $databaseURI, string $cuid, string $suid, integer $timestamp ) Creates a map entry to map between server and client IDs.
deleteEntry ( string $databaseURI, string $cuid ) : boolean Deletes an entry from the server database.
eraseMap ( string $databaseURI ) Erases all mapping entries for one combination of user, device ID.
getServerChanges ( string $databaseURI, integer $from_ts, integer $to_ts, &$adds, &$mods, &$dels ) : boolean Returns entries that have been modified in the server database.
getUserAnchors ( string $user ) : array Returns all previously written sync anchors for a user.
logMessage ( mixed $message, string $priority = 'INFO' ) Logs a message in the backend.
readSyncAnchors ( string $databaseURI ) : mixed Reads the previously written sync anchors from the database.
removeAnchor ( string $user, string $device = null, string $database = null ) : array Deletes previously written sync anchors for a user.
removeMaps ( string $user, string $device = null, string $database = null ) : array Deletes previously written sync maps for a user.
replaceEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : string Replaces an entry in the server database.
retrieveEntry ( string $databaseURI, string $suid, string $contentType, array $fields ) : mixed Retrieves an entry from the backend.
sessionStart ( string $syncDeviceID, $sessionId, integer $backendMode = Horde_SyncMl_Backend::MODE_SERVER ) Starts a PHP session.
setUser ( string $user ) Sets the user used for this session.
testSetup ( string $user, string $pwd ) Creates a clean test environment in the backend.
testStart ( string $user ) Prepares the test start.
testTearDown ( ) Tears down the test environment after the test is run.
writeSyncAnchors ( string $databaseURI, string $clientAnchorNext, string $serverAnchorNext ) Stores Sync anchors after a successful synchronization to allow two-way synchronization next time.

Protected Methods

Method Description
_checkAuthentication ( string $username, string $password ) : boolean | string Authenticates the user at the backend.
_fastsync ( $databaseURI, $from_ts, $to_ts )
_getChangeTS ( string $databaseURI, string $suid ) : mixed Returns a timestamp stored in the map for a given Server ID.
_getCuid ( string $databaseURI, string $suid ) : mixed Retrieves the Client ID for a given Server ID from the map.
_getSuid ( string $databaseURI, string $cuid ) : mixed Retrieves the Server ID for a given Client ID from the map.
_setAuthenticated ( string $username, string $credData ) : string Sets a user as being authenticated at the backend.
_slowsync ( $databaseURI, $from_ts, $to_ts )

Method Details

__construct() public method

Initializes the logger.
public __construct ( array $params )
$params array Any parameters the backend might need.

_checkAuthentication() protected method

Authenticates the user at the backend.
protected _checkAuthentication ( string $username, string $password ) : boolean | string
$username string A user name.
$password string A password.
return boolean | string The user name if authentication succeeded, false otherwise.

_fastsync() protected method

protected _fastsync ( $databaseURI, $from_ts, $to_ts )

_getChangeTS() protected method

The timestamp is the timestamp of the last change to this server ID that was done inside a sync session (as a result of a change received by the server). It's important to distinguish changes in the backend a) made by the user during normal operation and b) changes made by SyncML to reflect client updates. When the server is sending its changes it is only allowed to send type a). However the history feature in the backend my not know if a change is of type a) or type b). So the timestamp is used to differentiate between the two.
protected _getChangeTS ( string $databaseURI, string $suid ) : mixed
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$suid string The server ID.
return mixed The previously stored timestamp or false if no entry is found.

_getCuid() protected method

Retrieves the Client ID for a given Server ID from the map.
protected _getCuid ( string $databaseURI, string $suid ) : mixed
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$suid string The server ID.
return mixed The client ID string or false if no entry is found.

_getSuid() protected method

Retrieves the Server ID for a given Client ID from the map.
protected _getSuid ( string $databaseURI, string $cuid ) : mixed
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$cuid string The client ID.
return mixed The server ID string or false if no entry is found.

_setAuthenticated() protected method

Sets a user as being authenticated at the backend.
protected _setAuthenticated ( string $username, string $credData ) : string
$username string A user name.
$credData string Authentication data provided by in the .
return string The user name.

_slowsync() protected method

protected _slowsync ( $databaseURI, $from_ts, $to_ts )

addEntry() public method

Adds an entry into the server database.
public addEntry ( string $databaseURI, string $content, string $contentType, string $cuid = null ) : array
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$content string The actual data.
$contentType string MIME type of the content.
$cuid string Client ID of this entry.
return array PEAR_Error or suid (Horde guid) of new entry

close() public method

public close ( )

createUidMap() public method

If an entry already exists, it is overwritten.
public createUidMap ( string $databaseURI, string $cuid, string $suid, integer $timestamp )
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$cuid string Client ID of the entry.
$suid string Server ID of the entry.
$timestamp integer Optional timestamp. This can be used to 'tag' changes made in the backend during the sync process. This allows to identify these, and ensure that these changes are not replicated back to the client (and thus duplicated). See key concept "Changes and timestamps".

deleteEntry() public method

Deletes an entry from the server database.
public deleteEntry ( string $databaseURI, string $cuid ) : boolean
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$cuid string Client ID of the entry.
return boolean True on success or false on failed (item not found).

eraseMap() public method

This is used during SlowSync so that we really sync everything properly and no old mapping entries remain.
public eraseMap ( string $databaseURI )
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.

getServerChanges() public method

Returns entries that have been modified in the server database.
public getServerChanges ( string $databaseURI, integer $from_ts, integer $to_ts, &$adds, &$mods, &$dels ) : boolean
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$from_ts integer Start timestamp.
$to_ts integer Exclusive end timestamp. Not yet implemented.
return boolean true

getUserAnchors() public method

Returns all previously written sync anchors for a user.
public getUserAnchors ( string $user ) : array
$user string A user name.
return array A hash tree with all devices, databases and sync anchors from the specified user.

logMessage() public method

Logs a message in the backend.
public logMessage ( mixed $message, string $priority = 'INFO' )
$message mixed Either a string or a PEAR_Error object.
$priority string The priority of the message. One of: - EMERG - ALERT - CRIT - ERR - WARN - NOTICE - INFO - DEBUG

readSyncAnchors() public method

Reads the previously written sync anchors from the database.
public readSyncAnchors ( string $databaseURI ) : mixed
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
return mixed Two-element array with client anchor and server anchor as stored in previous writeSyncAnchor() calls. False if no data found.

removeAnchor() public method

If no device or database are specified, anchors for all devices and/or databases will be deleted.
public removeAnchor ( string $user, string $device = null, string $database = null ) : array
$user string A user name.
$device string The ID of the client device.
$database string Normalized URI of database to delete. Like calendar, tasks, contacts or notes.
return array

removeMaps() public method

If no device or database are specified, maps for all devices and/or databases will be deleted.
public removeMaps ( string $user, string $device = null, string $database = null ) : array
$user string A user name.
$device string The ID of the client device.
$database string Normalized URI of database to delete. Like calendar, tasks, contacts or notes.
return array

replaceEntry() public method

Replaces an entry in the server database.
public replaceEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : string
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$content string The actual data.
$contentType string MIME type of the content.
$cuid string Client ID of this entry.
return string PEAR_Error or server ID (Horde GUID) of modified entry.

retrieveEntry() public method

Retrieves an entry from the backend.
public retrieveEntry ( string $databaseURI, string $suid, string $contentType, array $fields ) : mixed
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$suid string Server unique id of the entry: for horde this is the guid.
$contentType string Content-Type: the MIME type in which the public function should return the data.
$fields array Hash of field names and Horde_SyncMl_Property properties with the requested fields.
return mixed A string with the data entry or a PEAR_Error object.

sessionStart() public method

Starts a PHP session.
public sessionStart ( string $syncDeviceID, $sessionId, integer $backendMode = Horde_SyncMl_Backend::MODE_SERVER )
$syncDeviceID string The device ID.
$backendMode integer The backend mode, one of the Horde_SyncMl_Backend::MODE_* constants.

setUser() public method

Sets the user used for this session.
public setUser ( string $user )
$user string A user name.

testSetup() public method

Ensures there's a user with the given credentials and an empty data store.
public testSetup ( string $user, string $pwd )
$user string This user accout has to be created in the backend.
$pwd string The password for user $user.

testStart() public method

Prepares the test start.
public testStart ( string $user )
$user string This user accout has to be created in the backend.

testTearDown() public method

Should remove the testuser created during testSetup and all its data.
public testTearDown ( )

writeSyncAnchors() public method

The backend has to store the parameters in its persistence engine where user, syncDeviceID and database are the keys while client and server anchor ar the payload. See readSyncAnchors() for retrieval.
public writeSyncAnchors ( string $databaseURI, string $clientAnchorNext, string $serverAnchorNext )
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$clientAnchorNext string The client anchor as sent by the client.
$serverAnchorNext string The anchor as used internally by the server.

Property Details

$_db protected property

A database instance.
protected Horde_Db_Adapter_Base $_db
return Horde_Db_Adapter_Base

$_sessionId protected property

The session ID used in the Horde session.
protected string $_sessionId
return string