This commit is contained in:
Sara Arjona
2025-03-12 12:23:00 +01:00
7 changed files with 24 additions and 98 deletions
@@ -0,0 +1,14 @@
issueNumber: MDL-79124
notes:
core_user:
- message: >-
Final removal of the following user preference helpers, please use the
`core_user/repository` module instead:
- `user_preference_allow_ajax_update`
- `M.util.set_user_preference`
- `lib/ajax/setuserpref.php`
type: removed
+2
View File
@@ -142,6 +142,8 @@ noreplybouncesubject,core
configgeneralquestionbank,core_backup
generalquestionbank,core_backup
cannotdeletecategoryquestions,core_error
errorsettinguserpref,core_error
notallowedtoupdateprefremotely,core_error
errordeletingquestionsfromcategory,core_question
importantupdates_content,core_admin
importantupdates_title,core_admin
+2 -2
View File
@@ -260,7 +260,6 @@ $string['erroroutput'] = 'Error output, so disabling automatic redirect.';
$string['errorparsingxml'] = 'Error parsing XML: {$a->errorstring} at line {$a->errorline}, char {$a->errorchar}';
$string['errorreadingfile'] = 'Error reading file "{$a}"';
$string['errorsavingrequest'] = 'An error occurred when trying to save your request.';
$string['errorsettinguserpref'] = 'Error setting user preference';
$string['errorunzippingfiles'] = 'Error unzipping files';
$string['expiredkey'] = 'Expired key';
$string['externalauthpassworderror'] = 'Non-empty password for external authentication';
@@ -484,7 +483,6 @@ $string['nosite'] = 'Could not find a top-level course!';
$string['nositeid'] = 'No site ID';
$string['nostartdatenoenddate'] = 'A course end date can only be set if a start date is also set.';
$string['nostatstodisplay'] = 'Sorry, there is no available data to display';
$string['notallowedtoupdateprefremotely'] = 'You are not allowed to update this user preference remotely';
$string['notavailable'] = 'That is not currently available';
$string['notfound'] = 'Not found';
$string['notlocalisederrormessage'] = '{$a}';
@@ -668,3 +666,5 @@ $string['myisamproblem'] = 'Database tables are using MyISAM database engine, it
// Deprecated since Moodle 5.0.
$string['cannotdeletecategoryquestions'] = 'Could not delete questions from category \'{$a}\'';
$string['errorsettinguserpref'] = 'Error setting user preference';
$string['notallowedtoupdateprefremotely'] = 'You are not allowed to update this user preference remotely';
+3 -16
View File
@@ -24,24 +24,11 @@
*/
/**
* You need to call this function if you wish to use the set_user_preference method in javascript_static.php, to white-list the
* preference you want to update from JavaScript, and to specify the type of cleaning you expect to be done on values.
*
* @package core
* @category preference
* @param string $name the name of the user_perference we should allow to be updated by remote calls.
* @param integer $paramtype one of the PARAM_{TYPE} constants, user to clean submitted values before set_user_preference is called.
* @return null
*
* @deprecated since Moodle 4.3
*/
function user_preference_allow_ajax_update($name, $paramtype) {
global $USER, $PAGE;
debugging(__FUNCTION__ . '() is deprecated. Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
// Record in the session that this user_preference is allowed to updated remotely.
$USER->ajax_updatable_user_prefs[$name] = $paramtype;
#[\core\attribute\deprecated('\'core_user/repository\' module', since: '4.3', mdl: 'MDL-76974', final: true)]
function user_preference_allow_ajax_update() {
\core\deprecation::emit_deprecation_if_present(__FUNCTION__);
}
/**
-53
View File
@@ -1,53 +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/>.
/**
* Code to update a user preference in response to an ajax call.
*
* You should not send requests to this script directly. Instead use the set_user_preference
* function in javascript_static.js.
*
* @package core
* @category preference
* @copyright 2008 Tim Hunt
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @deprecated since Moodle 4.3
*/
require_once(__DIR__ . '/../../config.php');
// Check access.
if (!confirm_sesskey()) {
throw new \moodle_exception('invalidsesskey');
}
// Get the name of the preference to update, and check it is allowed.
$name = required_param('pref', PARAM_RAW);
if (!isset($USER->ajax_updatable_user_prefs[$name])) {
throw new \moodle_exception('notallowedtoupdateprefremotely');
}
debugging('Use of setuserpref.php is deprecated. Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
// Get and the value.
$value = required_param('value', $USER->ajax_updatable_user_prefs[$name]);
// Update
if (!set_user_preference($name, $value)) {
throw new \moodle_exception('errorsettinguserpref');
}
echo 'OK';
+2 -16
View File
@@ -194,24 +194,10 @@ M.util.CollapsibleRegion.prototype.div = null;
M.util.CollapsibleRegion.prototype.icon = null;
/**
* Makes a best effort to connect back to Moodle to update a user preference,
* however, there is no mechanism for finding out if the update succeeded.
*
* Before you can use this function in your JavsScript, you must have called
* user_preference_allow_ajax_update from moodlelib.php to tell Moodle that
* the udpate is allowed, and how to safely clean and submitted values.
*
* @param {String} name the name of the setting to update.
* @param {String} value the value to set it to.
*
* @deprecated since Moodle 4.3.
*/
M.util.set_user_preference = function(name, value) {
Y.log('M.util.set_user_preference is deprecated. Please use the "core_user/repository" module instead.', 'warn');
require(['core_user/repository'], function(UserRepository) {
UserRepository.setUserPreference(name, value);
});
M.util.set_user_preference = function() {
throw new Error('M.util.set_user_preference is deprecated. Please use the "core_user/repository" module instead.');
};
/**
+1 -11
View File
@@ -1846,17 +1846,7 @@ class core_user_external extends \core_external\external_api {
try {
// Support legacy preferences from the old M.util.set_user_preference API (always using the current user).
if (isset($USER->ajax_updatable_user_prefs[$pref['name']])) {
debugging('Updating preferences via ajax_updatable_user_prefs is deprecated. ' .
'Please use the "core_user/repository" module instead.', DEBUG_DEVELOPER);
set_user_preference($pref['name'], $pref['value']);
$saved[] = array(
'name' => $pref['name'],
'userid' => $USER->id,
);
} else if (core_user::can_edit_preference($pref['name'], $user)) {
if (core_user::can_edit_preference($pref['name'], $user)) {
$value = core_user::clean_preference($pref['value'], $pref['name']);
set_user_preference($pref['name'], $value, $user->id);
$saved[] = array(