diff --git a/lib/filestorage/stored_file.php b/lib/filestorage/stored_file.php index f27f082d05f..9655d01b4f3 100644 --- a/lib/filestorage/stored_file.php +++ b/lib/filestorage/stored_file.php @@ -93,6 +93,24 @@ class stored_file { $this->filesystem = $fs->get_file_system(); } + /** + * Magic method, called during serialization. + * + * @return array + */ + public function __sleep() { + // We only ever want the file_record saved, not the file_storage object. + return ['file_record']; + } + + /** + * Magic method, called during unserialization. + */ + public function __wakeup() { + // Recreate our stored_file based on the file_record, and using file storage retrieved the correct way. + $this->__construct(get_file_storage(), $this->file_record); + } + /** * Whether or not this is a external resource *