Skip to content

Commit

Permalink
MDL-71107 core_contentbank: Fill content author when copying a course
Browse files Browse the repository at this point in the history
'usercreated' and 'usermodified' fields can not be always mapped.
We are filling those fields with 'old' users when working on the same
site, or with current user when working on a different instance.
  • Loading branch information
Amaia Anabitarte committed Apr 7, 2021
1 parent 18aafd0 commit 9b7b70c
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion backup/moodle2/restore_stepslib.php
Original file line number Diff line number Diff line change
Expand Up @@ -4065,9 +4065,30 @@ public function process_contentbankcontent($data) {
$exists = $DB->record_exists('contentbank_content', $params);
if (!$exists) {
$params['configdata'] = $data->configdata;
$params['timemodified'] = time();

// Trying to map users. Users cannot always be mapped, e.g. when copying.
$params['usercreated'] = $this->get_mappingid('user', $data->usercreated);
if (!$params['usercreated']) {
// Leave the content creator unchanged when we are restoring the same site.
// Otherwise use current user id.
if ($this->task->is_samesite()) {
$params['usercreated'] = $data->usercreated;
} else {
$params['usercreated'] = $this->task->get_userid();
}
}
$params['usermodified'] = $this->get_mappingid('user', $data->usermodified);
$params['timemodified'] = time();
if (!$params['usermodified']) {
// Leave the content modifier unchanged when we are restoring the same site.
// Otherwise use current user id.
if ($this->task->is_samesite()) {
$params['usermodified'] = $data->usermodified;
} else {
$params['usermodified'] = $this->task->get_userid();
}
}

$newitemid = $DB->insert_record('contentbank_content', $params);
$this->set_mapping('contentbank_content', $oldid, $newitemid, true);
}
Expand Down

0 comments on commit 9b7b70c

Please sign in to comment.