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 ;
@@ -66,7 +70,8 @@ public function delete() {
6670 $ this ->albumMapper ->delete ($ this ->album ->getAlbum ()->getId ());
6771 }
6872
69- public function getName (): string {
73+ public function getName (): string
74+ {
7075 return basename ($ this ->album ->getAlbum ()->getTitle ());
7176 }
7277
@@ -121,6 +126,7 @@ public function createFile($name, $data = null) {
121126 \header ('OC-FileId: ' . $ node ->getId ());
122127 return '" ' . $ node ->getEtag () . '" ' ;
123128 } catch (\Exception $ e ) {
129+ $ this ->logger ->error ('Could not create file ' , ['exception ' => $ e ]);
124130 throw new Forbidden ('Could not create file ' );
125131 }
126132 }
@@ -132,13 +138,15 @@ public function createDirectory($name) {
132138 throw new Forbidden ('Not allowed to create directories in this folder ' );
133139 }
134140
135- public function getChildren (): array {
141+ public function getChildren (): array
142+ {
136143 return array_map (function (AlbumFile $ file ) {
137144 return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
138145 }, $ this ->album ->getFiles ());
139146 }
140147
141- public function getChild ($ name ): AlbumPhoto {
148+ public function getChild ($ name ): AlbumPhoto
149+ {
142150 foreach ($ this ->album ->getFiles () as $ file ) {
143151 if ($ file ->getFileId () . "- " . $ file ->getName () === $ name ) {
144152 return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
@@ -147,7 +155,8 @@ public function getChild($name): AlbumPhoto {
147155 throw new NotFound ("$ name not found " );
148156 }
149157
150- public function childExists ($ name ): bool {
158+ public function childExists ($ name ): bool
159+ {
151160 try {
152161 $ this ->getChild ($ name );
153162 return true ;
@@ -156,11 +165,13 @@ public function childExists($name): bool {
156165 }
157166 }
158167
159- public function getLastModified (): int {
168+ public function getLastModified (): int
169+ {
160170 return 0 ;
161171 }
162172
163- public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool {
173+ public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool
174+ {
164175 if (!$ sourceNode instanceof File) {
165176 throw new Forbidden ("The source is not a file " );
166177 }
@@ -175,7 +186,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
175186 return $ this ->addFile ($ sourceId , $ ownerUID );
176187 }
177188
178- protected function addFile (int $ sourceId , string $ ownerUID ): bool {
189+ protected function addFile (int $ sourceId , string $ ownerUID ): bool
190+ {
179191 if (in_array ($ sourceId , $ this ->album ->getFileIds ())) {
180192 throw new Conflict ("File $ sourceId is already in the folder " );
181193 }
@@ -188,11 +200,13 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
188200 return false ;
189201 }
190202
191- public function getAlbum (): AlbumWithFiles {
203+ public function getAlbum (): AlbumWithFiles
204+ {
192205 return $ this ->album ;
193206 }
194207
195- public function getDateRange (): array {
208+ public function getDateRange (): array
209+ {
196210 $ earliestDate = null ;
197211 $ latestDate = null ;
198212
@@ -231,7 +245,8 @@ public function getCover() {
231245 /**
232246 * @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
233247 */
234- public function getCollaborators (): array {
248+ public function getCollaborators (): array
249+ {
235250 return array_map (
236251 fn (array $ collaborator ) => [ 'nc:collaborator ' => $ collaborator ],
237252 $ this ->albumMapper ->getCollaborators ($ this ->album ->getAlbum ()->getId ()),
@@ -242,7 +257,8 @@ public function getCollaborators(): array {
242257 * @param array{'id': string, 'type': int} $collaborators
243258 * @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
244259 */
245- public function setCollaborators ($ collaborators ): array {
260+ public function setCollaborators ($ collaborators ): array
261+ {
246262 $ this ->albumMapper ->setCollaborators ($ this ->getAlbum ()->getAlbum ()->getId (), $ collaborators );
247263 return $ this ->getCollaborators ();
248264 }
0 commit comments