Constructor.
SyncML_Backend_Sql
SyncML_Backend_Sql
(array $params)
-
array
$params: A hash with parameters. In addition to those supported by the SyncML_Backend class one more parameter is required for the database connection: 'dsn' => connection DSN.
Adds an entry into the server database.
array
addEntry
(string $databaseURI, string $content, string $contentType, [string $cuid = null])
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$content: The actual data.
-
string
$contentType: MIME type of the content.
-
string
$cuid: Client ID of this entry.
Redefinition of:
- SyncML_Backend::addEntry()
- Adds an entry into the server database.
Adds an entry into the server database.
array
addEntry_backend
(string $user, string $databaseURI, string $content, string $contentType)
-
string
$user: 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.
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$content: The actual data.
-
string
$contentType: MIME type of the content.
Cleanup function called after all message processing is finished.
Allows for things like closing databases or flushing logs. When running in test mode, tearDown() must be called rather than close.
void
close
()
Redefinition of:
- SyncML_Backend::close()
- Cleanup function called after all message processing is finished.
Creates a map entry to map between server and client IDs.
If an entry already exists, it is overwritten.
void
createUidMap
(string $databaseURI, string $cuid, string $suid, [integer $timestamp = 0])
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$cuid: Client ID of the entry.
-
string
$suid: Server ID of the entry.
-
integer
$timestamp: 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".
Redefinition of:
- SyncML_Backend::createUidMap()
- Creates a map entry to map between server and client IDs.
Deletes an entry from the server database.
boolean
deleteEntry
(string $databaseURI, string $cuid)
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$cuid: Client ID of the entry.
Redefinition of:
- SyncML_Backend::deleteEntry()
- Deletes an entry from the server database.
Deletes an entry from the server database.
boolean
deleteEntry_backend
(string $user, string $databaseURI, string $suid)
-
string
$user: 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.
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$suid: Server ID of the entry.
Erases all mapping entries for one combination of user, device ID.
This is used during SlowSync so that we really sync everything properly and no old mapping entries remain.
void
eraseMap
(string $databaseURI)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
Redefinition of:
- SyncML_Backend::eraseMap()
- Erases all mapping entries for one combination of user, device ID.
Returns entries that have been modified in the server database.
mixed
getServerChanges
(string $databaseURI, integer $from_ts, integer $to_ts, array &$adds, array &$mods, array &$dels)
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
integer
$from_ts: Start timestamp.
-
integer
$to_ts: Exclusive end timestamp. Not yet implemented.
-
array
&$adds: Output array: hash of adds suid => 0
-
array
&$mods: Output array: hash of modifications suid => cuid
-
array
&$dels: Output array: hash of deletions suid => cuid
Redefinition of:
- SyncML_Backend::getServerChanges()
- Returns entries that have been modified in the server database.
Returns whether a database URI is valid to be synced with this backend.
boolean
isValidDatabaseURI
(string $databaseURI)
-
string
$databaseURI: URI of a database. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
Redefinition of:
- SyncML_Backend::isValidDatabaseURI()
- Returns whether a database URI is valid to be synced with this backend.
Reads the previously written sync anchors from the database.
mixed
readSyncAnchors
(string $databaseURI)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
Redefinition of:
- SyncML_Backend::readSyncAnchors()
- Reads the previously written sync anchors from the database.
Replaces an entry in the server database.
string
replaceEntry
(string $databaseURI, string $content, string $contentType, string $cuid)
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$content: The actual data.
-
string
$contentType: MIME type of the content.
-
string
$cuid: Client ID of this entry.
Redefinition of:
- SyncML_Backend::replaceEntry()
- Replaces an entry in the server database.
Replaces an entry in the server database.
string
replaceEntry_backend
(string $user, string $databaseURI, string $content, string $contentType, string $suid)
-
string
$user: 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.
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$content: The actual data.
-
string
$contentType: MIME type of the content.
-
string
$suid: Server ID of this entry.
Retrieves an entry from the backend.
mixed
retrieveEntry
(string $databaseURI, string $suid, string $contentType, array $fields)
-
string
$databaseURI: URI of Database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$suid: Server unique id of the entry: for horde this is the guid.
-
string
$contentType: Content-Type: the MIME type in which the function should return the data.
-
array
$fields: Hash of field names and SyncML_Property properties with the requested fields.
Redefinition of:
- SyncML_Backend::retrieveEntry()
- Retrieves an entry from the backend.
Sets a user as being authenticated at the backend.
string
setAuthenticated
(string $username, string $credData)
-
string
$username: A user name.
-
string
$credData: Authentication data provided by <Cred><Data> in the <SyncHdr>.
Redefinition of:
- SyncML_Backend::setAuthenticated()
- Sets a user as being authenticated at the backend.
Creates a clean test environment in the backend.
Ensures there's a user with the given credentials and an empty data store.
void
testSetup
(string $user, string $pwd)
-
string
$user: This user accout has to be created in the backend.
-
string
$pwd: The password for user $user.
Redefinition of:
- SyncML_Backend::testSetup()
- Creates a clean test environment in the backend.
Prepares the test start.
void
testStart
(string $user)
-
string
$user: This user accout has to be created in the backend.
Redefinition of:
- SyncML_Backend::testStart()
- Prepares the test start.
Tears down the test environment after the test is run.
Should remove the testuser created during testSetup and all its data.
void
testTearDown
()
Redefinition of:
- SyncML_Backend::testTearDown()
- Tears down the test environment after the test is run.
Stores Sync anchors after a successful synchronization to allow two-way synchronization next time.
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.
void
writeSyncAnchors
(string $databaseURI, string $clientAnchorNext, string $serverAnchorNext)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$clientAnchorNext: The client anchor as sent by the client.
-
string
$serverAnchorNext: The anchor as used internally by the server.
Redefinition of:
- SyncML_Backend::writeSyncAnchors()
- Stores Sync anchors after a successful synchronization to allow two-way synchronization next time.
Authenticates the user at the backend.
boolean|string
_checkAuthentication
(string $username, string $password)
-
string
$username: A user name.
-
string
$password: A password.
Redefinition of:
- SyncML_Backend::_checkAuthentication()
- Authenticates the user at the backend.
Checks if the parameter is a PEAR_Error object and if so logs the error.
mixed
_checkForError
(mixed $o)
-
mixed
$o: An object or value to check.
Generates a unique ID used as suid
string
_generateID
()
Returns a timestamp stored in the map for a given Server ID.
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.
mixed
_getChangeTS
(string $databaseURI, string $suid)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$suid: The server ID.
Retrieves the Client ID for a given Server ID from the map.
mixed
_getCuid
(string $databaseURI, string $suid)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$suid: The server ID.
Retrieves the Server ID for a given Client ID from the map.
mixed
_getSuid
(string $databaseURI, string $cuid)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
string
$cuid: The client ID.
Removes a suid from the suidlist.
Called by _trackDeletes() when updating the suidlist and deleteEntry() when removing an entry due to a client request.
void
_removeFromSuidList
(string $databaseURI, array $suid)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
array
$suid: The suid to remove from the list.
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.
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.
array
_trackDeletes
(string $databaseURI, array $currentSuids)
-
string
$databaseURI: URI of database to sync. Like calendar, tasks, contacts or notes. May include optional parameters: tasks?options=ignorecompleted.
-
array
$currentSuids: Array of all SUIDs (primary keys) currently in the server datastore.
Inherited Methods
Inherited From SyncML_Backend
SyncML_Backend::SyncML_Backend()
SyncML_Backend::addEntry()
SyncML_Backend::checkAuthentication()
SyncML_Backend::close()
SyncML_Backend::createUidMap()
SyncML_Backend::deleteEntry()
SyncML_Backend::eraseMap()
SyncML_Backend::factory()
SyncML_Backend::getCharset()
SyncML_Backend::getCurrentTimeStamp()
SyncML_Backend::getParameter()
SyncML_Backend::getServerChanges()
SyncML_Backend::getSyncDeviceID()
SyncML_Backend::getUser()
SyncML_Backend::isValidDatabaseURI()
SyncML_Backend::logFile()
SyncML_Backend::logMessage()
SyncML_Backend::readSyncAnchors()
SyncML_Backend::replaceEntry()
SyncML_Backend::retrieveEntry()
SyncML_Backend::sessionClose()
SyncML_Backend::sessionStart()
SyncML_Backend::setAuthenticated()
SyncML_Backend::setCharset()
SyncML_Backend::setupState()
SyncML_Backend::setUser()
SyncML_Backend::testSetup()
SyncML_Backend::testStart()
SyncML_Backend::testTearDown()
SyncML_Backend::writeSyncAnchors()
SyncML_Backend::_checkAuthentication()
SyncML_Backend::_normalize()