diff options
Diffstat (limited to 'lib/Sabre/Album/AlbumRoot.php')
-rw-r--r-- | lib/Sabre/Album/AlbumRoot.php | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/lib/Sabre/Album/AlbumRoot.php b/lib/Sabre/Album/AlbumRoot.php index 0406a8c3..0a10157b 100644 --- a/lib/Sabre/Album/AlbumRoot.php +++ b/lib/Sabre/Album/AlbumRoot.php @@ -31,7 +31,6 @@ use OCA\Photos\Service\UserConfigService; use OCP\Files\Folder; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; -use OCP\IUser; use Sabre\DAV\Exception\Conflict; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; @@ -43,22 +42,19 @@ class AlbumRoot implements ICollection, ICopyTarget { protected AlbumMapper $albumMapper; protected AlbumWithFiles $album; protected IRootFolder $rootFolder; - protected Folder $userFolder; - protected IUser $user; + protected string $userId; public function __construct( AlbumMapper $albumMapper, AlbumWithFiles $album, IRootFolder $rootFolder, - Folder $userFolder, - IUser $user, + string $userId, UserConfigService $userConfigService ) { $this->albumMapper = $albumMapper; $this->album = $album; $this->rootFolder = $rootFolder; - $this->userFolder = $userFolder; - $this->user = $user; + $this->userId = $userId; $this->userConfigService = $userConfigService; } @@ -82,7 +78,7 @@ class AlbumRoot implements ICollection, ICopyTarget { protected function getPhotosLocationInfo() { $photosLocation = $this->userConfigService->getUserConfig('photosLocation'); - $userFolder = $this->rootFolder->getUserFolder($this->user->getUID()); + $userFolder = $this->rootFolder->getUserFolder($this->userId); return [$photosLocation, $userFolder]; } @@ -160,23 +156,22 @@ class AlbumRoot implements ICollection, ICopyTarget { } public function copyInto($targetName, $sourcePath, INode $sourceNode): bool { - $uid = $this->user->getUID(); if ($sourceNode instanceof File) { $sourceId = $sourceNode->getId(); $ownerUID = $sourceNode->getFileInfo()->getOwner()->getUID(); return $this->addFile($sourceId, $ownerUID); } + $uid = $this->userId; throw new \Exception("Can't add file to album, only files from $uid can be added"); } protected function addFile(int $sourceId, string $ownerUID): bool { - $uid = $this->user->getUID(); if (in_array($sourceId, $this->album->getFileIds())) { throw new Conflict("File $sourceId is already in the folder"); } - if ($ownerUID === $uid) { + if ($ownerUID === $this->userId) { $this->albumMapper->addFile($this->album->getAlbum()->getId(), $sourceId, $ownerUID); - $node = current($this->userFolder->getById($sourceId)); + $node = current($this->rootFolder->getUserFolder($ownerUID)->getById($sourceId)); $this->album->addFile(new AlbumFile($sourceId, $node->getName(), $node->getMimetype(), $node->getSize(), $node->getMTime(), $node->getEtag(), $node->getCreationTime(), $ownerUID)); return true; } |