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 ;
@@ -62,22 +66,26 @@ public function __construct(
62
66
/**
63
67
* @return void
64
68
*/
65
- public function delete () {
69
+ public function delete ()
70
+ {
66
71
$ this ->albumMapper ->delete ($ this ->album ->getAlbum ()->getId ());
67
72
}
68
73
69
- public function getName (): string {
74
+ public function getName (): string
75
+ {
70
76
return basename ($ this ->album ->getAlbum ()->getTitle ());
71
77
}
72
78
73
79
/**
74
80
* @return void
75
81
*/
76
- public function setName ($ name ) {
82
+ public function setName ($ name )
83
+ {
77
84
$ this ->albumMapper ->rename ($ this ->album ->getAlbum ()->getId (), $ name );
78
85
}
79
86
80
- protected function getPhotosLocationInfo () {
87
+ protected function getPhotosLocationInfo ()
88
+ {
81
89
$ photosLocation = $ this ->userConfigService ->getUserConfig ('photosLocation ' );
82
90
$ userFolder = $ this ->rootFolder ->getUserFolder ($ this ->userId );
83
91
return [$ photosLocation , $ userFolder ];
@@ -91,7 +99,8 @@ protected function getPhotosLocationInfo() {
91
99
* @param null|resource|string $data
92
100
* @return void
93
101
*/
94
- public function createFile ($ name , $ data = null ) {
102
+ public function createFile ($ name , $ data = null )
103
+ {
95
104
try {
96
105
[$ photosLocation , $ userFolder ] = $ this ->getPhotosLocationInfo ();
97
106
@@ -121,24 +130,28 @@ public function createFile($name, $data = null) {
121
130
\header ('OC-FileId: ' . $ node ->getId ());
122
131
return '" ' . $ node ->getEtag () . '" ' ;
123
132
} catch (\Exception $ e ) {
133
+ $ this ->logger ->error ('Could not create file ' , ['exception ' => $ e ]);
124
134
throw new Forbidden ('Could not create file ' );
125
135
}
126
136
}
127
137
128
138
/**
129
139
* @return never
130
140
*/
131
- public function createDirectory ($ name ) {
141
+ public function createDirectory ($ name )
142
+ {
132
143
throw new Forbidden ('Not allowed to create directories in this folder ' );
133
144
}
134
145
135
- public function getChildren (): array {
146
+ public function getChildren (): array
147
+ {
136
148
return array_map (function (AlbumFile $ file ) {
137
149
return new AlbumPhoto ($ this ->albumMapper , $ this ->album ->getAlbum (), $ file , $ this ->rootFolder , $ this ->rootFolder ->getUserFolder ($ this ->userId ));
138
150
}, $ this ->album ->getFiles ());
139
151
}
140
152
141
- public function getChild ($ name ): AlbumPhoto {
153
+ public function getChild ($ name ): AlbumPhoto
154
+ {
142
155
foreach ($ this ->album ->getFiles () as $ file ) {
143
156
if ($ file ->getFileId () . "- " . $ file ->getName () === $ name ) {
144
157
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 {
147
160
throw new NotFound ("$ name not found " );
148
161
}
149
162
150
- public function childExists ($ name ): bool {
163
+ public function childExists ($ name ): bool
164
+ {
151
165
try {
152
166
$ this ->getChild ($ name );
153
167
return true ;
@@ -156,11 +170,13 @@ public function childExists($name): bool {
156
170
}
157
171
}
158
172
159
- public function getLastModified (): int {
173
+ public function getLastModified (): int
174
+ {
160
175
return 0 ;
161
176
}
162
177
163
- public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool {
178
+ public function copyInto ($ targetName , $ sourcePath , INode $ sourceNode ): bool
179
+ {
164
180
if (!$ sourceNode instanceof File) {
165
181
throw new Forbidden ("The source is not a file " );
166
182
}
@@ -175,7 +191,8 @@ public function copyInto($targetName, $sourcePath, INode $sourceNode): bool {
175
191
return $ this ->addFile ($ sourceId , $ ownerUID );
176
192
}
177
193
178
- protected function addFile (int $ sourceId , string $ ownerUID ): bool {
194
+ protected function addFile (int $ sourceId , string $ ownerUID ): bool
195
+ {
179
196
if (in_array ($ sourceId , $ this ->album ->getFileIds ())) {
180
197
throw new Conflict ("File $ sourceId is already in the folder " );
181
198
}
@@ -188,11 +205,13 @@ protected function addFile(int $sourceId, string $ownerUID): bool {
188
205
return false ;
189
206
}
190
207
191
- public function getAlbum (): AlbumWithFiles {
208
+ public function getAlbum (): AlbumWithFiles
209
+ {
192
210
return $ this ->album ;
193
211
}
194
212
195
- public function getDateRange (): array {
213
+ public function getDateRange (): array
214
+ {
196
215
$ earliestDate = null ;
197
216
$ latestDate = null ;
198
217
@@ -218,7 +237,8 @@ public function getDateRange(): array {
218
237
/**
219
238
* @return int|null
220
239
*/
221
- public function getCover () {
240
+ public function getCover ()
241
+ {
222
242
$ children = $ this ->getChildren ();
223
243
224
244
if (count ($ children ) > 0 ) {
@@ -231,7 +251,8 @@ public function getCover() {
231
251
/**
232
252
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
233
253
*/
234
- public function getCollaborators (): array {
254
+ public function getCollaborators (): array
255
+ {
235
256
return array_map (
236
257
fn (array $ collaborator ) => [ 'nc:collaborator ' => $ collaborator ],
237
258
$ this ->albumMapper ->getCollaborators ($ this ->album ->getAlbum ()->getId ()),
@@ -242,7 +263,8 @@ public function getCollaborators(): array {
242
263
* @param array{'id': string, 'type': int} $collaborators
243
264
* @return array{array{'nc:collaborator': array{'id': string, 'label': string, 'type': int}}}
244
265
*/
245
- public function setCollaborators ($ collaborators ): array {
266
+ public function setCollaborators ($ collaborators ): array
267
+ {
246
268
$ this ->albumMapper ->setCollaborators ($ this ->getAlbum ()->getAlbum ()->getId (), $ collaborators );
247
269
return $ this ->getCollaborators ();
248
270
}
0 commit comments