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 Nov 29, 2024
1 parent 7a71375 commit 904de37
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 17 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 groupmode 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
29 changes: 23 additions & 6 deletions course/modduplicate.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* from the same course, using the default import settings. The newly created
* copy of the activity is then moved right below the original one.
*
* @todo Remove this file in Moodle 6.0 (MDL-83530).
* @package core
* @subpackage course
* @deprecated Moodle 2.8 MDL-46428 - Now redirects to mod.php.
Expand All @@ -29,17 +30,33 @@
*/

require_once(__DIR__ . '/../config.php');
require_once($CFG->dirroot .'/course/lib.php');

$cmid = required_param('cmid', PARAM_INT);
$courseid = required_param('course', PARAM_INT);
$sectionreturn = optional_param('sr', null, PARAM_INT);

require_sesskey();

debugging('Please use moodle_url(\'/course/mod.php\', array(\'duplicate\' => $cmid
, \'id\' => $courseid, \'sesskey\' => sesskey(), \'sr\' => $sectionreturn)))
instead of new moodle_url(\'/course/modduplicate.php\', array(\'cmid\' => $cmid
, \'course\' => $courseid, \'sr\' => $sectionreturn))', DEBUG_DEVELOPER);
debugging(
'This page is deprecated, please use state actions instead or
generate the new url using the course format instance. For example
$format->get_update_url(
action: \'cm_duplicate\',
ids: [$cm->id],
);',
DEBUG_DEVELOPER
);

redirect(new moodle_url('/course/mod.php', array('duplicate' => $cmid, 'id' => $courseid,
'sesskey' => sesskey(), 'sr' => $sectionreturn)));
$format = course_get_format($courseid);
if ($sectionreturn === null) {
$format->set_sectionnum($sectionnum);
}

$redirect = $format->get_update_url(
action: 'cm_duplicate',
ids: [$cmid],
returnurl: $format->get_view_url($format->get_sectionnum(), ['navigation' => true]),
);

redirect($redirect);
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 904de37

Please sign in to comment.