class DatabaseLockBackend in Drupal driver for SQL Server and SQL Azure 8.2
Same name in this branch
- 8.2 src/Lock/DatabaseLockBackend.php \Drupal\sqlsrv\Lock\DatabaseLockBackend
- 8.2 src/ProxyClass/Lock/DatabaseLockBackend.php \Drupal\sqlsrv\ProxyClass\Lock\DatabaseLockBackend
Workaround for an issue with floats:
Hierarchy
- class \Drupal\Core\Lock\LockBackendAbstract implements LockBackendInterface
- class \Drupal\Core\Lock\DatabaseLockBackend
- class \Drupal\sqlsrv\Lock\DatabaseLockBackend
- class \Drupal\Core\Lock\DatabaseLockBackend
Expanded class hierarchy of DatabaseLockBackend
See also
https://github.com/Azure/msphpsql/issues/71
File
- src/
Lock/ DatabaseLockBackend.php, line 21 - Contains \Drupal\sqlsrv\Lock\DatabaseLockBackend.
Namespace
Drupal\sqlsrv\LockView source
class DatabaseLockBackend extends CoreDatabaseLockBackend {
/**
* {@inheritdoc}
*/
public function lockMayBeAvailable($name) {
$lock = $this->database
->query('SELECT CONVERT(varchar(50), expire, 128) as expire, value FROM {semaphore} WHERE name = :name', array(
':name' => $name,
))
->fetchAssoc();
if (!$lock) {
return true;
}
$expire = (double) $lock['expire'];
$now = microtime(true);
if ($now > $expire) {
// We check two conditions to prevent a race condition where another
// request acquired the lock and set a new expire time. We add a small
// number to $expire to avoid errors with float to string conversion.
return (bool) $this->database
->delete('semaphore')
->condition('name', $name)
->condition('value', $lock['value'])
->condition('expire', 0.0001 + $expire, '<=')
->execute();
}
return false;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DatabaseLockBackend:: |
protected | property | The database connection. | |
DatabaseLockBackend:: |
public | function |
Acquires a lock. Overrides LockBackendInterface:: |
|
DatabaseLockBackend:: |
protected | function | Act on an exception when semaphore might be stale. | |
DatabaseLockBackend:: |
protected | function | Check if the semaphore table exists and create it if not. | |
DatabaseLockBackend:: |
public | function |
Checks if a lock is available for acquiring. Overrides DatabaseLockBackend:: |
|
DatabaseLockBackend:: |
protected | function | Normalizes a lock name in order to comply with database limitations. | |
DatabaseLockBackend:: |
public | function |
Releases the given lock. Overrides LockBackendInterface:: |
|
DatabaseLockBackend:: |
public | function |
Releases all locks for the given lock token identifier. Overrides LockBackendInterface:: |
|
DatabaseLockBackend:: |
public | function | Defines the schema for the semaphore table. | |
DatabaseLockBackend:: |
constant | The database table name. | ||
DatabaseLockBackend:: |
public | function | Constructs a new DatabaseLockBackend. | 1 |
LockBackendAbstract:: |
protected | property | Current page lock token identifier. | |
LockBackendAbstract:: |
protected | property | Existing locks for this page. | |
LockBackendAbstract:: |
public | function |
Gets the unique page token for locks. Overrides LockBackendInterface:: |
|
LockBackendAbstract:: |
public | function |
Waits a short amount of time before a second lock acquire attempt. Overrides LockBackendInterface:: |