if (empty($file->repositoryid)) {
|
// create the file in the filepool if it does not exist yet
|
if (!$fs->file_exists($newcontextid, $component, $filearea, $rec->newitemid, $file->filepath, $file->filename)) {
|
//ADD THIS
|
if($copy_fileid = $DB->get_field('files','id',array('contenthash'=>$file->contenthash))){
|
$file_record = array(
|
'contextid' => $newcontextid,
|
'component' => $component,
|
'filearea' => $filearea,
|
'itemid' => $rec->newitemid,
|
'filepath' => $file->filepath,
|
'filename' => $file->filename,
|
'timecreated' => $file->timecreated,
|
'timemodified'=> $file->timemodified,
|
'userid' => $mappeduserid,
|
'author' => $file->author,
|
'license' => $file->license,
|
'sortorder' => $file->sortorder
|
);
|
$fs->create_file_from_storedfile($file_record, $copy_fileid);
|
} else {
|
// this is a regular file, it must be present in the backup pool
|
$backuppath = $basepath . backup_file_manager::get_backup_content_file_location($file->contenthash);
|
|
// The file is not found in the backup.
|
if (!file_exists($backuppath)) {
|
$result = new stdClass();
|
$result->code = 'file_missing_in_backup';
|
$result->message = sprintf('missing file %s%s in backup', $file->filepath, $file->filename);
|
$result->level = backup::LOG_WARNING;
|
$results[] = $result;
|
continue;
|
}
|
|
$file_record = array(
|
'contextid' => $newcontextid,
|
'component' => $component,
|
'filearea' => $filearea,
|
'itemid' => $rec->newitemid,
|
'filepath' => $file->filepath,
|
'filename' => $file->filename,
|
'timecreated' => $file->timecreated,
|
'timemodified'=> $file->timemodified,
|
'userid' => $mappeduserid,
|
'author' => $file->author,
|
'license' => $file->license,
|
'sortorder' => $file->sortorder
|
);
|
$fs->create_file_from_pathname($file_record, $backuppath);
|
}
|
}
|
|