Moodle

Course restore causes role names to go missing

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Won't Fix
  • Affects Version/s: 1.9.1
  • Fix Version/s: None
  • Component/s: Backup, Roles / Access
  • Labels:
    None
  • Affected Branches:
    MOODLE_19_STABLE

Description

I just restored a course but found that the switch role dropdown now shows numbers instead of some of the role names. Its just in this course, not the whole site, and if I go to the assign roles page in the course, those roles have brackets around them.

Activity

Hide
Jacques Monnard added a comment -

This is probably the same bug : when you try to reset a restored course showing the above problem, some role names in the "Roles" list are empty.

Now if you go to "Administration/Settings" in the course, and save the page without changing anything, the problem is resolved : role names appear again, and brackets disappear in the assign roles page!

Btw., I'm using the latest weekly version (1.9.1+, 20080611).

Show
Jacques Monnard added a comment - This is probably the same bug : when you try to reset a restored course showing the above problem, some role names in the "Roles" list are empty. Now if you go to "Administration/Settings" in the course, and save the page without changing anything, the problem is resolved : role names appear again, and brackets disappear in the assign roles page! Btw., I'm using the latest weekly version (1.9.1+, 20080611).
Hide
Jacques Monnard added a comment -

I did some additional tests. I used the 1.9.1 install at opensourcecms.com, to make sure that it wasn't my installation causing problems. Here is what I found out :

1. Backup an empty course with default options, and restore it in a new course, also with default options selected. Everything works ok.

2. In the original course, do a single role assignment (e.g. add a teacher). Now if you try the same backup/restore procedure, the "teacher" role will appear as a number in the "Switch role" dropdown, as empty in "Reset", and between brackets in "Assign roles".

If you assign students, the same problem with happen with the "Student" role.

So it seems that as soon as a role has been assigned to a person, the backup/restore process does something different with the role.

Show
Jacques Monnard added a comment - I did some additional tests. I used the 1.9.1 install at opensourcecms.com, to make sure that it wasn't my installation causing problems. Here is what I found out : 1. Backup an empty course with default options, and restore it in a new course, also with default options selected. Everything works ok. 2. In the original course, do a single role assignment (e.g. add a teacher). Now if you try the same backup/restore procedure, the "teacher" role will appear as a number in the "Switch role" dropdown, as empty in "Reset", and between brackets in "Assign roles". If you assign students, the same problem with happen with the "Student" role. So it seems that as soon as a role has been assigned to a person, the backup/restore process does something different with the role.
Hide
Matt Gibson added a comment -

Yup, saving the settings page fixed it. Thanks for the tip.

Show
Matt Gibson added a comment - Yup, saving the settings page fixed it. Thanks for the tip.
Hide
Jacques Monnard added a comment -

Apparently, the code responsible for recreating custom role names in courses (backup/restorelib.php, lines 8352-8366) doesn't check whether a custom name has been defined for a role before creating it! And this causes the problem : if there is no custom name for a role, there is also no corresponding value NAMEINCOURSE in the backup. So the two statements

$rolename->name = addslashes($roledata->nameincourse);
insert_record('role_names', $rolename);

make no sense in such a case, as they just create a record with an empty name in the role_names table.
And this causes the problems mentioned above.

Going to the course settings page and saving it solves the problem, because the code then notices that custom role names are empty, and deletes the invalid entries from the role_names table.

Enclosing the above block of code in a "if (!empty($roledata->nameincourse))" statement should solve this, but I don't know if it has any side effects on the rest of the role creation process.

Show
Jacques Monnard added a comment - Apparently, the code responsible for recreating custom role names in courses (backup/restorelib.php, lines 8352-8366) doesn't check whether a custom name has been defined for a role before creating it! And this causes the problem : if there is no custom name for a role, there is also no corresponding value NAMEINCOURSE in the backup. So the two statements $rolename->name = addslashes($roledata->nameincourse); insert_record('role_names', $rolename); make no sense in such a case, as they just create a record with an empty name in the role_names table. And this causes the problems mentioned above. Going to the course settings page and saving it solves the problem, because the code then notices that custom role names are empty, and deletes the invalid entries from the role_names table. Enclosing the above block of code in a "if (!empty($roledata->nameincourse))" statement should solve this, but I don't know if it has any side effects on the rest of the role creation process.
Hide
Mary Parke added a comment -

We're having the same problem. This role-breaking occurs from courses backed up in Moodle 1.8.2+ (2007021520) and restored in Moodle 1.9.1+ (Build: 20080617). Bracketed roles do not function properly within the restored course. The oddity is that even if during the restore process all user data is set to Null or None (user data, users, user files, etc.) this still causes the roles to break in the restored course. Also, sometimes in the restore process the roles mapping section appears (to map legacy to new default roles) and sometimes it doesn't - even though all the backups were created the same way on the 1.8.2+ version.

Once the 1.8.2+ course is restored in the 1.9.1 version, with the roles breaking, even if a new backup is created of the course as it is in 1.9.1 and attempted to be restored in 1.9.1 - the roles inherit this breaking. There seems to be no way of ridding the broken roles from the restored course - especially if they are default site roles such as Teacher or Student.

I would elevate this issue to a PRIORITY as this is causing our development process on our site to fail - we can't migrate our courses from 1.8.2+ to our new 1.9.1 version of Moodle.

For more information on this in detail and/or backup files to test along with the restore logs we've captured for broken roles upon restore, please contact me at mparke at ccsf dot edu.

Many thanks,

Mary

