Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Stud.IP
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Jan-Hendrik Willms
Stud.IP
Commits
3cb7ba8d
Commit
3cb7ba8d
authored
2 years ago
by
Jan-Hendrik Willms
Committed by
David Siegfried
2 years ago
Browse files
Options
Downloads
Patches
Plain Diff
fix parameter count for sprintf() in StudipLock::get(), fixes #1247
Closes #1247 Merge request
studip/studip!763
parent
cd2da0ea
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/classes/StudipLock.class.php
+16
-13
16 additions, 13 deletions
lib/classes/StudipLock.class.php
with
16 additions
and
13 deletions
lib/classes/StudipLock.class.php
+
16
−
13
View file @
3cb7ba8d
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
/**
/**
* StudipLock.class.php
* StudipLock.class.php
* class with methods to perform cooperative advisory locking
* class with methods to perform cooperative advisory locking
* using the GET_LOCK feature from Mysql
* using the GET_LOCK feature from Mysql
* https://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock
* https://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_get-lock
*
*
* This program is free software; you can redistribute it and/or
* This program is free software; you can redistribute it and/or
...
@@ -33,23 +33,26 @@ class StudipLock
...
@@ -33,23 +33,26 @@ class StudipLock
}
}
/**
/**
* Tries to obtain a lock with a name given by the string $lockname,
* Tries to obtain a lock with a name given by the string $lockname,
* using a timeout of $timeout seconds. Returns 1 if the lock was obtained
* using a timeout of $timeout seconds. Returns 1 if the lock was obtained
* successfully, 0 if the attempt timed out
* successfully, 0 if the attempt timed out
* (for example, because another client has previously locked the name),
* (for example, because another client has previously locked the name),
* or NULL if an error occurred
* or NULL if an error occurred
* If a name has been locked by one client, any request by another client
* If a name has been locked by one client, any request by another client
* for a lock with the same name is blocked.
* for a lock with the same name is blocked.
*
*
* @param string $lockname
* @param string $lockname
* @param number $timeout in seconds
* @param number $timeout in seconds
* @throws UnexpectedValueException if there is already an active lock
* @throws UnexpectedValueException if there is already an active lock
* @return integer 1 if the lock was obtained successfully, 0 if the attempt timed out
* @return integer 1 if the lock was obtained successfully, 0 if the attempt timed out
*/
*/
public
static
function
get
(
$lockname
,
$timeout
=
10
)
public
static
function
get
(
$lockname
,
$timeout
=
10
)
{
{
if
(
self
::
$current
!==
null
)
{
if
(
self
::
$current
!==
null
)
{
throw
new
UnexpectedValueException
(
sprintf
(
'could not acquire new lock, %s still active'
));
throw
new
UnexpectedValueException
(
sprintf
(
'could not acquire new lock, %s still active'
,
self
::
$current
));
}
}
$ok
=
DBManager
::
get
()
->
fetchColumn
(
"SELECT GET_LOCK(?,?)"
,
[
self
::
lockname
(
$lockname
),
$timeout
]);
$ok
=
DBManager
::
get
()
->
fetchColumn
(
"SELECT GET_LOCK(?,?)"
,
[
self
::
lockname
(
$lockname
),
$timeout
]);
if
(
$ok
)
{
if
(
$ok
)
{
...
@@ -60,7 +63,7 @@ class StudipLock
...
@@ -60,7 +63,7 @@ class StudipLock
/**
/**
* check if lock with given name is available
* check if lock with given name is available
*
*
* @param string $lockname
* @param string $lockname
* @return integer 1 if lock is available
* @return integer 1 if lock is available
*/
*/
...
@@ -68,10 +71,10 @@ class StudipLock
...
@@ -68,10 +71,10 @@ class StudipLock
{
{
return
DBManager
::
get
()
->
fetchColumn
(
"SELECT IS_FREE_LOCK(?)"
,
[
self
::
lockname
(
$lockname
)]);
return
DBManager
::
get
()
->
fetchColumn
(
"SELECT IS_FREE_LOCK(?)"
,
[
self
::
lockname
(
$lockname
)]);
}
}
/**
/**
* release the current lock
* release the current lock
*
*
* @return integer 1 if the lock could be released
* @return integer 1 if the lock could be released
*/
*/
public
static
function
release
()
public
static
function
release
()
...
@@ -80,11 +83,11 @@ class StudipLock
...
@@ -80,11 +83,11 @@ class StudipLock
return
DBManager
::
get
()
->
fetchColumn
(
"SELECT RELEASE_LOCK(?)"
,
[
self
::
lockname
(
self
::
$current
)]);
return
DBManager
::
get
()
->
fetchColumn
(
"SELECT RELEASE_LOCK(?)"
,
[
self
::
lockname
(
self
::
$current
)]);
}
}
}
}
/**
/**
* prepends the name of current database to lockname
* prepends the name of current database to lockname
* because locks are server-wide
* because locks are server-wide
*
*
* @param string $lockname
* @param string $lockname
* @return string
* @return string
*/
*/
...
@@ -92,4 +95,4 @@ class StudipLock
...
@@ -92,4 +95,4 @@ class StudipLock
{
{
return
$GLOBALS
[
'DB_STUDIP_DATABASE'
]
.
'_'
.
$lockname
;
return
$GLOBALS
[
'DB_STUDIP_DATABASE'
]
.
'_'
.
$lockname
;
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment