From 7bac7a66de8ed4447b24168011dc59bc1a4dab8d Mon Sep 17 00:00:00 2001 From: Brendan Heywood Date: Wed, 22 Mar 2023 18:17:29 +1100 Subject: [PATCH] Add location metadata on upload #554 --- classes/local/store/object_file_system.php | 36 ++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/classes/local/store/object_file_system.php b/classes/local/store/object_file_system.php index 16f2f210..179f011a 100644 --- a/classes/local/store/object_file_system.php +++ b/classes/local/store/object_file_system.php @@ -995,4 +995,40 @@ protected function get_trash_fullpath_from_hash($contenthash) { debugging('Objectfs does not implement a trashdir.'); return ''; } + + /** + * Add the supplied file to the file system and update its location. + * + * @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) + */ + public function add_file_from_path($pathname, $contenthash = null) { + $result = parent::add_file_from_path($pathname, $contenthash); + + // Rather than getting its exact location we just set it to local. + // Almost all file uploads will be unique, and if it is a duplicate + // then this will be corrected when the file is synced later. + manager::update_object_by_hash($result[0], OBJECT_LOCATION_LOCAL, $result[1]); + + return $result; + } + + /** + * Add a file with the supplied content to the file system and update its location. + * + * @param string $content file content - binary string + * @return array (contenthash, filesize, newfile) + */ + public function add_file_from_string($content) { + $result = parent::add_file_from_string($content); + + // Rather than getting its exact location we just set it to local. + // Almost all file uploads will be unique, and if it is a duplicate + // then this will be corrected when the file is synced later. + manager::update_object_by_hash($result[0], OBJECT_LOCATION_LOCAL, $result[1]); + + return $result; + } + }