Skip to content

Commit

Permalink
fix: ensure proper lock release and error handling in objectfs manipu…
Browse files Browse the repository at this point in the history
…lator
  • Loading branch information
Vithusha Kethiri committed Jan 21, 2025
1 parent 0c2b62d commit 9762b1f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions classes/local/object_manipulator/manipulator.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,19 @@ public function execute(array $objectrecords) {
continue;
}

$newlocation = $this->manipulate_object($objectrecord);
if (!empty($objectrecord->id)) {
manager::upsert_object($objectrecord, $newlocation);
} else {
manager::update_object_by_hash($objectrecord->contenthash, $newlocation);
try {
$newlocation = $this->manipulate_object($objectrecord);
if (!empty($objectrecord->id)) {
manager::upsert_object($objectrecord, $newlocation);
} else {
manager::update_object_by_hash($objectrecord->contenthash, $newlocation);
}
} catch (Exception $e) {
mtrace('Error processing object: ' . $e->getMessage());
} finally {
$objectlock->release();
mtrace('Lock released for: ' . $objectrecord->contenthash);
}
$objectlock->release();
}

$this->logger->end_timing();
Expand Down
2 changes: 1 addition & 1 deletion classes/local/store/object_file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ protected function get_local_path_from_hash($contenthash, $fetchifnotfound = fal
* @param string $contenthash
* @return string mimetype as stored in mdl_files
*/
protected function get_mimetype_from_hash(string $contenthash): string {
protected function get_mimetype_from_hash(string $contenthash): ?string {
global $DB;

// We limit 1 because multiple files can have the same contenthash.
Expand Down
2 changes: 1 addition & 1 deletion classes/local/store/s3/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ public function define_client_section($settings, $config) {
*
* @throws \Exception if fails.
*/
public function upload_to_s3($localpath, $contenthash, string $mimetype) {
public function upload_to_s3($localpath, $contenthash, ?string $mimetype) {
$filehandle = fopen($localpath, 'rb');

if (!$filehandle) {
Expand Down

0 comments on commit 9762b1f

Please sign in to comment.