$foundfile = reset($foundfiles);
$fs->create_file_from_storedfile($file_record, $foundfile->id);
} else {
- // Finally try to restore the file from trash.
- $filesytem = $fs->get_file_system();
+ $filesystem = $fs->get_file_system();
$restorefile = $file;
$restorefile->contextid = $newcontextid;
$storedfile = new stored_file($fs, $restorefile);
- $trashrecovery = $filesytem->recover_file($storedfile, true);
- if (!$trashrecovery) {
+
+ // Ok, let's try recover this file.
+ // 1. We check if the file can be fetched locally without attempting to fetch
+ // from the trash.
+ // 2. We check if we can get the remote filepath for the specified stored file.
+ // 3. We check if the file can be fetched from the trash.
+ // 4. All failed, say we couldn't find it.
+ if ($filesystem->is_file_readable_locally_by_storedfile($storedfile)) {
+ $localpath = $filesystem->get_local_path_from_storedfile($storedfile);
+ $fs->create_file_from_pathname($file, $localpath);
+ } else if ($filesystem->is_file_readable_remotely_by_storedfile($storedfile)) {
+ $url = $filesystem->get_remote_path_from_storedfile($storedfile);
+ $fs->create_file_from_url($file, $url);
+ } else if ($filesystem->is_file_readable_locally_by_storedfile($storedfile, true)) {
+ $localpath = $filesystem->get_local_path_from_storedfile($storedfile, true);
+ $fs->create_file_from_pathname($file, $localpath);
+ } else {
// A matching file was not found.
$results[] = self::get_missing_file_result($file);
continue;
* @param bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.
* @return string full path to pool file with file content
*/
- protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) {
+ public function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) {
return $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound);
}
* @param stored_file $file The file to serve.
* @return string full path to pool file with file content
*/
- protected function get_remote_path_from_storedfile(stored_file $file) {
+ public function get_remote_path_from_storedfile(stored_file $file) {
return $this->get_remote_path_from_hash($file->get_contenthash(), false);
}
* @param bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.
* @return string The full path to the content file
*/
- protected function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) {
+ public function get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false) {
$filepath = $this->get_local_path_from_hash($file->get_contenthash(), $fetchifnotfound);
// Try content recovery.
* @param stored_file $file The file to serve.
* @return string full path to pool file with file content
*/
- protected function get_remote_path_from_storedfile(stored_file $file) {
+ public function get_remote_path_from_storedfile(stored_file $file) {
return $this->get_local_path_from_storedfile($file, false);
}
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>$pathhash)));
- $method = new ReflectionMethod('file_system', 'get_local_path_from_storedfile');
- $method->setAccessible(true);
$filesystem = $fs->get_file_system();
- $location = $method->invokeArgs($filesystem, array($file, true));
+ $location = $filesystem->get_local_path_from_storedfile($file, true);
$this->assertFileExists($location);
$this->assertTrue($DB->record_exists('files', array('pathnamehash'=>$pathhash)));
- $method = new ReflectionMethod('file_system', 'get_local_path_from_storedfile');
- $method->setAccessible(true);
$filesystem = $fs->get_file_system();
- $location = $method->invokeArgs($filesystem, array($file, true));
+ $location = $filesystem->get_local_path_from_storedfile($file, true);
$this->assertFileExists($location);
->with($this->equalTo($file));
$file = $this->get_stored_file('example content');
- $method = new ReflectionMethod(file_system_filedir::class, 'get_local_path_from_storedfile');
- $method->setAccessible(true);
- $result = $method->invokeArgs($fs, array($file, true));
+ $result = $fs->get_local_path_from_storedfile($file, true);
$this->assertEquals($filepath, $result);
}
->method('recover_file');
$file = $this->get_stored_file('example content');
- $method = new ReflectionMethod(file_system_filedir::class, 'get_local_path_from_storedfile');
- $method->setAccessible(true);
- $result = $method->invokeArgs($fs, array($file, false));
+ $result = $fs->get_local_path_from_storedfile($file, false);
$this->assertEquals($filepath, $result);
}
$file = $this->get_stored_file($filecontent);
- $method = new ReflectionMethod(file_system::class, 'get_local_path_from_storedfile');
- $method->setAccessible(true);
- $result = $method->invokeArgs($fs, array_merge([$file], $args));
+ $result = $fs->get_local_path_from_storedfile($file, $fetch);
$this->assertEquals($filepath, $result);
}
$file = $this->get_stored_file($filecontent);
- $method = new ReflectionMethod(file_system::class, 'get_remote_path_from_storedfile');
- $method->setAccessible(true);
- $result = $method->invokeArgs($fs, [$file]);
+ $result = $fs->get_remote_path_from_storedfile($file);
$this->assertEquals($filepath, $result);
}
at least a single checkbox item is selected or not.
* Final deprecation (removal) of the core/modal_confirm dialogue.
* Upgrade scssphp to v1.0.2, This involves renaming classes from Leafo => ScssPhp as the repo has changed.
+* The methods get_local_path_from_storedfile and get_remote_path_from_storedfile in lib/filestore/file_system.php
+ are now public. If you are overriding these then you will need to change your methods to public in your class.
=== 3.7 ===