|
3 | 3 | namespace wcf\data\attachment; |
4 | 4 |
|
5 | 5 | use wcf\data\DatabaseObject; |
6 | | -use wcf\data\ILinkableObject; |
7 | | -use wcf\data\IThumbnailFile; |
8 | 6 | use wcf\data\file\File; |
9 | 7 | use wcf\data\file\thumbnail\FileThumbnailList; |
| 8 | +use wcf\data\ILinkableObject; |
| 9 | +use wcf\data\IThumbnailFile; |
10 | 10 | use wcf\data\object\type\ObjectTypeCache; |
11 | 11 | use wcf\system\request\IRouteController; |
12 | 12 | use wcf\system\request\LinkHandler; |
@@ -390,46 +390,62 @@ public function getFile(): ?File |
390 | 390 |
|
391 | 391 | public function setFile(File $file): void |
392 | 392 | { |
393 | | - if ($this->file->fileID === $file->fileID) { |
| 393 | + if ($this->fileID === $file->fileID) { |
394 | 394 | $this->file = $file; |
395 | 395 | } |
396 | 396 | } |
397 | 397 |
|
398 | 398 | #[\Override] |
399 | 399 | public function __get($name) |
400 | 400 | { |
401 | | - $file = $this->getFile(); |
402 | | - if ($file === null) { |
403 | | - return parent::__get($name); |
404 | | - } |
405 | | - |
406 | 401 | if ($name === 'downloads' || $name === 'lastDownloadTime') { |
407 | 402 | // Static files are no longer served through PHP but the web server |
408 | 403 | // instead, therefore we can no longer report any meaningful numbers. |
409 | 404 | // |
410 | 405 | // For existing files the stored value is suppressed because it is |
411 | 406 | // not going to be increased ever, possibly creating a false |
412 | 407 | // impression when the historic stored value is being reported. |
413 | | - if ($file->isStaticFile()) { |
| 408 | + if ($this->getFile()?->isStaticFile()) { |
414 | 409 | return 0; |
415 | 410 | } |
416 | 411 | } |
417 | 412 |
|
418 | | - return match ($name) { |
419 | | - 'filename' => $file->filename, |
420 | | - 'filesize' => $file->fileSize, |
421 | | - 'fileType' => $file->mimeType, |
422 | | - 'isImage' => $file->isImage() ? 1 : 0, |
423 | | - 'height' => $file->height ?: 0, |
424 | | - 'width' => $file->width ?: 0, |
425 | | - 'thumbnailType' => $file->getThumbnail('')?->getMimeType() ?: '', |
426 | | - 'thumbnailWidth' => $file->getThumbnail('')?->width ?: 0, |
427 | | - 'thumbnailHeight' => $file->getThumbnail('')?->height ?: 0, |
428 | | - 'tinyThumbnailType' => $file->getThumbnail('tiny')?->getMimeType() ?: '', |
429 | | - 'tinyThumbnailWidth' => $file->getThumbnail('tiny')?->width ?: 0, |
430 | | - 'tinyThumbnailHeight' => $file->getThumbnail('tiny')?->height ?: 0, |
431 | | - default => parent::__get($name), |
432 | | - }; |
| 413 | + if (\in_array($name, [ |
| 414 | + 'filename', |
| 415 | + 'filesize', |
| 416 | + 'fileType', |
| 417 | + 'isImage', |
| 418 | + 'height', |
| 419 | + 'width', |
| 420 | + 'thumbnailType', |
| 421 | + 'thumbnailWidth', |
| 422 | + 'thumbnailHeight', |
| 423 | + 'tinyThumbnailType', |
| 424 | + 'tinyThumbnailWidth', |
| 425 | + 'tinyThumbnailHeight', |
| 426 | + ])) { |
| 427 | + $file = $this->getFile(); |
| 428 | + if ($file === null) { |
| 429 | + return parent::__get($name); |
| 430 | + } |
| 431 | + |
| 432 | + return match ($name) { |
| 433 | + 'filename' => $file->filename, |
| 434 | + 'filesize' => $file->fileSize, |
| 435 | + 'fileType' => $file->mimeType, |
| 436 | + 'isImage' => $file->isImage() ? 1 : 0, |
| 437 | + 'height' => $file->height ?: 0, |
| 438 | + 'width' => $file->width ?: 0, |
| 439 | + 'thumbnailType' => $file->getThumbnail('')?->getMimeType() ?: '', |
| 440 | + 'thumbnailWidth' => $file->getThumbnail('')?->width ?: 0, |
| 441 | + 'thumbnailHeight' => $file->getThumbnail('')?->height ?: 0, |
| 442 | + 'tinyThumbnailType' => $file->getThumbnail('tiny')?->getMimeType() ?: '', |
| 443 | + 'tinyThumbnailWidth' => $file->getThumbnail('tiny')?->width ?: 0, |
| 444 | + 'tinyThumbnailHeight' => $file->getThumbnail('tiny')?->height ?: 0, |
| 445 | + }; |
| 446 | + } |
| 447 | + |
| 448 | + return parent::__get($name); |
433 | 449 | } |
434 | 450 |
|
435 | 451 | public function toHtmlElement(): ?string |
|
0 commit comments