Commit bdffbe3e authored by Mathew May's avatar Mathew May
Browse files

MDL-65799 enrol: Final deprecations

parent 072311e9
......@@ -1029,122 +1029,6 @@ class core_enrol_external extends external_api {
);
}
/**
* Returns description of edit_user_enrolment() parameters
*
* @deprecated since 3.8
* @return external_function_parameters
*/
public static function edit_user_enrolment_parameters() {
return new external_function_parameters(
array(
'courseid' => new external_value(PARAM_INT, 'User enrolment ID'),
'ueid' => new external_value(PARAM_INT, 'User enrolment ID'),
'status' => new external_value(PARAM_INT, 'Enrolment status'),
'timestart' => new external_value(PARAM_INT, 'Enrolment start timestamp', VALUE_DEFAULT, 0),
'timeend' => new external_value(PARAM_INT, 'Enrolment end timestamp', VALUE_DEFAULT, 0),
)
);
}
/**
* External function that updates a given user enrolment.
*
* @deprecated since 3.8
* @param int $courseid The course ID.
* @param int $ueid The user enrolment ID.
* @param int $status The enrolment status.
* @param int $timestart Enrolment start timestamp.
* @param int $timeend Enrolment end timestamp.
* @return array An array consisting of the processing result, errors and form output, if available.
*/
public static function edit_user_enrolment($courseid, $ueid, $status, $timestart = 0, $timeend = 0) {
global $CFG, $DB, $PAGE;
$params = self::validate_parameters(self::edit_user_enrolment_parameters(), [
'courseid' => $courseid,
'ueid' => $ueid,
'status' => $status,
'timestart' => $timestart,
'timeend' => $timeend,
]);
$course = get_course($courseid);
$context = context_course::instance($course->id);
self::validate_context($context);
$userenrolment = $DB->get_record('user_enrolments', ['id' => $params['ueid']], '*', MUST_EXIST);
$userenroldata = [
'status' => $params['status'],
'timestart' => $params['timestart'],
'timeend' => $params['timeend'],
];
$result = false;
$errors = [];
// Validate data against the edit user enrolment form.
$instance = $DB->get_record('enrol', ['id' => $userenrolment->enrolid], '*', MUST_EXIST);
$plugin = enrol_get_plugin($instance->enrol);
require_once("$CFG->dirroot/enrol/editenrolment_form.php");
$customformdata = [
'ue' => $userenrolment,
'modal' => true,
'enrolinstancename' => $plugin->get_instance_name($instance)
];
$mform = new \enrol_user_enrolment_form(null, $customformdata, 'post', '', null, true, $userenroldata);
$mform->set_data($userenroldata);
$validationerrors = $mform->validation($userenroldata, null);
if (empty($validationerrors)) {
require_once($CFG->dirroot . '/enrol/locallib.php');
$manager = new course_enrolment_manager($PAGE, $course);
$result = $manager->edit_enrolment($userenrolment, (object)$userenroldata);
} else {
foreach ($validationerrors as $key => $errormessage) {
$errors[] = (object)[
'key' => $key,
'message' => $errormessage
];
}
}
return [
'result' => $result,
'errors' => $errors,
];
}
/**
* Returns description of edit_user_enrolment() result value
*
* @deprecated since 3.8
* @return external_description
*/
public static function edit_user_enrolment_returns() {
return new external_single_structure(
array(
'result' => new external_value(PARAM_BOOL, 'True if the user\'s enrolment was successfully updated'),
'errors' => new external_multiple_structure(
new external_single_structure(
array(
'key' => new external_value(PARAM_TEXT, 'The data that failed the validation'),
'message' => new external_value(PARAM_TEXT, 'The error message'),
)
), 'List of validation errors'
),
)
);
}
/**
* Mark the edit_user_enrolment web service as deprecated.
*
* @return bool
*/
public static function edit_user_enrolment_is_deprecated() {
return true;
}
/**
* Returns description of submit_user_enrolment_form parameters.
*
......
......@@ -1093,89 +1093,6 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase {
$this->assertEquals($timenow, $expecteduserlist['users'][1]['lastcourseaccess']);
}
/**
* Test for core_enrol_external::edit_user_enrolment().
*/
public function test_edit_user_enrolment() {
global $DB;
$this->resetAfterTest(true);
$datagen = $this->getDataGenerator();
/** @var enrol_manual_plugin $manualplugin */
$manualplugin = enrol_get_plugin('manual');
$this->assertNotNull($manualplugin);
$studentroleid = $DB->get_field('role', 'id', ['shortname' => 'student'], MUST_EXIST);
$teacherroleid = $DB->get_field('role', 'id', ['shortname' => 'editingteacher'], MUST_EXIST);
$course = $datagen->create_course();
$user = $datagen->create_user();
$teacher = $datagen->create_user();
$instanceid = null;
$instances = enrol_get_instances($course->id, true);
foreach ($instances as $inst) {
if ($inst->enrol == 'manual') {
$instanceid = (int)$inst->id;
break;
}
}
if (empty($instanceid)) {
$instanceid = $manualplugin->add_default_instance($course);
if (empty($instanceid)) {
$instanceid = $manualplugin->add_instance($course);
}
}
$this->assertNotNull($instanceid);
$instance = $DB->get_record('enrol', ['id' => $instanceid], '*', MUST_EXIST);
$manualplugin->enrol_user($instance, $user->id, $studentroleid, 0, 0, ENROL_USER_ACTIVE);
$manualplugin->enrol_user($instance, $teacher->id, $teacherroleid, 0, 0, ENROL_USER_ACTIVE);
$ueid = (int)$DB->get_field(
'user_enrolments',
'id',
['enrolid' => $instance->id, 'userid' => $user->id],
MUST_EXIST
);
// Login as teacher.
$this->setUser($teacher);
$now = new DateTime();
$nowtime = $now->getTimestamp();
// Invalid data.
$data = core_enrol_external::edit_user_enrolment($course->id, $ueid, ENROL_USER_ACTIVE, $nowtime, $nowtime);
$data = external_api::clean_returnvalue(core_enrol_external::edit_user_enrolment_returns(), $data);
$this->assertFalse($data['result']);
$this->assertNotEmpty($data['errors']);
// Valid data.
$nextmonth = clone($now);
$nextmonth->add(new DateInterval('P1M'));
$nextmonthtime = $nextmonth->getTimestamp();
$data = core_enrol_external::edit_user_enrolment($course->id, $ueid, ENROL_USER_ACTIVE, $nowtime, $nextmonthtime);
$data = external_api::clean_returnvalue(core_enrol_external::edit_user_enrolment_returns(), $data);
$this->assertTrue($data['result']);
$this->assertEmpty($data['errors']);
// Check updated user enrolment.
$ue = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
$this->assertEquals(ENROL_USER_ACTIVE, $ue->status);
$this->assertEquals($nowtime, $ue->timestart);
$this->assertEquals($nextmonthtime, $ue->timeend);
// Suspend user.
$data = core_enrol_external::edit_user_enrolment($course->id, $ueid, ENROL_USER_SUSPENDED);
$data = external_api::clean_returnvalue(core_enrol_external::edit_user_enrolment_returns(), $data);
$this->assertTrue($data['result']);
$this->assertEmpty($data['errors']);
// Check updated user enrolment.
$ue = $DB->get_record('user_enrolments', ['id' => $ueid], '*', MUST_EXIST);
$this->assertEquals(ENROL_USER_SUSPENDED, $ue->status);
}
/**
* dataProvider for test_submit_user_enrolment_form().
*/
......
This files describes API changes in /enrol/* - plugins,
information provided here is intended especially for developers.
=== 4.0 ===
* Final deprecation of the following webservice:
* core_enrol_edit_user_enrolment
=== 3.11 ===
* Added onlysuspended option to core_enrol_get_enrolled_users webservice to retrieve only suspended users.
......
......@@ -768,15 +768,6 @@ $functions = array(
'capabilities' => 'moodle/course:viewparticipants',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_enrol_edit_user_enrolment' => array(
'classname' => 'core_enrol_external',
'methodname' => 'edit_user_enrolment',
'classpath' => 'enrol/externallib.php',
'description' => '** DEPRECATED ** Please do not call this function any more.
External function that updates a given user enrolment',
'type' => 'write',
'ajax' => true,
),
'core_enrol_submit_user_enrolment_form' => array(
'classname' => 'core_enrol_external',
'methodname' => 'submit_user_enrolment_form',
......
......@@ -2761,7 +2761,8 @@ function get_courses_page() {
*/
function report_insights_context_insights(\context $context) {
throw new coding_exception(
'Function report_insights_context_insights() has been removed. \core_analytics\manager::cached_models_with_insights instead'
'Function report_insights_context_insights() ' .
'has been removed. Please use \core_analytics\manager::cached_models_with_insights instead'
);
}
......
......@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2021110800.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2021110800.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '4.0dev+ (Build: 20211106)'; // Human-friendly version name
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment