Skip to content

Commit

Permalink
MDL-82767 core_courseformat: deprecate edits in mod.php and view.php
Browse files Browse the repository at this point in the history
Most edit logic embed directly into course/view.php and course/mod.php
is now redirected to course/format/update.php. This commit add
deprecations messages to the old get params so it can be removed in
Moodle 6.0 for good.
  • Loading branch information
ferranrecio committed Oct 30, 2024
1 parent 1fdeee6 commit 92912b0
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 11 deletions.
9 changes: 9 additions & 0 deletions .upgradenotes/MDL-82767-2024103011171091.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
issueNumber: MDL-82767
notes:
core_courseformat:
- message: >-
Many get actions from course/view.php and course/mod.php are now
deprecated. Use the new course/format/update.php instead to replace all
direct edit urls in your code. The course/format/updates.php uses the
same parameters as the core_courseformat_course_update webservice
type: deprecated
51 changes: 43 additions & 8 deletions course/mod.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,20 @@
$sectionreturn = optional_param('sr', null, PARAM_INT);
$add = optional_param('add', '', PARAM_ALPHANUM);
$type = optional_param('type', '', PARAM_ALPHA);
$indent = optional_param('indent', 0, PARAM_INT);
$indent = optional_param('indent', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$update = optional_param('update', 0, PARAM_INT);
$duplicate = optional_param('duplicate', 0, PARAM_INT);
$hide = optional_param('hide', 0, PARAM_INT);
$stealth = optional_param('stealth', 0, PARAM_INT);
$show = optional_param('show', 0, PARAM_INT);
$duplicate = optional_param('duplicate', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$hide = optional_param('hide', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$stealth = optional_param('stealth', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$show = optional_param('show', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$copy = optional_param('copy', 0, PARAM_INT);
$moveto = optional_param('moveto', 0, PARAM_INT);
$movetosection = optional_param('movetosection', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT);
$delete = optional_param('delete', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$course = optional_param('course', 0, PARAM_INT);
$groupmode = optional_param('groupmode', -1, PARAM_INT);
$groupmode = optional_param('groupmode', -1, PARAM_INT); // TODO remove this param as part of MDL-83530.
$cancelcopy = optional_param('cancelcopy', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
$confirm = optional_param('confirm', 0, PARAM_BOOL); // TODO remove this param as part of MDL-83530.

// This page should always redirect
$url = new moodle_url('/course/mod.php');
Expand Down Expand Up @@ -118,6 +118,11 @@
)
);
} else if (!empty($duplicate) and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The duplicate param is deprecated. Please use action cm_duplicate in course/format/update.php instead.',
DEBUG_DEVELOPER
);
$cm = get_coursemodule_from_id('', $duplicate, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

Expand All @@ -130,6 +135,11 @@
redirect(course_get_url($course, $cm->sectionnum, $urloptions));

} else if (!empty($delete)) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The delete param is deprecated. Please use action cm_delete in course/format/update.php instead.',
DEBUG_DEVELOPER
);
$cm = get_coursemodule_from_id('', $delete, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

Expand Down Expand Up @@ -216,6 +226,11 @@
redirect(course_get_url($course, $section->section, $urloptions));

} else if (!empty($indent) and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The delete param deprecated. Please use action cm_moveleft and cm_moveright in course/format/update.php instead.',
DEBUG_DEVELOPER
);
$id = required_param('id', PARAM_INT);

$cm = get_coursemodule_from_id('', $id, 0, true, MUST_EXIST);
Expand All @@ -241,6 +256,11 @@
redirect(course_get_url($course, $cm->sectionnum, $urloptions));

} else if (!empty($hide) and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The hide param deprecated. Please use action cm_hide in course/format/update.php instead.',
DEBUG_DEVELOPER
);
$cm = get_coursemodule_from_id('', $hide, 0, true, MUST_EXIST);
$course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);

Expand All @@ -255,6 +275,11 @@
redirect(course_get_url($course, $cm->sectionnum, $urloptions));

} else if (!empty($stealth) and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The stealth param deprecated. Please use action cm_stealth in course/format/update.php instead.',
DEBUG_DEVELOPER
);
list($course, $cm) = get_course_and_cm_from_cmid($stealth);
require_login($course, false, $cm);
require_capability('moodle/course:activityvisibility', $cm->context);
Expand All @@ -265,6 +290,11 @@
redirect(course_get_url($course, $cm->sectionnum, array('sr' => $sectionreturn)));

} else if (!empty($show) and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The show param deprecated. Please use action cm_show in course/format/update.php instead.',
DEBUG_DEVELOPER
);
list($course, $cm) = get_course_and_cm_from_cmid($show);
require_login($course, false, $cm);
require_capability('moodle/course:activityvisibility', $cm->context);
Expand All @@ -276,6 +306,11 @@
redirect(course_get_url($course, $section->section, $urloptions));

} else if ($groupmode > -1 and confirm_sesskey()) {
// TODO remove this else if as part of MDL-83530.
debugging(
'The gruopmode param deprecated. Please use the group mode actions in course/format/update.php instead.',
DEBUG_DEVELOPER
);
$id = required_param('id', PARAM_INT);

$cm = get_coursemodule_from_id('', $id, 0, true, MUST_EXIST);
Expand Down
20 changes: 17 additions & 3 deletions course/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
$id = optional_param('id', 0, PARAM_INT);
$name = optional_param('name', '', PARAM_TEXT);
$edit = optional_param('edit', -1, PARAM_BOOL);
$hide = optional_param('hide', 0, PARAM_INT);
$show = optional_param('show', 0, PARAM_INT);
$hide = optional_param('hide', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$show = optional_param('show', 0, PARAM_INT); // TODO remove this param as part of MDL-83530.
$duplicatesection = optional_param('duplicatesection', 0, PARAM_INT);
$idnumber = optional_param('idnumber', '', PARAM_RAW);
$sectionid = optional_param('sectionid', 0, PARAM_INT);
$section = optional_param('section', null, PARAM_INT);
$expandsection = optional_param('expandsection', -1, PARAM_INT);
$move = optional_param('move', 0, PARAM_INT);
$marker = optional_param('marker', -1 , PARAM_INT);
$marker = optional_param('marker', -1 , PARAM_INT); // TODO remove this param as part of MDL-83530.
$switchrole = optional_param('switchrole', -1, PARAM_INT); // Deprecated, use course/switchrole.php instead.
$return = optional_param('return', 0, PARAM_LOCALURL);

Expand Down Expand Up @@ -199,8 +199,13 @@
}
}

// TODO remove this if as part of MDL-83530.
if (has_capability('moodle/course:sectionvisibility', $context)) {
if ($hide && confirm_sesskey()) {
debugging(
'The hide param in course view is deprecated. Please use course/format/update.php instead.',
DEBUG_DEVELOPER
);
set_section_visible($course->id, $hide, '0');
if ($sectionid) {
redirect(course_get_url($course, $section, ['navigation' => true]));
Expand All @@ -210,6 +215,10 @@
}

if ($show && confirm_sesskey()) {
debugging(
'The show param in course view is deprecated. Please use course/format/update.php instead.',
DEBUG_DEVELOPER
);
set_section_visible($course->id, $show, '1');
if ($sectionid) {
redirect(course_get_url($course, $section, ['navigation' => true]));
Expand All @@ -219,7 +228,12 @@
}
}

// TODO remove this if as part of MDL-83530.
if ($marker >= 0 && confirm_sesskey()) {
debugging(
'The marker param in course view is deprecated. Please use course/format/update.php instead.',
DEBUG_DEVELOPER
);
course_set_marker($course->id, $marker);
if ($sectionid) {
redirect(course_get_url($course, $section, ['navigation' => true]));
Expand Down

0 comments on commit 92912b0

Please sign in to comment.