Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
moodle
moodle
Commits
e4d6ab3b
Commit
e4d6ab3b
authored
Apr 07, 2015
by
Dan Poltawski
Browse files
Merge branch 'MDL-49747-task-error-improvement' of
https://github.com/brendanheywood/moodle
parents
bfceabab
e8a1c3e9
Changes
1
Hide whitespace changes
Inline
Side-by-side
lib/classes/lock/lock.php
View file @
e4d6ab3b
...
...
@@ -49,6 +49,9 @@ class lock {
/** @var bool $released Has this lock been released? If a lock falls out of scope without being released - show a warning. */
protected
$released
;
/** @var string $caller Where was this called from? Stored for when a warning is shown */
protected
$caller
=
'unknown'
;
/**
* Construct a lock containing the unique key required to release it.
* @param mixed $key - The lock key. The type of this is up to the lock_factory being used.
...
...
@@ -59,6 +62,12 @@ class lock {
$this
->
factory
=
$factory
;
$this
->
key
=
$key
;
$this
->
released
=
false
;
$caller
=
debug_backtrace
(
true
,
2
)[
1
];
if
(
$caller
&&
array_key_exists
(
'file'
,
$caller
)
)
{
$this
->
caller
=
$caller
[
'file'
]
.
' on line '
.
$caller
[
'line'
];
}
else
if
(
$caller
&&
array_key_exists
(
'class'
,
$caller
))
{
$this
->
caller
=
$caller
[
'class'
]
.
$caller
[
'type'
]
.
$caller
[
'function'
];
}
}
/**
...
...
@@ -103,10 +112,14 @@ class lock {
*/
public
function
__destruct
()
{
if
(
!
$this
->
released
&&
defined
(
'PHPUNIT_TEST'
))
{
$key
=
$this
->
key
;
$this
->
release
();
throw
new
\
coding_exception
(
'\core\lock\lock('
.
$this
->
key
.
') has fallen out of scope '
.
'without being released.'
.
"
\n
"
.
'Locks must ALWAYS be released by calling $mylock->release().'
);
throw
new
\
coding_exception
(
"A lock was created but not released at:
\n
"
.
$this
->
caller
.
"
\n\n
"
.
" Code should look like:
\n\n
"
.
"
\$
factory = \core\lock\lock_config::get_lock_factory('type');
\n
"
.
"
\$
lock =
\$
factory->get_lock(
$key
);
\n
"
.
"
\$
lock->release(); // Locks must ALWAYS be released like this.
\n\n
"
);
}
}
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment