PHP Class Horde_SyncMl_Backend_Sql, horde

Inheritance: extends Horde_SyncMl_Backend
Afficher le fichier Open project: horde/horde

Protected Properties

Свойство Type Description
$_db MDB2 A PEAR MDB2 instance.

Méthodes publiques

Méthode Description
__construct ( array $params ) Constructor.
addEntry ( string $databaseURI, string $content, string $contentType, string $cuid = null ) : array Adds an entry into the server database.
addEntry_backend ( string $user, string $databaseURI, string $content, string $contentType ) : array Adds an entry into the server database.
close ( ) Cleanup public function called after all message processing is finished.
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.
deleteEntry_backend ( string $user, string $databaseURI, string $suid ) : 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 ) : mixed Returns entries that have been modified in the server database.
isValidDatabaseURI ( string $databaseURI ) : boolean Returns whether a database URI is valid to be synced with this backend.
readSyncAnchors ( string $databaseURI ) : mixed Reads the previously written sync anchors from the database.
replaceEntry ( string $databaseURI, string $content, string $contentType, string $cuid ) : string Replaces an entry in the server database.
replaceEntry_backend ( string $user, string $databaseURI, string $content, string $contentType, string $suid ) : string Replaces an entry in the server database.
retrieveEntry ( string $databaseURI, string $suid, string $contentType, array $fields ) : mixed Retrieves an entry from the backend.
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.

Méthodes protégées

Méthode Description
_checkAuthentication ( string $username, string $password ) : boolean | string Authenticates the user at the backend.
_checkForError ( mixed $o ) : mixed Checks if the parameter is a PEAR_Error object and if so logs the error.
_cleanUser ( $user )
_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.
_removeFromSuidList ( string $databaseURI, array $suid ) Removes a suid from the suidlist.
_setAuthenticated ( string $username, string $credData ) : string Sets a user as being authenticated at the backend.
_trackDeletes ( string $databaseURI, array $currentSuids ) : array Returns a list of item IDs that have been deleted since the last sync run and stores a complete list of IDs for next sync run.

Method Details

__construct() public méthode

Constructor.
public __construct ( array $params )
$params array A hash with parameters. In addition to those supported by the Horde_SyncMl_Backend class one more parameter is required for the database connection: 'dsn' => connection DSN.

_checkAuthentication() protected méthode

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

_checkForError() protected méthode

Checks if the parameter is a PEAR_Error object and if so logs the error.
protected _checkForError ( mixed $o ) : mixed
$o mixed An object or value to check.
Résultat mixed The error object if an error has been passed or false if no error has been passed.

_cleanUser() protected méthode

protected _cleanUser ( $user )

_getChangeTS() protected méthode

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.
Résultat mixed The previously stored timestamp or false if no entry is found.

_getCuid() protected méthode

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.
Résultat mixed The client ID string or false if no entry is found.

_getSuid() protected méthode

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.
Résultat mixed The server ID string or false if no entry is found.

_removeFromSuidList() protected méthode

Called by _trackDeletes() when updating the suidlist and deleteEntry() when removing an entry due to a client request.
protected _removeFromSuidList ( string $databaseURI, array $suid )
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$suid array The suid to remove from the list.

_setAuthenticated() protected méthode

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 .
Résultat string The user name.

_trackDeletes() protected méthode

Some backend datastores don't keep information about deleted entries. So we have to create a workaround that finds out what entries have been deleted since the last sync run. This method provides this functionality: it is called with a list of all IDs currently in the database. It then compares this list with its own previously stored list of IDs to identify those missing (and thus deleted). The passed list is then stored for the next invocation.
protected _trackDeletes ( string $databaseURI, array $currentSuids ) : array
$databaseURI string URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$currentSuids array Array of all SUIDs (primary keys) currently in the server datastore.
Résultat array Array of all entries that have been deleted since the last call.

addEntry() public méthode

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.
Résultat array PEAR_Error or suid (Horde guid) of new entry

addEntry_backend() public méthode

Adds an entry into the server database.
public addEntry_backend ( string $user, string $databaseURI, string $content, string $contentType ) : array
$user string The username to use. Not strictly necessery to store this, but it helps for the test environment to clean up all entries for a test user.
$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.
Résultat array PEAR_Error or suid of new entry.

close() public méthode

Allows for things like closing databases or flushing logs. When running in test mode, tearDown() must be called rather than close.
public close ( )

createUidMap() public méthode

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 méthode

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.
Résultat boolean True on success or false on failed (item not found).

deleteEntry_backend() public méthode

Deletes an entry from the server database.
public deleteEntry_backend ( string $user, string $databaseURI, string $suid ) : boolean
$user string The username to use. Not strictly necessery to store this, but it helps for the test environment to clean up all entries for a test user.
$databaseURI string URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
$suid string Server ID of the entry.
Résultat boolean True on success or false on failed (item not found).

eraseMap() public méthode

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 méthode

Returns entries that have been modified in the server database.
public getServerChanges ( string $databaseURI, integer $from_ts, integer $to_ts, &$adds, &$mods, &$dels ) : mixed
$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.
Résultat mixed True on success or a PEAR_Error object.

isValidDatabaseURI() public méthode

Returns whether a database URI is valid to be synced with this backend.
public isValidDatabaseURI ( string $databaseURI ) : boolean
$databaseURI string URI of a database. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
Résultat boolean True if a valid URI.

readSyncAnchors() public méthode

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.
Résultat mixed Two-element array with client anchor and server anchor as stored in previous writeSyncAnchor() calls. False if no data found.

replaceEntry() public méthode

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.
Résultat string PEAR_Error or server ID (Horde GUID) of modified entry.

replaceEntry_backend() public méthode

Replaces an entry in the server database.
public replaceEntry_backend ( string $user, string $databaseURI, string $content, string $contentType, string $suid ) : string
$user string The username to use. Not strictly necessery to store this but, it helps for the test environment to clean up all entries for a test user.
$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.
$suid string Server ID of this entry.
Résultat string PEAR_Error or suid of modified entry.

retrieveEntry() public méthode

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.
Résultat mixed A string with the data entry or a PEAR_Error object.

testSetup() public méthode

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 méthode

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

testTearDown() public méthode

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

writeSyncAnchors() public méthode

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_oe property

A PEAR MDB2 instance.
protected MDB2 $_db
Résultat MDB2