From e689e4d446013bdbf96530ab3b17ac9dae3cc87b Mon Sep 17 00:00:00 2001 From: Zig Tan Date: Fri, 15 Jun 2018 09:46:29 +0800 Subject: [PATCH] MDL-58702 backup: Fix restoration of role mappings labels 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'. --- backup/util/ui/restore_ui_stage.class.php | 21 ++++++++++++++++++++- lang/en/backup.php | 1 + 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/backup/util/ui/restore_ui_stage.class.php b/backup/util/ui/restore_ui_stage.class.php index 2ff89e64305..bc09bc531fe 100644 --- a/backup/util/ui/restore_ui_stage.class.php +++ b/backup/util/ui/restore_ui_stage.class.php @@ -1061,7 +1061,26 @@ class restore_ui_stage_process extends restore_ui_stage { 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: diff --git a/lang/en/backup.php b/lang/en/backup.php index dc711e84279..abaf88e7859 100644 --- a/lang/en/backup.php +++ b/lang/en/backup.php @@ -326,6 +326,7 @@ $string['timetaken'] = 'Time taken'; $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';