Skip to content

Commit

Permalink
Improve path resolution in files_version hooks
Browse files Browse the repository at this point in the history
Signed-off-by: Louis Chemineau <[email protected]>
  • Loading branch information
artonge committed Jan 17, 2024
1 parent 5de3028 commit 8aca484
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions apps/files_versions/lib/Listener/FileEventsListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,10 @@ public function write_hook(Node $node): void {
}

$path = $this->getPathForNode($node);
if ($path === null) {
$this->logger->error('Failed to find relative path for file for ' . $node->getPath() . ' and owner ' .$node->getOwner());
}

$result = Storage::store($path);

// Store the result of the version creation so it can be used in post_write_hook.
Expand Down Expand Up @@ -350,16 +354,24 @@ public function pre_renameOrCopy_hook(Node $source, Node $target): void {
private function getPathForNode(Node $node): ?string {
$user = $this->userSession->getUser()?->getUID();
if ($user) {
return $this->rootFolder
$path = $this->rootFolder
->getUserFolder($user)
->getRelativePath($node->getPath());

if ($path !== null) {
return $path;
}
}

$owner = $node->getOwner()?->getUid();
if ($owner) {
return $this->rootFolder
$path = $this->rootFolder
->getUserFolder($owner)
->getRelativePath($node->getPath());

if ($path !== null) {
return $path;
}
}

return null;
Expand Down

0 comments on commit 8aca484

Please sign in to comment.