-
Bug
-
Resolution: Fixed
-
Blocker
-
2.0.4, 2.1.1, 2.2
-
MySQL
-
MOODLE_20_STABLE, MOODLE_21_STABLE, MOODLE_22_STABLE
-
MOODLE_22_STABLE
-
w47_
MDL-27233_m22_restoreenrol -
Performing the restore of a course, from a teacher's perspective, flushs the role assignements. Permissions have been checked for the teacher to attribute role assignements to users in a restore process.
Steps to replicate the bug :
1- As administrator, Create an "empty course" for the test
2- Assign another user as teacher of the course.
3- Log in as this user and perform a backup of the course. Assure that "Include enrolled users" and "Include user role assignments" are checked.
4- Perform the restore of the course. Choose "Delete the contents of this course and then restore" and continue.Assure that "Include enrolled users" and "Include user role assignments" are checked.
After restoring, its says "This course is currently unavailable to students".
If you go back as administrator, you can see that the user is still there but he is no more teacher of the course.
--------------------------------------------------------------------------
I dug the code a bit and found these things :
1- The function process_assignement
"/moodle/backup/moodle2/restore_stepslib.php" |
public function process_assignment($data) {
|
global $DB;
|
|
$data = (object)$data;
|
|
// Check roleid, userid are one of the mapped ones
|
if (!$newroleid = $this->get_mappingid('role', $data->roleid)) {
|
return;
|
}
|
|
...
|
The method get_mappingid returns 0 when it should return 3 and so the assignment fails.
get_mappingid is checking on the column newitemid of the temporary table backup_ids_temp. If I output the table content, I can clearly see that it is effectively set to 0.
"backup_ids_temp content" |
...
|
|
[8] => stdClass Object ( [id] => 8 [backupid] => c07aa265cba1cccd0e58119906ca6576 [itemname] => role [itemid] => 3 [newitemid]=> 0
|
|
...
|
2- The functions that affect the content of the table "backup_ids_temp"
"/moodle/backup/util/dbops/restore_dbops.php" |
protected static function get_best_assignable_role($role, $courseid, $userid, $samesite) {
|
global $CFG, $DB;
|
|
// Gather various information about roles
|
$coursectx = get_context_instance(CONTEXT_COURSE, $courseid);
|
$allroles = $DB->get_records('role');
|
$assignablerolesshortname = get_assignable_roles($coursectx, ROLENAME_SHORT, false, $userid);
|
|
...
|
get_assignable_roles returns an empty array of role.
I think the problem may be that the role assignments are deleted before the call to the function, so the match can't be done.
Hope it helps!
- is blocked by
-
MDL-29466 Backup: "Include user role assignments" box has no effect
-
- Closed
-
- is duplicated by
-
MDL-28063 Backup: Unable to download courses from MOOCH when teacher deletes contents of course and then restores
-
- Closed
-
-
MDL-29988 Restore option to allow instructors to replace course content
-
- Closed
-
- will be (partly) resolved by
-
MDL-29450 remove_course_contents() BC and other improvements...
-
- Closed
-
- will help resolve
-
MDL-27141 Perform the restore of a course as a teacher breaks the course in Moodle
-
- Closed
-