From d41b721dc3c2379a19d2a2878ae894ea815c6594 Mon Sep 17 00:00:00 2001 From: Laurent David Date: Mon, 1 Jul 2024 09:04:58 +0200 Subject: [PATCH] MDL-81683 core_courseformat: Prevent subsection to be moved onto itself * Subsections are considered as section and need to be prevented to be moved into itself so to avoid infinite recursive structures. --- course/format/classes/stateactions.php | 4 ++++ lang/en/moodle.php | 1 + 2 files changed, 5 insertions(+) diff --git a/course/format/classes/stateactions.php b/course/format/classes/stateactions.php index 8ee286a717cfa..2f44be5cd9022 100644 --- a/course/format/classes/stateactions.php +++ b/course/format/classes/stateactions.php @@ -85,6 +85,10 @@ public function cm_move( $cm = $modinfo->get_cm($cmid); $currentsectionid = $cm->section; $targetsection = $modinfo->get_section_info_by_id($targetsectionid, MUST_EXIST); + if ($targetsection->is_delegated() && $cm->get_delegated_section_info()) { + throw new moodle_exception('subsectionmoveerror', 'core', '', null, 'Cannot move section on' . + ' another subsection'); + } $beforecm = (!empty($beforecmdid)) ? $modinfo->get_cm($beforecmdid) : null; if ($beforecm === null || $beforecm->id != $cmid) { moveto_module($cm, $targetsection, $beforecm); diff --git a/lang/en/moodle.php b/lang/en/moodle.php index 9a27682c6c309..f578e4b1b823c 100644 --- a/lang/en/moodle.php +++ b/lang/en/moodle.php @@ -1982,6 +1982,7 @@ $string['secs'] = 'secs'; $string['section'] = 'Section'; $string['sectionactionnotsupported'] = 'Section action "{$a}" is not supported here'; +$string['subsectionmoveerror'] = 'Subsection moved here'; $string['sectionname'] = 'Section name'; $string['sectionoutline'] = 'Section outline'; $string['sections'] = 'Sections';