@@ -75,6 +75,7 @@ public function __construct(
75
75
* The response with file contents.
76
76
*/
77
77
protected function wopiCheckFileInfo (FileInterface $ file , UserInterface $ user , bool $ can_write ): Response {
78
+ assert ($ file ->getChangedTime () !== NULL );
78
79
$ response_data = [
79
80
'BaseFileName ' => $ file ->getFilename (),
80
81
'Size ' => $ file ->getSize (),
@@ -88,9 +89,14 @@ protected function wopiCheckFileInfo(FileInterface $file, UserInterface $user, b
88
89
'SupportsRename ' => FALSE ,
89
90
];
90
91
91
- $ user_picture = $ user ->user_picture ?->entity;
92
- if ($ user_picture ) {
93
- $ response_data ['UserExtraInfo ' ]['avatar ' ] = $ this ->fileUrlGenerator ->generateAbsoluteString ($ user_picture ->getFileUri ());
92
+ if ($ user ->hasField ('user_picture ' )) {
93
+ $ user_picture = $ user ->get ('user_picture ' )->entity ;
94
+ if (
95
+ $ user_picture instanceof FileInterface &&
96
+ $ user_picture ->getFileUri () !== NULL
97
+ ) {
98
+ $ response_data ['UserExtraInfo ' ]['avatar ' ] = $ this ->fileUrlGenerator ->generateAbsoluteString ($ user_picture ->getFileUri ());
99
+ }
94
100
}
95
101
96
102
return new JsonResponse (
@@ -112,6 +118,7 @@ protected function wopiCheckFileInfo(FileInterface $file, UserInterface $user, b
112
118
* @see \Drupal\system\FileDownloadController::download()
113
119
*/
114
120
protected function wopiGetFile (FileInterface $ file ): Response {
121
+ assert ($ file ->getFileUri () !== NULL );
115
122
if (!is_file ($ file ->getFileUri ())) {
116
123
throw new NotFoundHttpException ('The file is missing in the file system. ' );
117
124
}
@@ -159,6 +166,7 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
159
166
$ request_time - $ file ->getCreatedTime () <= $ new_file_interval
160
167
) {
161
168
// Replace file with new content.
169
+ assert ($ file ->getFileUri () !== NULL );
162
170
$ this ->fileSystem ->saveData (
163
171
$ new_file_content ,
164
172
$ file ->getFileUri (),
@@ -182,6 +190,7 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
182
190
],
183
191
);
184
192
193
+ assert ($ file ->getChangedTime () !== NULL );
185
194
return new JsonResponse (
186
195
[
187
196
'LastModifiedTime ' => DateTimeHelper::format ($ file ->getChangedTime ()),
@@ -216,6 +225,7 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
216
225
],
217
226
);
218
227
228
+ assert ($ new_file ->getChangedTime () !== NULL );
219
229
return new JsonResponse (
220
230
[
221
231
'LastModifiedTime ' => DateTimeHelper::format ($ new_file ->getChangedTime ()),
@@ -238,6 +248,7 @@ protected function wopiPutFile(MediaInterface $media, FileInterface $file, UserI
238
248
* This may have a different uri, but will have the same filename.
239
249
*/
240
250
protected function createNewFileEntity (FileInterface $ file , string $ new_file_content ): FileInterface {
251
+ assert ($ file ->getFileUri () !== NULL );
241
252
// The current file uri may have a number suffix like "_0".
242
253
// For the new file uri, start with the clean file name, to avoid repeated
243
254
// suffixes like "_0_0_0".
@@ -250,10 +261,12 @@ protected function createNewFileEntity(FileInterface $file, string $new_file_con
250
261
FileExists::Rename,
251
262
);
252
263
253
- /** @var \Drupal\file\FileInterface|null $new_file */
264
+ /** @var \Drupal\file\FileInterface $new_file */
254
265
$ new_file = $ this ->entityTypeManager ->getStorage ('file ' )->create ([
255
266
'uri ' => $ new_file_uri ,
256
267
]);
268
+ // Parameter and return docs on entity owner methods are inconsistent.
269
+ // @phpstan-ignore argument.type
257
270
$ new_file ->setOwnerId ($ file ->getOwnerId ());
258
271
// Preserve the original file name, no matter the uri was renamed.
259
272
$ new_file ->setFilename ($ file ->getFilename ());
@@ -285,7 +298,10 @@ protected function checkSaveTimestampConflict(Request $request, MediaInterface $
285
298
return NULL ;
286
299
}
287
300
$ wopi_datetime = \DateTimeImmutable::createFromFormat (\DateTimeInterface::ATOM , $ wopi_time_atom );
288
- $ file_datetime = \DateTimeImmutable::createFromFormat ('U ' , $ file ->getChangedTime ());
301
+ $ file_datetime = \DateTimeImmutable::createFromFormat ('U ' , (string ) $ file ->getChangedTime ());
302
+
303
+ assert ($ wopi_datetime !== FALSE );
304
+ assert ($ file_datetime !== FALSE );
289
305
290
306
if ($ wopi_datetime == $ file_datetime ) {
291
307
return NULL ;
@@ -354,6 +370,10 @@ public function wopi(string $action, MediaInterface $media, Request $request): R
354
370
if ($ token === NULL ) {
355
371
throw new AccessDeniedHttpException ('Missing access token. ' );
356
372
}
373
+ if (!is_string ($ token )) {
374
+ // A malformed request could have a non-string value for access_token.
375
+ throw new AccessDeniedHttpException (sprintf ('Expected a string access token, found %s. ' , gettype ($ token )));
376
+ }
357
377
$ jwt_payload = $ this ->verifyTokenForMedia ($ token , $ media );
358
378
359
379
/** @var \Drupal\user\UserInterface|null $user */
0 commit comments