Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
D
drupal
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Custom Issue Tracker
Custom Issue Tracker
Labels
Merge Requests
222
Merge Requests
222
Requirements
Requirements
List
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Analytics
Analytics
Code Review
Insights
Issue
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
project
drupal
Commits
4e1d6670
Commit
4e1d6670
authored
Sep 26, 2013
by
alexpott
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue
#2087931
by damiankloip: Inject database connection into DatabaseLockBackend.
parent
34f638b2
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
9 deletions
+22
-9
core/core.services.yml
core/core.services.yml
+1
-0
core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
+19
-7
core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
...ules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
+1
-1
core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
...ules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
+1
-1
No files found.
core/core.services.yml
View file @
4e1d6670
...
...
@@ -221,6 +221,7 @@ services:
arguments
:
[
'
@container.namespaces'
,
'
@cache.cache'
,
'
@language_manager'
,
'
@module_handler'
]
lock
:
class
:
Drupal\Core\Lock\DatabaseLockBackend
arguments
:
[
'
@database'
]
user.tempstore
:
class
:
Drupal\user\TempStoreFactory
arguments
:
[
'
@database'
,
'
@lock'
]
...
...
core/lib/Drupal/Core/Lock/DatabaseLockBackend.php
View file @
4e1d6670
...
...
@@ -7,6 +7,7 @@
namespace
Drupal\Core\Lock
;
use
Drupal\Core\Database\Connection
;
use
Drupal\Core\Database\IntegrityConstraintViolationException
;
/**
...
...
@@ -14,13 +15,24 @@
*/
class
DatabaseLockBackend
extends
LockBackendAbstract
{
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected
$database
;
/**
* Constructs a new DatabaseLockBackend.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
*/
public
function
__construct
()
{
public
function
__construct
(
Connection
$database
)
{
// __destruct() is causing problems with garbage collections, register a
// shutdown function instead.
drupal_register_shutdown_function
(
array
(
$this
,
'releaseAll'
));
$this
->
database
=
$database
;
}
/**
...
...
@@ -32,7 +44,7 @@ public function acquire($name, $timeout = 30.0) {
$expire
=
microtime
(
TRUE
)
+
$timeout
;
if
(
isset
(
$this
->
locks
[
$name
]))
{
// Try to extend the expiration of a lock we already acquired.
$success
=
(
bool
)
db_
update
(
'semaphore'
)
$success
=
(
bool
)
$this
->
database
->
update
(
'semaphore'
)
->
fields
(
array
(
'expire'
=>
$expire
))
->
condition
(
'name'
,
$name
)
->
condition
(
'value'
,
$this
->
getLockId
())
...
...
@@ -50,7 +62,7 @@ public function acquire($name, $timeout = 30.0) {
// We always want to do this code at least once.
do
{
try
{
db_
insert
(
'semaphore'
)
$this
->
database
->
insert
(
'semaphore'
)
->
fields
(
array
(
'name'
=>
$name
,
'value'
=>
$this
->
getLockId
(),
...
...
@@ -81,7 +93,7 @@ public function acquire($name, $timeout = 30.0) {
* Implements Drupal\Core\Lock\LockBackedInterface::lockMayBeAvailable().
*/
public
function
lockMayBeAvailable
(
$name
)
{
$lock
=
db_
query
(
'SELECT expire, value FROM {semaphore} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetchAssoc
();
$lock
=
$this
->
database
->
query
(
'SELECT expire, value FROM {semaphore} WHERE name = :name'
,
array
(
':name'
=>
$name
))
->
fetchAssoc
();
if
(
!
$lock
)
{
return
TRUE
;
}
...
...
@@ -91,7 +103,7 @@ public function lockMayBeAvailable($name) {
// 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
)
db_
delete
(
'semaphore'
)
return
(
bool
)
$this
->
database
->
delete
(
'semaphore'
)
->
condition
(
'name'
,
$name
)
->
condition
(
'value'
,
$lock
[
'value'
])
->
condition
(
'expire'
,
0.0001
+
$expire
,
'<='
)
...
...
@@ -105,7 +117,7 @@ public function lockMayBeAvailable($name) {
*/
public
function
release
(
$name
)
{
unset
(
$this
->
locks
[
$name
]);
db_
delete
(
'semaphore'
)
$this
->
database
->
delete
(
'semaphore'
)
->
condition
(
'name'
,
$name
)
->
condition
(
'value'
,
$this
->
getLockId
())
->
execute
();
...
...
@@ -121,7 +133,7 @@ public function releaseAll($lock_id = NULL) {
if
(
empty
(
$lock_id
))
{
$lock_id
=
$this
->
getLockId
();
}
db_
delete
(
'semaphore'
)
$this
->
database
->
delete
(
'semaphore'
)
->
condition
(
'value'
,
$lock_id
)
->
execute
();
}
...
...
core/modules/system/lib/Drupal/system/Tests/Lock/LockUnitTest.php
View file @
4e1d6670
...
...
@@ -39,7 +39,7 @@ public static function getInfo() {
public
function
setUp
()
{
parent
::
setUp
();
$this
->
lock
=
new
DatabaseLockBackend
();
$this
->
lock
=
new
DatabaseLockBackend
(
$this
->
container
->
get
(
'database'
)
);
$this
->
installSchema
(
'system'
,
'semaphore'
);
}
...
...
core/modules/user/lib/Drupal/user/Tests/TempStoreDatabaseTest.php
View file @
4e1d6670
...
...
@@ -83,7 +83,7 @@ protected function tearDown() {
*/
public
function
testUserTempStore
()
{
// Create a key/value collection.
$factory
=
new
TempStoreFactory
(
Database
::
getConnection
(),
new
DatabaseLockBackend
());
$factory
=
new
TempStoreFactory
(
Database
::
getConnection
(),
new
DatabaseLockBackend
(
Database
::
getConnection
()
));
$collection
=
$this
->
randomName
();
// Create two mock users.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment