Skip to content

Commit

Permalink
Merge pull request #558 from catalyst/metadata-on-upload-33
Browse files Browse the repository at this point in the history
Add location metadata on upload (3.3 stable) #554
  • Loading branch information
brendanheywood committed Apr 12, 2023
2 parents dc063a7 + 6326dc8 commit 6dfb6fe
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
36 changes: 36 additions & 0 deletions classes/local/store/object_file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

}
4 changes: 2 additions & 2 deletions version.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2021122307; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021122307; // Same as version.
$plugin->version = 2021122308; // The current plugin version (Date: YYYYMMDDXX).
$plugin->release = 2021122308; // Same as version.
$plugin->requires = 2013111811; // Requires Filesystem API.
$plugin->component = "tool_objectfs";
$plugin->maturity = MATURITY_STABLE;
Expand Down

0 comments on commit 6dfb6fe

Please sign in to comment.