简体   繁体   中英

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 (ie 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.

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM