diff --git a/lib/Sabre/Album/AlbumRoot.php b/lib/Sabre/Album/AlbumRoot.php index 236215467..78af26a0c 100644 --- a/lib/Sabre/Album/AlbumRoot.php +++ b/lib/Sabre/Album/AlbumRoot.php @@ -17,6 +17,7 @@ use OCP\Files\InvalidDirectoryException; use OCP\Files\IRootFolder; use OCP\Files\NotFoundException; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Conflict; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; @@ -30,7 +31,8 @@ public function __construct( protected AlbumWithFiles $album, protected IRootFolder $rootFolder, protected string $userId, - protected UserConfigService $userConfigService + protected UserConfigService $userConfigService, + protected LoggerInterface $logger, ) { } @@ -96,6 +98,7 @@ public function createFile($name, $data = null) { \header('OC-FileId: ' . $node->getId()); return '"' . $node->getEtag() . '"'; } catch (\Exception $e) { + $this->logger->error('Could not create file', ['exception' => $e]); throw new Forbidden('Could not create file'); } } diff --git a/lib/Sabre/Album/AlbumsHome.php b/lib/Sabre/Album/AlbumsHome.php index 80ad55a0d..28a26f6f3 100644 --- a/lib/Sabre/Album/AlbumsHome.php +++ b/lib/Sabre/Album/AlbumsHome.php @@ -13,17 +13,12 @@ use OCA\Photos\Album\AlbumWithFiles; use OCA\Photos\Service\UserConfigService; use OCP\Files\IRootFolder; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; class AlbumsHome implements ICollection { - protected AlbumMapper $albumMapper; - protected array $principalInfo; - protected string $userId; - protected IRootFolder $rootFolder; - protected UserConfigService $userConfigService; - public const NAME = 'albums'; /** @@ -32,17 +27,13 @@ class AlbumsHome implements ICollection { protected ?array $children = null; public function __construct( - array $principalInfo, - AlbumMapper $albumMapper, - string $userId, - IRootFolder $rootFolder, - UserConfigService $userConfigService + private array $principalInfo, + private AlbumMapper $albumMapper, + private string $userId, + private IRootFolder $rootFolder, + private UserConfigService $userConfigService, + private LoggerInterface $logger, ) { - $this->principalInfo = $principalInfo; - $this->albumMapper = $albumMapper; - $this->userId = $userId; - $this->rootFolder = $rootFolder; - $this->userConfigService = $userConfigService; } /** @@ -91,7 +82,14 @@ public function getChildren(): array { if ($this->children === null) { $albumInfos = $this->albumMapper->getForUser($this->userId); $this->children = array_map(function (AlbumInfo $albumInfo) { - return new AlbumRoot($this->albumMapper, new AlbumWithFiles($albumInfo, $this->albumMapper), $this->rootFolder, $this->userId, $this->userConfigService); + return new AlbumRoot( + $this->albumMapper, + new AlbumWithFiles($albumInfo, $this->albumMapper), + $this->rootFolder, + $this->userId, + $this->userConfigService, + $this->logger, + ); }, $albumInfos); } diff --git a/lib/Sabre/Album/SharedAlbumRoot.php b/lib/Sabre/Album/SharedAlbumRoot.php index 034f86609..98a014560 100644 --- a/lib/Sabre/Album/SharedAlbumRoot.php +++ b/lib/Sabre/Album/SharedAlbumRoot.php @@ -13,19 +13,19 @@ use OCA\Photos\Service\UserConfigService; use OCP\Files\IRootFolder; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Conflict; use Sabre\DAV\Exception\Forbidden; class SharedAlbumRoot extends AlbumRoot { - private IUserManager $userManager; - public function __construct( AlbumMapper $albumMapper, AlbumWithFiles $album, IRootFolder $rootFolder, string $userId, UserConfigService $userConfigService, - IUserManager $userManager + private IUserManager $userManager, + LoggerInterface $logger, ) { parent::__construct( $albumMapper, @@ -33,9 +33,8 @@ public function __construct( $rootFolder, $userId, $userConfigService, + $logger, ); - - $this->userManager = $userManager; } /** diff --git a/lib/Sabre/Album/SharedAlbumsHome.php b/lib/Sabre/Album/SharedAlbumsHome.php index f8cc4096e..b0b936b41 100644 --- a/lib/Sabre/Album/SharedAlbumsHome.php +++ b/lib/Sabre/Album/SharedAlbumsHome.php @@ -14,12 +14,10 @@ use OCP\Files\IRootFolder; use OCP\IGroupManager; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; class SharedAlbumsHome extends AlbumsHome { - private IUserManager $userManager; - private IGroupManager $groupManager; - public const NAME = 'sharedalbums'; public function __construct( @@ -27,20 +25,20 @@ public function __construct( AlbumMapper $albumMapper, string $userId, IRootFolder $rootFolder, - IUserManager $userManager, - IGroupManager $groupManager, - UserConfigService $userConfigService + private IUserManager $userManager, + private IGroupManager $groupManager, + UserConfigService $userConfigService, + LoggerInterface $logger, + ) { parent::__construct( $principalInfo, $albumMapper, $userId, $rootFolder, - $userConfigService + $userConfigService, + $logger, ); - - $this->userManager = $userManager; - $this->groupManager = $groupManager; } /** diff --git a/lib/Sabre/PhotosHome.php b/lib/Sabre/PhotosHome.php index face3e3a9..37730c690 100644 --- a/lib/Sabre/PhotosHome.php +++ b/lib/Sabre/PhotosHome.php @@ -18,6 +18,7 @@ use OCP\Files\IRootFolder; use OCP\IGroupManager; use OCP\IUserManager; +use Psr\Log\LoggerInterface; use Sabre\DAV\Exception\Forbidden; use Sabre\DAV\Exception\NotFound; use Sabre\DAV\ICollection; @@ -33,6 +34,7 @@ public function __construct( private IUserManager $userManager, private IGroupManager $groupManager, private UserConfigService $userConfigService, + private LoggerInterface $logger, ) { } @@ -69,9 +71,9 @@ public function createDirectory($name) { public function getChild($name) { switch ($name) { case AlbumsHome::NAME: - return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService); + return new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger); case SharedAlbumsHome::NAME: - return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService); + return new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger); case PlacesHome::NAME: return new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper); } @@ -84,8 +86,8 @@ public function getChild($name) { */ public function getChildren(): array { return [ - new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService), - new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService), + new AlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userConfigService, $this->logger), + new SharedAlbumsHome($this->principalInfo, $this->albumMapper, $this->userId, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger), new PlacesHome($this->userId, $this->rootFolder, $this->reverseGeoCoderService, $this->placeMapper), ]; } diff --git a/lib/Sabre/RootCollection.php b/lib/Sabre/RootCollection.php index 977ca963f..6a5e74899 100644 --- a/lib/Sabre/RootCollection.php +++ b/lib/Sabre/RootCollection.php @@ -16,6 +16,7 @@ use OCP\IGroupManager; use OCP\IUserManager; use OCP\IUserSession; +use Psr\Log\LoggerInterface; use Sabre\DAVACL\AbstractPrincipalCollection; use Sabre\DAVACL\PrincipalBackend; @@ -30,6 +31,7 @@ public function __construct( private IUserManager $userManager, private IGroupManager $groupManager, private UserConfigService $userConfigService, + private LoggerInterface $logger, ) { parent::__construct($principalBackend, 'principals/users'); } @@ -49,7 +51,7 @@ public function getChildForPrincipal(array $principalInfo): PhotosHome { if (is_null($user) || $name !== $user->getUID()) { throw new \Sabre\DAV\Exception\Forbidden(); } - return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService); + return new PhotosHome($principalInfo, $this->albumMapper, $this->placeMapper, $this->reverseGeoCoderService, $name, $this->rootFolder, $this->userManager, $this->groupManager, $this->userConfigService, $this->logger); } public function getName(): string {