aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLouis Chemineau <louis@chmn.me>2022-12-15 15:30:18 +0100
committerLouis (Rebase PR Action) <artonge@users.noreply.github.com>2023-01-26 10:12:23 +0000
commit3da63f4148898ec4bc9544a4a9ef07bac3e07669 (patch)
tree1dfd3cbc6dbd53b942883a1231ea46c492178a31
parent84e5b9c5f7646303ca9f5070187c8464cde0bd30 (diff)
downloadnextcloud-server-3da63f4148898ec4bc9544a4a9ef07bac3e07669.tar.gz
nextcloud-server-3da63f4148898ec4bc9544a4a9ef07bac3e07669.zip
Use node's owner if no user is connected
Signed-off-by: Louis Chemineau <louis@chmn.me>
-rw-r--r--apps/files_versions/lib/Listener/FileEventsListener.php40
1 files changed, 25 insertions, 15 deletions
diff --git a/apps/files_versions/lib/Listener/FileEventsListener.php b/apps/files_versions/lib/Listener/FileEventsListener.php
index 98dbce17e96..20b3881e953 100644
--- a/apps/files_versions/lib/Listener/FileEventsListener.php
+++ b/apps/files_versions/lib/Listener/FileEventsListener.php
@@ -182,8 +182,7 @@ class FileEventsListener implements IEventListener {
return;
}
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $path = $userFolder->getRelativePath($node->getPath());
+ $path = $this->getPathForNode($node);
$result = Storage::store($path);
// Store the result of the version creation so it can be used in post_write_hook.
@@ -244,8 +243,7 @@ class FileEventsListener implements IEventListener {
return;
}
$node = $this->versionsDeleted[$path];
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $relativePath = $userFolder->getRelativePath($node->getPath());
+ $relativePath = $this->getPathForNode($node);
unset($this->versionsDeleted[$path]);
Storage::delete($relativePath);
$this->versionsMapper->deleteAllVersionsForFileId($node->getId());
@@ -255,8 +253,7 @@ class FileEventsListener implements IEventListener {
* mark file as "deleted" so that we can clean up the versions if the file is gone
*/
public function pre_remove_hook(Node $node): void {
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $path = $userFolder->getRelativePath($node->getPath());
+ $path = $this->getPathForNode($node);
Storage::markDeletedFile($path);
$this->versionsDeleted[$node->getPath()] = $node;
}
@@ -268,9 +265,8 @@ class FileEventsListener implements IEventListener {
* of the stored versions along the actual file
*/
public function rename_hook(Node $source, Node $target): void {
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $oldPath = $userFolder->getRelativePath($source->getPath());
- $newPath = $userFolder->getRelativePath($target->getPath());
+ $oldPath = $this->getPathForNode($source);
+ $newPath = $this->getPathForNode($target);
Storage::renameOrCopy($oldPath, $newPath, 'rename');
}
@@ -281,9 +277,8 @@ class FileEventsListener implements IEventListener {
* the stored versions to the new location
*/
public function copy_hook(Node $source, Node $target): void {
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $oldPath = $userFolder->getRelativePath($source->getPath());
- $newPath = $userFolder->getRelativePath($target->getPath());
+ $oldPath = $this->getPathForNode($source);
+ $newPath = $this->getPathForNode($target);
Storage::renameOrCopy($oldPath, $newPath, 'copy');
}
@@ -297,9 +292,8 @@ class FileEventsListener implements IEventListener {
public function pre_renameOrCopy_hook(Node $source, Node $target): void {
// if we rename a movable mount point, then the versions don't have
// to be renamed
- $userFolder = $this->rootFolder->getUserFolder(\OC_User::getUser());
- $oldPath = $userFolder->getRelativePath($source->getPath());
- $newPath = $userFolder->getRelativePath($target->getPath());
+ $oldPath = $this->getPathForNode($source);
+ $newPath = $this->getPathForNode($target);
$absOldPath = Filesystem::normalizePath('/' . \OC_User::getUser() . '/files' . $oldPath);
$manager = Filesystem::getMountManager();
$mount = $manager->find($absOldPath);
@@ -315,4 +309,20 @@ class FileEventsListener implements IEventListener {
Storage::setSourcePathAndUser($oldPath);
}
}
+
+ /**
+ * Retrieve the path relative to the current user root folder.
+ * If no user is connected, use the node's owner.
+ */
+ private function getPathForNode(Node $node): ?string {
+ try {
+ return $this->rootFolder
+ ->getUserFolder(\OC_User::getUser())
+ ->getRelativePath($node->getPath());
+ } catch (\Throwable $ex) {
+ return $this->rootFolder
+ ->getUserFolder($node->getOwner()->getUid())
+ ->getRelativePath($node->getPath());
+ }
+ }
}