From 51d31432c875644abfcaee8f9fe2e32e9481ab0c Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Tue, 23 Jan 2018 09:48:05 +0800 Subject: [PATCH] MDL-61253 repository: Add referenced files to archives --- lib/filestorage/stored_file.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index c1a4254c8f0..0f67664bdfb 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -537,6 +537,18 @@ class stored_file { * @return bool success */ public function archive_file(file_archive $filearch, $archivepath) { + if ($this->repository) { + $this->sync_external_file(); + if ($this->compare_to_string('')) { + // This file is not stored locally - attempt to retrieve it from the repository. + // This may happen if the repository deliberately does not fetch files, or if there is a failure with the sync. + $fileinfo = $this->repository->get_file($this->get_reference()); + if (isset($fileinfo['path'])) { + return $filearch->add_file_from_pathname($archivepath, $fileinfo['path']); + } + } + } + return $this->filesystem->add_storedfile_to_archive($this, $filearch, $archivepath); }