mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 08:56:36 +02:00
MDL-71107 core_contentbank: Fill content author when copying a course
'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.
This commit is contained in:
parent
89cab88a3a
commit
78a10f1724
1 changed files with 23 additions and 2 deletions
|
@ -4065,9 +4065,30 @@ class restore_contentbankcontent_structure_step extends restore_structure_step {
|
|||
$exists = $DB->record_exists('contentbank_content', $params);
|
||||
if (!$exists) {
|
||||
$params['configdata'] = $data->configdata;
|
||||
$params['usercreated'] = $this->get_mappingid('user', $data->usercreated);
|
||||
$params['usermodified'] = $this->get_mappingid('user', $data->usermodified);
|
||||
$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);
|
||||
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);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue