[BUGFIX] Catch Exception while extracting metadata 40/56540/2
authorrickymk <ricky.mk@pitsolutions.com>
Tue, 29 Aug 2017 11:18:10 +0000 (16:48 +0530)
committerNicole Cordes <typo3@cordes.co>
Thu, 5 Apr 2018 21:43:31 +0000 (23:43 +0200)
Catch InsufficientFileAccessPermissionsException while extracting
metadata. Reason for this exception could be that the file extension is
not allowed by the ['BE']['fileDenyPattern'] setting.

This patch makes sure that the indexer doesn't break and is able to
extract the other files from storage.

Resolves: #82060
Release: master, 8.7, 7.6
Change-Id: I37950aa70f4f59b388c6b9203e1922708ad07b71
Reviewed-on: https://review.typo3.org/56540
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Stephan GroƟberndt <stephan.grossberndt@typo3.org>
Reviewed-by: Nicole Cordes <typo3@cordes.co>
Tested-by: Nicole Cordes <typo3@cordes.co>
typo3/sysext/core/Classes/Resource/Index/Indexer.php

index 2913657..20400bd 100644 (file)
@@ -14,6 +14,8 @@ namespace TYPO3\CMS\Core\Resource\Index;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Resource\Exception\IllegalFileExtensionException;
+use TYPO3\CMS\Core\Resource\Exception\InsufficientFileAccessPermissionsException;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\Resource\ResourceStorage;
 use TYPO3\CMS\Core\Type\File\ImageInfo;
@@ -107,7 +109,20 @@ class Indexer
         $fileIndexRecords = $this->getFileIndexRepository()->findInStorageWithIndexOutstanding($this->storage, $maximumFileCount);
         foreach ($fileIndexRecords as $indexRecord) {
             $fileObject = $this->getResourceFactory()->getFileObject($indexRecord['uid'], $indexRecord);
-            $this->extractMetaData($fileObject);
+
+            // Check for existence of file before extraction
+            if ($fileObject->exists()) {
+                try {
+                    $this->extractMetaData($fileObject);
+                } catch (InsufficientFileAccessPermissionsException $e) {
+                    //  We skip files that are not accessible
+                } catch (IllegalFileExtensionException $e) {
+                    //  We skip files that have an extension that we don't allow
+                }
+            } else {
+                // Mark file as missing and continue with next record
+                $this->getFileIndexRepository()->markFileAsMissing($indexRecord['uid']);
+            }
         }
     }