MDL-82767 core_courseformat: deprecate edits in mod.php and view.php

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.
This commit is contained in:
ferran
2025-01-22 10:35:23 +01:00
parent fec5bf61f4
commit a438da66ca
4 changed files with 71 additions and 56 deletions
@@ -0,0 +1,11 @@
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 affected actions are: indent,
duplicate, hide, show, stealth, delete, groupmode and marker (highlight).
The course/format/updates.php uses the same parameters as the
core_courseformat_course_update webservice
type: deprecated
+43 -8
View File
@@ -29,20 +29,20 @@ require_once("lib.php");
$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');
@@ -118,6 +118,11 @@ if (!empty($add)) {
)
);
} 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);
@@ -130,6 +135,11 @@ if (!empty($add)) {
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);
@@ -220,6 +230,11 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
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 indent 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);
@@ -245,6 +260,11 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
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);
@@ -259,6 +279,11 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
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);
@@ -269,6 +294,11 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
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);
@@ -280,6 +310,11 @@ if ((!empty($movetosection) or !empty($moveto)) and confirm_sesskey()) {
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);
-45
View File
@@ -1,45 +0,0 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Duplicates a given course module
*
* The script backups and restores a single activity as if it was imported
* from the same course, using the default import settings. The newly created
* copy of the activity is then moved right below the original one.
*
* @package core
* @subpackage course
* @deprecated Moodle 2.8 MDL-46428 - Now redirects to mod.php.
* @copyright 2011 David Mudrak <[email protected]>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__ . '/../config.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);
redirect(new moodle_url('/course/mod.php', array('duplicate' => $cmid, 'id' => $courseid,
'sesskey' => sesskey(), 'sr' => $sectionreturn)));
+17 -3
View File
@@ -31,15 +31,15 @@ redirect_if_major_upgrade_required();
$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);
@@ -193,8 +193,13 @@ if ($PAGE->user_allowed_editing()) {
}
}
// 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]));
@@ -204,6 +209,10 @@ if ($PAGE->user_allowed_editing()) {
}
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]));
@@ -213,7 +222,12 @@ if ($PAGE->user_allowed_editing()) {
}
}
// 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]));