Horde_Lock_Sql
extends Horde_Lock
in package
The Horde_Lock_Sql driver implements a storage backend for the Horde_Lock API.
The table structure for the locks is as follows:
CREATE TABLE horde_locks ( lock_id VARCHAR(36) NOT NULL, lock_owner VARCHAR(32) NOT NULL, lock_scope VARCHAR(32) NOT NULL, lock_principal VARCHAR(255) NOT NULL, lock_origin_timestamp BIGINT NOT NULL, lock_update_timestamp BIGINT NOT NULL, lock_expiry_timestamp BIGINT NOT NULL, lock_type TINYINT NOT NULL, PRIMARY KEY (lock_id) );
Copyright 2008-2017 Horde LLC (http://www.horde.org/)
See the enclosed file LICENSE for license information (LGPL). If you did not receive this file, see http://www.horde.org/licenses/lgpl21.
Tags
Table of Contents
- PERMANENT = -1
- TYPE_EXCLUSIVE = 1
- TYPE_SHARED = 2
- $_logger : Horde_Log_Logger
- Logger.
- $_params : array<string|int, mixed>
- Driver parameters.
- $_db : Horde_Db_Adapter
- Handle for the current database connection.
- __construct() : mixed
- Constructor.
- clearLock() : bool
- Removes a lock given the lock ID.
- doGC() : mixed
- Do garbage collection needed for the driver.
- getLockInfo() : array<string|int, mixed>
- Return an array of information about the requested lock.
- getLocks() : array<string|int, mixed>
- Return a list of valid locks with the option to limit the results by principal, scope and/or type.
- resetLock() : bool
- Extend the valid lifetime of a valid lock to now + $lifetime.
- setLock() : mixed
- Sets a lock on the requested principal and returns the generated lock ID.
Constants
PERMANENT
public
mixed
PERMANENT
= -1
TYPE_EXCLUSIVE
public
mixed
TYPE_EXCLUSIVE
= 1
TYPE_SHARED
public
mixed
TYPE_SHARED
= 2
Properties
$_logger
Logger.
protected
Horde_Log_Logger
$_logger
$_params
Driver parameters.
protected
array<string|int, mixed>
$_params
$_db
Handle for the current database connection.
private
Horde_Db_Adapter
$_db
Methods
__construct()
Constructor.
public
__construct([array<string|int, mixed> $params = array() ]) : mixed
Parameters
- $params : array<string|int, mixed> = array()
-
Parameters:
'db' - (Horde_Db_Adapter) [REQUIRED] The DB instance. 'table' - (string) The name of the lock table in 'database'. DEFAULT: 'horde_locks'
Tags
Return values
mixed —clearLock()
Removes a lock given the lock ID.
public
clearLock(mixed $lockid) : bool
Parameters
- $lockid : mixed
-
The lock ID as generated by a previous call to setLock()
Tags
Return values
bool —Returns true on success.
doGC()
Do garbage collection needed for the driver.
public
doGC() : mixed
Tags
Return values
mixed —getLockInfo()
Return an array of information about the requested lock.
public
getLockInfo(mixed $lockid) : array<string|int, mixed>
Parameters
- $lockid : mixed
-
Lock ID to look up.
Tags
Return values
array<string|int, mixed> —Lock information.
getLocks()
Return a list of valid locks with the option to limit the results by principal, scope and/or type.
public
getLocks([mixed $scope = null ][, mixed $principal = null ][, mixed $type = null ]) : array<string|int, mixed>
Parameters
- $scope : mixed = null
-
The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
- $principal : mixed = null
-
Principal for which to check for locks
- $type : mixed = null
-
Only return locks of the given type. Defaults to null, or all locks
Tags
Return values
array<string|int, mixed> —Array of locks with the ID as the key and the lock details as the value. If there are no current locks this will return an empty array.
resetLock()
Extend the valid lifetime of a valid lock to now + $lifetime.
public
resetLock(mixed $lockid, mixed $lifetime) : bool
Parameters
- $lockid : mixed
-
Lock ID to reset. Must be a valid, non-expired lock.
- $lifetime : mixed
Tags
Return values
bool —Returns true on success.
setLock()
Sets a lock on the requested principal and returns the generated lock ID.
public
setLock(mixed $requestor, mixed $scope, mixed $principal[, mixed $lifetime = 1 ][, mixed $type = Horde_Lock::TYPE_SHARED ]) : mixed
Parameters
- $requestor : mixed
-
User ID of the lock requestor.
- $scope : mixed
-
The scope of the lock. Typically the name of the application requesting the lock or some other identifier used to group locks together.
- $principal : mixed
-
A principal on which a lock should be granted. The format can be any string but is suggested to be in URI form.
- $lifetime : mixed = 1
-
Time (in seconds) for which the lock will be considered valid.
- $type : mixed = Horde_Lock::TYPE_SHARED
Tags
Return values
mixed —A string lock ID.