mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 00:12:56 +02:00
MDL-40097 completion: Apply robust role detection to samesite restores.
This commit is contained in:
parent
a43f43e2fa
commit
1151210154
@ -2528,25 +2528,27 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
|
||||
// Map the role from the criteria
|
||||
if (isset($data->role) && $data->role != '') {
|
||||
|
||||
// If same site use the same role id, otherwise try calculate it.
|
||||
if (!$this->task->is_samesite()) {
|
||||
// Newer backups should include roleshortname, which makes this much easier.
|
||||
if (!empty($data->roleshortname)) {
|
||||
$roleinstanceid = $DB->get_field('role', 'id', array('shortname' => $data->roleshortname));
|
||||
if (!$roleinstanceid) {
|
||||
debugging('Could not match the role shortname in course_completion_criteria, so skipping');
|
||||
return;
|
||||
}
|
||||
$data->role = $roleinstanceid;
|
||||
} else {
|
||||
$data->role = $this->get_mappingid('role', $data->role);
|
||||
// Newer backups should include roleshortname, which makes this much easier.
|
||||
if (!empty($data->roleshortname)) {
|
||||
$roleinstanceid = $DB->get_field('role', 'id', array('shortname' => $data->roleshortname));
|
||||
if (!$roleinstanceid) {
|
||||
$this->log(
|
||||
'Could not match the role shortname in course_completion_criteria, so skipping',
|
||||
backup::LOG_DEBUG
|
||||
);
|
||||
return;
|
||||
}
|
||||
$data->role = $roleinstanceid;
|
||||
} else {
|
||||
$data->role = $this->get_mappingid('role', $data->role);
|
||||
}
|
||||
|
||||
// Check we have an id, otherwise it causes all sorts of bugs.
|
||||
if (!$data->role) {
|
||||
debugging('Could not match role in course_completion_criteria, so skipping');
|
||||
$this->log(
|
||||
'Could not match role in course_completion_criteria, so skipping',
|
||||
backup::LOG_DEBUG
|
||||
);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@ -2556,7 +2558,10 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
if (!empty($data->moduleinstance) && !empty($data->module)) {
|
||||
$data->moduleinstance = $this->get_mappingid('course_module', $data->moduleinstance);
|
||||
if (empty($data->moduleinstance)) {
|
||||
debugging('Could not match the module instance in course_completion_criteria, so skipping');
|
||||
$this->log(
|
||||
'Could not match the module instance in course_completion_criteria, so skipping',
|
||||
backup::LOG_DEBUG
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
@ -2568,7 +2573,10 @@ class restore_course_completion_structure_step extends restore_structure_step {
|
||||
if (!empty($data->courseinstanceshortname)) {
|
||||
$courseinstanceid = $DB->get_field('course', 'id', array('shortname'=>$data->courseinstanceshortname));
|
||||
if (!$courseinstanceid) {
|
||||
debugging('Could not match the course instance in course_completion_criteria, so skipping');
|
||||
$this->log(
|
||||
'Could not match the course instance in course_completion_criteria, so skipping',
|
||||
backup::LOG_DEBUG
|
||||
);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
|
Loading…
x
Reference in New Issue
Block a user