3232use OCP \Files \InvalidDirectoryException ;
3333use OCP \Files \IRootFolder ;
3434use OCP \Files \NotFoundException ;
35+ use Psr \Log \LoggerInterface ;
3536use Sabre \DAV \Exception \Conflict ;
3637use Sabre \DAV \Exception \Forbidden ;
3738use Sabre \DAV \Exception \NotFound ;
3839use Sabre \DAV \ICollection ;
3940use Sabre \DAV \ICopyTarget ;
4041use Sabre \DAV \INode ;
4142
42- class AlbumRoot implements ICollection, ICopyTarget {
43+ class AlbumRoot implements ICollection, ICopyTarget
44+ {
4345 protected AlbumMapper $ albumMapper ;
4446 protected AlbumWithFiles $ album ;
4547 protected IRootFolder $ rootFolder ;
4648 protected string $ userId ;
49+ private UserConfigService $ userConfigService ;
4750
4851 public function __construct (
4952 AlbumMapper $ albumMapper ,
5053 AlbumWithFiles $ album ,
5154 IRootFolder $ rootFolder ,
5255 string $ userId ,
53- UserConfigService $ userConfigService
56+ UserConfigService $ userConfigService ,
57+ protected LoggerInterface $ logger ,
5458 ) {
5559 $ this ->albumMapper = $ albumMapper ;
5660 $ this ->album = $ album ;
@@ -62,22 +66,26 @@ public function __construct(
6266 /**
6367 * @return void
6468 */
65- public function delete () {
69+ public function delete ()
70+ {
6671 $ this ->albumMapper ->delete ($ this ->album ->getAlbum ()->getId ());
6772 }
6873
69- public function getName (): string {
74+ public function getName (): string
75+ {
7076 return basename ($ this ->album ->getAlbum ()->getTitle ());
7177 }
7278
7379 /**
7480 * @return void
7581 */
76- public function setName ($ name ) {
82+ public function setName ($ name )
83+ {
7784 $ this ->albumMapper ->rename ($ this ->album ->getAlbum ()->getId (), $ name );
7885 }
7986
80- protected function getPhotosLocationInfo () {
87+ protected function getPhotosLocationInfo ()
88+ {
8189 $ photosLocation = $ this ->userConfigService ->getUserConfig ('photosLocation ' );
8290 $ userFolder = $ this ->rootFolder ->getUserFolder ($ this ->userId );
8391 return [$ photosLocation , $ userFolder ];
@@ -91,7 +99,8 @@ protected function getPhotosLocationInfo() {
9199 * @param null|resource|string $data
92100 * @return void
93101 */
94- public function createFile ($ name , $ data = null ) {
102+ public function createFile ($ name , $ data = null )
103+ {
95104 try {
96105 [$ photosLocation , $ userFolder ] = $ this ->getPhotosLocationInfo ();
97106
@@ -121,24 +130,28 @@ public function createFile($name, $data = null) {
121130 \header ('OC-FileId: ' . $ node ->getId ());
122131 return '" ' . $ node ->getEtag () . '" ' ;
123132 } catch (\Exception $ e ) {
133+ $ this ->logger ->error ('Could not create file ' , ['exception ' => $ e ]);
124134 throw new Forbidden ('Could not create file ' );
125135 }
126136 }
127137
128138 /**
129139 * @return never
130140 */
131- public function createDirectory ($ name ) {
141+ public function createDirectory ($ name )
142+ {
132143 throw new Forbidden ('Not allowed to create directories in this folder ' );
133144 }
134145
135- public function getChildren (): array {
146+ public function getChildren (): array
147+ {
136148 return array_map (function (AlbumFile $ file ) {
137149 return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
138150 }, $ this ->album ->getFiles ());
139151 }
140152
141- public function getChild ($ name ): AlbumPhoto {
153+ public function getChild ($ name ): AlbumPhoto
154+ {
142155 foreach ($ this ->album ->getFiles () as $ file ) {
143156 if ($ file ->getFileId () . "- " . $ file ->getName () === $ name ) {
144157 return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
@@ -147,7 +160,8 @@ public function getChild($name): AlbumPhoto {
147160 throw new NotFound ("$ name not found " );
148161 }
149162
150- public function childExists ($ name ): bool {
163+ public function childExists ($ name ): bool
164+ {
151165 try {
152166 $ this ->getChild ($ name );
153167 return true ;
@@ -156,11 +170,13 @@ public function childExists($name): bool {
156170 }
157171 }
158172
159- public function getLastModified (): int {
173+ public function getLastModified (): int
174+ {
160175 return 0 ;
161176 }
162177
163- public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool {
178+ public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool
179+ {
164180 if (!$ sourceNode instanceof File) {
165181 throw new Forbidden ("The source is not a file " );
166182 }
@@ -175,7 +191,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
175191 return $ this ->addFile ($ sourceId , $ ownerUID );
176192 }
177193
178- protected function addFile (int $ sourceId , string $ ownerUID ): bool {
194+ protected function addFile (int $ sourceId , string $ ownerUID ): bool
195+ {
179196 if (in_array ($ sourceId , $ this ->album ->getFileIds ())) {
180197 throw new Conflict ("File $ sourceId is already in the folder " );
181198 }
@@ -188,11 +205,13 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
188205 return false ;
189206 }
190207
191- public function getAlbum (): AlbumWithFiles {
208+ public function getAlbum (): AlbumWithFiles
209+ {
192210 return $ this ->album ;
193211 }
194212
195- public function getDateRange (): array {
213+ public function getDateRange (): array
214+ {
196215 $ earliestDate = null ;
197216 $ latestDate = null ;
198217
@@ -218,7 +237,8 @@ public function getDateRange(): array {
218237 /**
219238 * @return int|null
220239 */
221- public function getCover () {
240+ public function getCover ()
241+ {
222242 $ children = $ this ->getChildren ();
223243
224244 if (count ($ children ) > 0 ) {
@@ -231,7 +251,8 @@ public function getCover() {
231251 /**
232252 * @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
233253 */
234- public function getCollaborators (): array {
254+ public function getCollaborators (): array
255+ {
235256 return array_map (
236257 fn (array $ collaborator ) => [ 'nc:collaborator ' => $ collaborator ],
237258 $ this ->albumMapper ->getCollaborators ($ this ->album ->getAlbum ()->getId ()),
@@ -242,7 +263,8 @@ public function getCollaborators(): array {
242263 * @param array{'id': string, 'type': int} $collaborators
243264 * @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
244265 */
245- public function setCollaborators ($ collaborators ): array {
266+ public function setCollaborators ($ collaborators ): array
267+ {
246268 $ this ->albumMapper ->setCollaborators ($ this ->getAlbum ()->getAlbum ()->getId (), $ collaborators );
247269 return $ this ->getCollaborators ();
248270 }
0 commit comments