Show
Mary Parke added a comment - We're having the same problem. This role-breaking occurs from courses backed up in Moodle 1.8.2+ (2007021520) and restored in Moodle 1.9.1+ (Build: 20080617). Bracketed roles do not function properly within the restored course. The oddity is that even if during the restore process all user data is set to Null or None (user data, users, user files, etc.) this still causes the roles to break in the restored course. Also, sometimes in the restore process the roles mapping section appears (to map legacy to new default roles) and sometimes it doesn't - even though all the backups were created the same way on the 1.8.2+ version. Once the 1.8.2+ course is restored in the 1.9.1 version, with the roles breaking, even if a new backup is created of the course as it is in 1.9.1 and attempted to be restored in 1.9.1 - the roles inherit this breaking. There seems to be no way of ridding the broken roles from the restored course - especially if they are default site roles such as Teacher or Student. I would elevate this issue to a PRIORITY as this is causing our development process on our site to fail - we can't migrate our courses from 1.8.2+ to our new 1.9.1 version of Moodle. For more information on this in detail and/or backup files to test along with the restore logs we've captured for broken roles upon restore, please contact me at mparke at ccsf dot edu. Many thanks, Mary
Hide
Jeffrey Silverman added a comment -

Howdy. I used Jacques' suggestion and indeed it does appear to work. Here is a code snippet. (I try to be extra clear what is added and where)

// CODE SNIPPET (approximately lines 8356-8362):

$rolename->roleid = $newrole->new_id;
$rolename->contextid = $coursecontext->id;
$rolename->name = addslashes($roledata->nameincourse);
// THIS LINE WAS ADDED
if (!empty($roledata->nameincourse)){ insert_record('role_names', $rolename); // THIS LINE WAS ADDED }
// END SNIPPET

I only put the if() around the line that adds the record.

Warning: I did not test this against a course restore with a named custom role for that course. I.e. a situation where the row in mdl_role_names should be created.

Thanks! See you all later...

Show
Jeffrey Silverman added a comment - Howdy. I used Jacques' suggestion and indeed it does appear to work. Here is a code snippet. (I try to be extra clear what is added and where) // CODE SNIPPET (approximately lines 8356-8362): $rolename->roleid = $newrole->new_id; $rolename->contextid = $coursecontext->id; $rolename->name = addslashes($roledata->nameincourse); // THIS LINE WAS ADDED if (!empty($roledata->nameincourse)){ insert_record('role_names', $rolename); // THIS LINE WAS ADDED } // END SNIPPET I only put the if() around the line that adds the record. Warning: I did not test this against a course restore with a named custom role for that course. I.e. a situation where the row in mdl_role_names should be created. Thanks! See you all later...
Hide
Jeffrey Silverman added a comment -

Hey, to be more technical, here is a diff

@@ -8357,9 +8357,8 @@
$rolename->roleid = $newrole->new_id;
$rolename->contextid = $coursecontext->id;
$rolename->name = addslashes($roledata->nameincourse);

  • if (!empty($roledata->nameincourse)){ - insert_record('role_names', $rolename); - }
    +
    + insert_record('role_names', $rolename);
    }
    }
    }

Thank you have a nice day

Show
Jeffrey Silverman added a comment - Hey, to be more technical, here is a diff @@ -8357,9 +8357,8 @@ $rolename->roleid = $newrole->new_id; $rolename->contextid = $coursecontext->id; $rolename->name = addslashes($roledata->nameincourse);
  • if (!empty($roledata->nameincourse)){ - insert_record('role_names', $rolename); - } + + insert_record('role_names', $rolename); } } }
Thank you have a nice day
Hide
Jeffrey Silverman added a comment -

Ugh!! I reversed the input file order. Sorry. New diff:

@@ -8357,8 +8357,9 @@
$rolename->roleid = $newrole->new_id;
$rolename->contextid = $coursecontext->id;
$rolename->name = addslashes($roledata->nameincourse);
-

  • insert_record('role_names', $rolename);
    + if (!empty($roledata->nameincourse)){ + insert_record('role_names', $rolename); + }
    }
    }
    }
Show
Jeffrey Silverman added a comment - Ugh!! I reversed the input file order. Sorry. New diff: @@ -8357,8 +8357,9 @@ $rolename->roleid = $newrole->new_id; $rolename->contextid = $coursecontext->id; $rolename->name = addslashes($roledata->nameincourse); -
  • insert_record('role_names', $rolename); + if (!empty($roledata->nameincourse)){ + insert_record('role_names', $rolename); + } } } }
Hide
Steve Bond added a comment -

This appears to be fixed in Moodle 2.0. I backed up and restored a course and the role names all seemed to be OK afterwards.

Show
Steve Bond added a comment - This appears to be fixed in Moodle 2.0. I backed up and restored a course and the role names all seemed to be OK afterwards.
Hide
Michael de Raadt added a comment -

Thanks for reporting this issue.

We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported.

If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed.

Michael d;

lqjjLKA0p6

Show
Michael de Raadt added a comment - Thanks for reporting this issue. We have detected that this issue has been inactive for over a year has been recorded as affecting versions that are no longer supported. If you believe that this issue is still relevant to current versions (2.1 and beyond), please comment on the issue. Issues left inactive for a further month will be closed. Michael d; lqjjLKA0p6
Hide
Michael de Raadt added a comment -

I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Show
Michael de Raadt added a comment - I'm closing this issue as it appears to have become inactive and is probably not relevant to a current supported version. If you are encountering this problem or one similar, please launch a new issue.

Dates

  • Created:
    Updated:
    Resolved: