32
32
use OCP \Files \InvalidDirectoryException ;
33
33
use OCP \Files \IRootFolder ;
34
34
use OCP \Files \NotFoundException ;
35
+ use Psr \Log \LoggerInterface ;
35
36
use Sabre \DAV \Exception \Conflict ;
36
37
use Sabre \DAV \Exception \Forbidden ;
37
38
use Sabre \DAV \Exception \NotFound ;
38
39
use Sabre \DAV \ICollection ;
39
40
use Sabre \DAV \ICopyTarget ;
40
41
use Sabre \DAV \INode ;
41
42
42
- class AlbumRoot implements ICollection, ICopyTarget {
43
+ class AlbumRoot implements ICollection, ICopyTarget
44
+ {
43
45
protected AlbumMapper $ albumMapper ;
44
46
protected AlbumWithFiles $ album ;
45
47
protected IRootFolder $ rootFolder ;
46
48
protected string $ userId ;
49
+ private UserConfigService $ userConfigService ;
47
50
48
51
public function __construct (
49
52
AlbumMapper $ albumMapper ,
50
53
AlbumWithFiles $ album ,
51
54
IRootFolder $ rootFolder ,
52
55
string $ userId ,
53
- UserConfigService $ userConfigService
56
+ UserConfigService $ userConfigService ,
57
+ protected LoggerInterface $ logger ,
54
58
) {
55
59
$ this ->albumMapper = $ albumMapper ;
56
60
$ this ->album = $ album ;
@@ -66,7 +70,8 @@ public function delete() {
66
70
$ this ->albumMapper ->delete ($ this ->album ->getAlbum ()->getId ());
67
71
}
68
72
69
- public function getName (): string {
73
+ public function getName (): string
74
+ {
70
75
return basename ($ this ->album ->getAlbum ()->getTitle ());
71
76
}
72
77
@@ -121,6 +126,7 @@ public function createFile($name, $data = null) {
121
126
\header ('OC-FileId: ' . $ node ->getId ());
122
127
return '" ' . $ node ->getEtag () . '" ' ;
123
128
} catch (\Exception $ e ) {
129
+ $ this ->logger ->error ('Could not create file ' , ['exception ' => $ e ]);
124
130
throw new Forbidden ('Could not create file ' );
125
131
}
126
132
}
@@ -132,13 +138,15 @@ public function createDirectory($name) {
132
138
throw new Forbidden ('Not allowed to create directories in this folder ' );
133
139
}
134
140
135
- public function getChildren (): array {
141
+ public function getChildren (): array
142
+ {
136
143
return array_map (function (AlbumFile $ file ) {
137
144
return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
138
145
}, $ this ->album ->getFiles ());
139
146
}
140
147
141
- public function getChild ($ name ): AlbumPhoto {
148
+ public function getChild ($ name ): AlbumPhoto
149
+ {
142
150
foreach ($ this ->album ->getFiles () as $ file ) {
143
151
if ($ file ->getFileId () . "- " . $ file ->getName () === $ name ) {
144
152
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 {
147
155
throw new NotFound ("$ name not found " );
148
156
}
149
157
150
- public function childExists ($ name ): bool {
158
+ public function childExists ($ name ): bool
159
+ {
151
160
try {
152
161
$ this ->getChild ($ name );
153
162
return true ;
@@ -156,11 +165,13 @@ public function childExists($name): bool {
156
165
}
157
166
}
158
167
159
- public function getLastModified (): int {
168
+ public function getLastModified (): int
169
+ {
160
170
return 0 ;
161
171
}
162
172
163
- public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool {
173
+ public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool
174
+ {
164
175
if (!$ sourceNode instanceof File) {
165
176
throw new Forbidden ("The source is not a file " );
166
177
}
@@ -175,7 +186,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
175
186
return $ this ->addFile ($ sourceId , $ ownerUID );
176
187
}
177
188
178
- protected function addFile (int $ sourceId , string $ ownerUID ): bool {
189
+ protected function addFile (int $ sourceId , string $ ownerUID ): bool
190
+ {
179
191
if (in_array ($ sourceId , $ this ->album ->getFileIds ())) {
180
192
throw new Conflict ("File $ sourceId is already in the folder " );
181
193
}
@@ -188,11 +200,13 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
188
200
return false ;
189
201
}
190
202
191
- public function getAlbum (): AlbumWithFiles {
203
+ public function getAlbum (): AlbumWithFiles
204
+ {
192
205
return $ this ->album ;
193
206
}
194
207
195
- public function getDateRange (): array {
208
+ public function getDateRange (): array
209
+ {
196
210
$ earliestDate = null ;
197
211
$ latestDate = null ;
198
212
@@ -231,7 +245,8 @@ public function getCover() {
231
245
/**
232
246
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
233
247
*/
234
- public function getCollaborators (): array {
248
+ public function getCollaborators (): array
249
+ {
235
250
return array_map (
236
251
fn (array $ collaborator ) => [ 'nc:collaborator ' => $ collaborator ],
237
252
$ this ->albumMapper ->getCollaborators ($ this ->album ->getAlbum ()->getId ()),
@@ -242,7 +257,8 @@ public function getCollaborators(): array {
242
257
* @param array{'id': string, 'type': int} $collaborators
243
258
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
244
259
*/
245
- public function setCollaborators ($ collaborators ): array {
260
+ public function setCollaborators ($ collaborators ): array
261
+ {
246
262
$ this ->albumMapper ->setCollaborators ($ this ->getAlbum ()->getAlbum ()->getId (), $ collaborators );
247
263
return $ this ->getCollaborators ();
248
264
}
0 commit comments