From 100360f96cc027e111c326f8558b9771a2ec0fa5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 2 Jul 2013 11:01:04 +0100 Subject: [PATCH] MDL-40440 Backup: Skip files that already exist --- backup/util/dbops/restore_dbops.class.php | 34 +++++++++++++---------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/backup/util/dbops/restore_dbops.class.php b/backup/util/dbops/restore_dbops.class.php index 5146cfe73d9..e308baee6b3 100644 --- a/backup/util/dbops/restore_dbops.class.php +++ b/backup/util/dbops/restore_dbops.class.php @@ -949,21 +949,25 @@ abstract class restore_dbops { } else { // This backup does not include the files - they should be available in moodle filestorage already. - // Even if a file has been deleted since the backup was made, the file metadata will remain in the - // files table, and the file will not be moved to the trashdir. - // Files are not cleared from the files table by cron until several days after deletion. - if ($foundfiles = $DB->get_records('files', array('contenthash' => $file->contenthash))) { - // Only grab one of the foundfiles - the file content should be the same for all entries. - $foundfile = reset($foundfiles); - $fs->create_file_from_storedfile($file_record, $foundfile->id); - } else { - // A matching existing file record was not found in the database. - $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; + // 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)) { + + // Even if a file has been deleted since the backup was made, the file metadata will remain in the + // files table, and the file will not be moved to the trashdir. + // Files are not cleared from the files table by cron until several days after deletion. + if ($foundfiles = $DB->get_records('files', array('contenthash' => $file->contenthash))) { + // Only grab one of the foundfiles - the file content should be the same for all entries. + $foundfile = reset($foundfiles); + $fs->create_file_from_storedfile($file_record, $foundfile->id); + } else { + // A matching existing file record was not found in the database. + $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; + } } } -- 2.43.0