Issue Feature Closed

#87833Detect missing file for a given FileReference in Extbase

Jan Kornblum 03/04/19, 13:47 updated 10/16/26, 15:02

Description

I’ve tried three different ways to detect if a `FileReference`‘s original file is still existing (i.e. file has been deleted outside TYPO3 using SFTP or similar):

if($fileReference instanceof \TYPO3\CMS\Extbase\Domain\Model\FileReference) {
    $isMissing = $fileReference->getOriginalResource()->getStorage()->getFile($fileReference->getOriginalResource()->getIdentifier())->isMissing();
    $isMissing = $fileReference->getOriginalResource()->getOriginalFile()->isMissing();
    $isMissing = $fileReference->getOriginalResource()->isMissing();
}

Only the first one gives me the right `isMissing()` value. In addition, there is no possibility in FLUID to check against missing files for a fiven relation. You have to write an own viewhelper using the code above for this.

Reviews 0

No change resolves or names this issue in its commit message, and no comment links one.

History 2

  1. Jan Kornblum commented and changed tracker Bug Feature <span data-processor="relativetime" data-value="2020-07-22T23:21:34+00:00" > 07/22/20, 23:21 </span>

    Changed this from “bug” to possible “feature” as the current behaviour is explained here: https://stackoverflow.com/questions/54983438/typo3-extbase-detect-missing-files-for-a-given-filereference. Otherwise this issue might be closed, of course.

  2. Georg Ringer commented and changed status New Closed <span data-processor="relativetime" data-value="2026-10-16T15:02:59+00:00" > 10/16/26, 15:02 </span>

    Thanks for the report. As Jan already noted, this is not a bug: isMissing() does not look at the file system, it returns the missing flag of the sys_file record. That flag is set by the file indexer (scheduler task “File Abstraction Layer: Update storage index” or the Filelist module) once it notices that a file has vanished. A file deleted via SFTP stays “not missing” until then.

    In current versions FileReference::isMissing() and File::isMissing() read the very same flag, so the Extbase FileReference model can be asked in Fluid without a custom ViewHelper:

    <f:if condition="{fileReference.originalResource.missing}">
        ...
    </f:if>

    Checking the real existence of the file for every reference on each request would require a storage access per file, which is intentionally not done by default. Where this matters, running the indexer regularly or checking $file->getStorage()->hasFile($file->getIdentifier()) in project code is the way to go. Also, f:image does not render an img tag for files flagged as missing anymore.

    I’m therefore closing this as “works as designed”.

    If this is still valid for you in v14, please open a new issue and provide information how to reproduce it. Thanks!