Skip to content

Commit

Permalink
MDL-58702 backup: Fix restoration of role mappings labels
Browse files Browse the repository at this point in the history
Changes:
- Add logic to retrieve all the existing current roles.
- Apply the backup's role shortname by matching on the archetype.
- Added backup lang string 'undefinedrolemapping'.
  • Loading branch information
zig-moodle committed Jun 15, 2018
1 parent 9e7c397 commit e689e4d
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
21 changes: 20 additions & 1 deletion backup/util/ui/restore_ui_stage.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,26 @@ public function display(core_backup_renderer $renderer) {
if (!empty($info->role_mappings->mappings)) {
$context = context_course::instance($this->ui->get_controller()->get_courseid());
$assignableroles = get_assignable_roles($context, ROLENAME_ALIAS, false);
$html .= $renderer->role_mappings($info->role_mappings->mappings, $assignableroles);

// Get current role mappings.
$currentroles = role_fix_names(get_all_roles(), $context);
// Get backup role mappings.
$rolemappings = $info->role_mappings->mappings;

array_map(function($rolemapping) use ($currentroles) {
foreach ($currentroles as $role) {
// Find matching archetype to determine the backup's shortname for label display.
if ($rolemapping->archetype == $role->archetype) {
$rolemapping->name = $rolemapping->shortname;
break;
}
}
if ($rolemapping->name == null) {
$rolemapping->name = get_string('undefinedrolemapping', 'backup', $rolemapping->archetype);
}
}, $rolemappings);

$html .= $renderer->role_mappings($rolemappings, $assignableroles);
}
break;
default:
Expand Down
1 change: 1 addition & 0 deletions lang/en/backup.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
$string['title'] = 'Title';
$string['totalcategorysearchresults'] = 'Total categories: {$a}';
$string['totalcoursesearchresults'] = 'Total courses: {$a}';
$string['undefinedrolemapping'] = 'Role mapping undefined for: \'{$a}\' archetype';
$string['unnamedsection'] = 'Unnamed section';
$string['userinfo'] = 'Userinfo';
$string['module'] = 'Module';
Expand Down

0 comments on commit e689e4d

Please sign in to comment.