typo3extbasefilereference

TYPO3 - Extbase - Detect missing files for a given FileReference


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 give me the right isMissing() value.


Solution

  • The property isMissing is an database value, which is set if the storage detect an missing file. On getFile the storage check if the file is missing and set "isMissing" for the file. If you dont persist this to the database, the setting is get loose with the next call.

    You can also call $isMissing = $fileReference->getOriginalResource()->getStorage()->hasFile($fileReference->getOriginalResource()->getIdentifier());

    You can run the file indexer scheduler (TYPO3\CMS\Scheduler\Task\FileStorageIndexingTask) if you want to check frequently for deleted files. This should be required if you let change files externaly (like ftp).