MDL-47178 question: Retain question authors when restoring backups.

This commit is contained in:
Mikhail Golenkov 2020-08-31 14:53:03 +10:00
parent c71355941b
commit 1f3aacf8fc
3 changed files with 203 additions and 6 deletions

View file

@ -4711,10 +4711,28 @@ class restore_create_categories_and_questions extends restore_structure_step {
}
$userid = $this->get_mappingid('user', $data->createdby);
$data->createdby = $userid ? $userid : $this->task->get_userid();
if ($userid) {
// The question creator is included in the backup, so we can use their mapping id.
$data->createdby = $userid;
} else {
// Leave the question creator unchanged when we are restoring the same site.
// Otherwise use current user id.
if (!$this->task->is_samesite()) {
$data->createdby = $this->task->get_userid();
}
}
$userid = $this->get_mappingid('user', $data->modifiedby);
$data->modifiedby = $userid ? $userid : $this->task->get_userid();
if ($userid) {
// The question modifier is included in the backup, so we can use their mapping id.
$data->modifiedby = $userid;
} else {
// Leave the question modifier unchanged when we are restoring the same site.
// Otherwise use current user id.
if (!$this->task->is_samesite()) {
$data->modifiedby = $this->task->get_userid();
}
}
// With newitemid = 0, let's create the question
if (!$questionmapping->newitemid) {