Skip to content

Commit

Permalink
Fix 'A lock was created but not released at' error - attempt 2?
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Dec 10, 2023
1 parent 3fd3e5c commit a08c2d3
Showing 1 changed file with 16 additions and 14 deletions.
30 changes: 16 additions & 14 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -694,22 +694,24 @@ private static function update_the_displayed_images($courseid = null) {
$lock = $lockfactory->get_lock('sectionid' . $coursesectionimage->sectionid, 5);
}
if (($lock instanceof \core\lock\lock) || (defined('BEHAT_SITE_RUNNING'))) {
$files = $fs->get_area_files($coursecontext->id, 'format_grid', 'sectionimage', $coursesectionimage->sectionid);
foreach ($files as $file) {
if (!$file->is_directory()) {
try {
$coursesectionimage = $toolbox->setup_displayed_image(
$coursesectionimage,
$file,
$courseid,
$coursesectionimage->sectionid,
$format
);
} catch (\Exception $e) {
$lock->release();
throw $e;
try {
$files = $fs->get_area_files($coursecontext->id, 'format_grid', 'sectionimage', $coursesectionimage->sectionid);
foreach ($files as $file) {
if (!$file->is_directory()) {
$coursesectionimage = $toolbox->setup_displayed_image(
$coursesectionimage,
$file,
$courseid,
$coursesectionimage->sectionid,
$format
);
}
}
} catch (\Exception $e) {
if (!defined('BEHAT_SITE_RUNNING')) {
$lock->release();
}
throw $e;
}
if (!defined('BEHAT_SITE_RUNNING')) {
$lock->release();
Expand Down

0 comments on commit a08c2d3

Please sign in to comment.