Skip to content

Commit

Permalink
Fix 'Unable to update defaultimageresizemethod setting' - #211
Browse files Browse the repository at this point in the history
  • Loading branch information
gjb2048 committed Jun 9, 2024
1 parent e8358a2 commit 24d20bb
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 29 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ History
Version 403.1.3 - In development
--------------------------------
1. Fix updating of course when adding or removing sections. Note: Known issue of the section not looking as it should.
2. Fix 'Unable to update defaultimageresizemethod setting' - #211.

Version 403.1.2 - 08/04/2024
----------------------------
Expand Down
68 changes: 39 additions & 29 deletions classes/toolbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,9 @@ private static function update_the_displayed_images($courseid = null) {
$fs = get_file_storage();
$lockfactory = null;
$lock = null;
$format = null;
$coursecontext = null;

if (!defined('BEHAT_SITE_RUNNING')) {
$lockfactory = \core\lock\lock_config::get_lock_factory('format_grid');
}
Expand All @@ -696,42 +699,49 @@ private static function update_the_displayed_images($courseid = null) {
if ($courseid != $coursesectionimage->courseid) {
$courseid = $coursesectionimage->courseid;
$format = course_get_format($courseid);
if (get_class($format) != 'format_grid') {
// Not currently in the Grid format, but was.
$format = null;
continue;
}
$coursecontext = \context_course::instance($courseid);
}
$coursecontext = \context_course::instance($courseid);
if (!defined('BEHAT_SITE_RUNNING')) {
$lock = $lockfactory->get_lock('sectionid' . $coursesectionimage->sectionid, 5);
}
if (($lock instanceof \core\lock\lock) || (defined('BEHAT_SITE_RUNNING'))) {
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
);
if (!empty($format)) {
if (!defined('BEHAT_SITE_RUNNING')) {
$lock = $lockfactory->get_lock('sectionid' . $coursesectionimage->sectionid, 5);
}
if (($lock instanceof \core\lock\lock) || (defined('BEHAT_SITE_RUNNING'))) {
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;
}
} catch (\Exception $e) {
if (!defined('BEHAT_SITE_RUNNING')) {
$lock->release();
}
throw $e;
}
if (!defined('BEHAT_SITE_RUNNING')) {
$lock->release();
} else {
throw new \moodle_exception(
'imagemanagement',
'format_grid',
'',
get_string('cannotgetmanagesectionimagelock', 'format_grid')
);
}
} else {
throw new \moodle_exception(
'imagemanagement',
'format_grid',
'',
get_string('cannotgetmanagesectionimagelock', 'format_grid')
);
}
}
}
Expand Down

0 comments on commit 24d20bb

Please sign in to comment.