Skip to content

Commit

Permalink
MDL-81683 core_courseformat: Prevent subsection to be moved onto itself
Browse files Browse the repository at this point in the history
* Subsections are considered as section and need to be prevented to
be moved into itself so to avoid infinite recursive structures.
  • Loading branch information
laurentdavid committed Jul 2, 2024
1 parent 1ec1064 commit d41b721
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
4 changes: 4 additions & 0 deletions course/format/classes/stateactions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions lang/en/moodle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d41b721

Please sign in to comment.