From d98bf4c5ff88709cadbc2292a33dd9f7bb2200a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Catal=C3=A0?= Date: Tue, 7 Dec 2021 14:44:53 +0100 Subject: [PATCH] MDL-72771 core_course: Set module visibility after moving it Move a module to another section needs to update its visibility after placing it into the new section. Otherwise an invalid database state prevents the system to move any module with a completion rule involving grades. --- course/lib.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/course/lib.php b/course/lib.php index db20748e21b..bc9ba12dc5d 100644 --- a/course/lib.php +++ b/course/lib.php @@ -1744,6 +1744,9 @@ function moveto_module($mod, $section, $beforemod=NULL) { echo $OUTPUT->notification("Could not delete module from existing section"); } + // Add the module into the new section. + course_add_cm_to_section($section->course, $mod->id, $section->section, $beforemod); + // If moving to a hidden section then hide module. if ($mod->section != $section->id) { if (!$section->visible && $mod->visible) { @@ -1760,8 +1763,6 @@ function moveto_module($mod, $section, $beforemod=NULL) { } } - // Add the module into the new section. - course_add_cm_to_section($section->course, $mod->id, $section->section, $beforemod); return $modvisible; }