MDL-58684 files: Ensure stored_file never serializes the file_storage

Magic methods __sleep and __wakeup used to properly store only the
file_record property and to reinit using get_file_storage().
This commit is contained in:
Jake Dallimore 2017-05-08 11:12:39 +08:00
parent ac6b845de7
commit e927581a50

View File

@ -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
*