Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

Core file system class definition.

Copyright: 2017 Andrew Nicols <andrew@nicols.co.uk>
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 498 lines (18 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class


Class: file_system_filedir  - X-Ref

File system class used for low level access to real files in filedir.

__construct()   X-Ref
Perform any custom setup for this type of file_system.


get_local_path_from_hash($contenthash, $fetchifnotfound = false)   X-Ref
Get the full path for the specified hash, including the path to the filedir.

param: string $contenthash The content hash
param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.
return: string The full path to the content file

get_local_path_from_storedfile(stored_file $file, $fetchifnotfound = false)   X-Ref
Get a remote filepath for the specified stored file.

param: stored_file $file The file to fetch the path for
param: bool $fetchifnotfound Whether to attempt to fetch from the remote path if not found.
return: string The full path to the content file

get_remote_path_from_storedfile(stored_file $file)   X-Ref
Get a remote filepath for the specified stored file.

param: stored_file $file The file to serve.
return: string full path to pool file with file content

get_remote_path_from_hash($contenthash)   X-Ref
Get the full path for the specified hash, including the path to the filedir.

param: string $contenthash The content hash
return: string The full path to the content file

get_fulldir_from_storedfile(stored_file $file)   X-Ref
Get the full directory to the stored file, including the path to the
filedir, and the directory which the file is actually in.

Note: This function does not ensure that the file is present on disk.

param: stored_file $file The file to fetch details for.
return: string The full path to the content directory

get_fulldir_from_hash($contenthash)   X-Ref
Get the full directory to the stored file, including the path to the
filedir, and the directory which the file is actually in.

param: string $contenthash The content hash
return: string The full path to the content directory

get_contentdir_from_hash($contenthash)   X-Ref
Get the content directory for the specified content hash.
This is the directory that the file will be in, but without the
fulldir.

param: string $contenthash The content hash
return: string The directory within filedir

get_contentpath_from_hash($contenthash)   X-Ref
Get the content path for the specified content hash within filedir.

This does not include the filedir, and is often used by file systems
as the object key for storage and retrieval.

param: string $contenthash The content hash
return: string The filepath within filedir

get_trash_fulldir_from_hash($contenthash)   X-Ref
Get the full directory for the specified hash in the trash, including the path to the
trashdir, and the directory which the file is actually in.

param: string $contenthash The content hash
return: string The full path to the trash directory

get_trash_fullpath_from_hash($contenthash)   X-Ref
Get the full path for the specified hash in the trash, including the path to the trashdir.

param: string $contenthash The content hash
return: string The full path to the trash file

copy_content_from_storedfile(stored_file $file, $target)   X-Ref
Copy content of file to given pathname.

param: stored_file $file The file to be copied
param: string $target real path to the new file
return: bool success

recover_file(stored_file $file)   X-Ref
Tries to recover missing content of file from trash.

param: stored_file $file stored_file instance
return: bool success

remove_file($contenthash)   X-Ref
Marks pool file as candidate for deleting.

param: string $contenthash

cron()   X-Ref
Cleanup the trash directory.


empty_trash()   X-Ref
No description

add_file_from_path($pathname, $contenthash = null)   X-Ref
Add the supplied file to the file system.

Note: If overriding this function, it is advisable to store the file
in the path returned by get_local_path_from_hash as there may be
subsequent uses of the file in the same request.

param: string $pathname Path to file currently on disk
param: string $contenthash SHA1 hash of content if known (performance only)
return: array (contenthash, filesize, newfile)

add_file_from_string($content)   X-Ref
Add a file with the supplied content to the file system.

Note: If overriding this function, it is advisable to store the file
in the path returned by get_local_path_from_hash as there may be
subsequent uses of the file in the same request.

param: string $content file content - binary string
return: array (contenthash, filesize, newfile)