[BUGFIX] Gracefully show missing files in IRRE relations 89/36489/3
authorJan Helke <typo3@helke.de>
Thu, 17 Apr 2014 13:24:58 +0000 (15:24 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sat, 31 Jan 2015 11:01:41 +0000 (12:01 +0100)
When the database is inconsistent and a sys_file entry linked
from sys_file_reference does not exist anymore, an exception
is shown in the "page" module in the backend:

> No file found for given UID.

We will now gracefully show the reference as "broken" and let
the action up to the editor. Works for temporarily unavailable
storages too.

Releases: master, 6.2
Resolves: #58013
Change-Id: Ibce9bb3b60e9294aa1902b95c1b99337d3a8e2e6
Reviewed-on: http://review.typo3.org/36489
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Utility/BackendUtility.php
typo3/sysext/core/Classes/Resource/Exception/InvalidUidException.php [new file with mode: 0644]
typo3/sysext/core/Classes/Resource/Index/MetaDataRepository.php
typo3/sysext/core/Classes/Resource/Service/UserFileInlineLabelService.php

index e790986..183dc6c 100644 (file)
@@ -1531,8 +1531,15 @@ class BackendUtility {
                $referenceUids = $relationHandler->tableArray[$configuration['foreign_table']];
 
                foreach ($referenceUids as $referenceUid) {
-                       $fileReference = ResourceFactory::getInstance()->getFileReferenceObject($referenceUid, array(), ($workspaceId === 0));
-                       $fileReferences[$fileReference->getUid()] = $fileReference;
+                       try {
+                               $fileReference = ResourceFactory::getInstance()->getFileReferenceObject($referenceUid, array(), ($workspaceId === 0));
+                               $fileReferences[$fileReference->getUid()] = $fileReference;
+                       } catch (\TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException $e) {
+                               /**
+                                * We just catch the exception here
+                                * Reasoning: There is nothing an editor or even admin could do
+                                */
+                       }
                }
 
                return $fileReferences;
diff --git a/typo3/sysext/core/Classes/Resource/Exception/InvalidUidException.php b/typo3/sysext/core/Classes/Resource/Exception/InvalidUidException.php
new file mode 100644 (file)
index 0000000..3ac1e0c
--- /dev/null
@@ -0,0 +1,22 @@
+<?php
+namespace TYPO3\CMS\Core\Resource\Exception;
+
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Thrown if an invalid uid is handled.
+ */
+class InvalidUidException extends \TYPO3\CMS\Core\Resource\Exception {
+
+}
\ No newline at end of file
index 5b758d2..873e6ad 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Core\Resource\Index;
 use TYPO3\CMS\Core\Resource\File;
 use TYPO3\CMS\Core\SingletonInterface;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Resource\Exception\InvalidUidException;
 use TYPO3\CMS\Core\Type\File as FileType;
 
 /**
@@ -91,7 +92,7 @@ class MetaDataRepository implements SingletonInterface {
        public function findByFileUid($uid) {
                $uid = (int)$uid;
                if ($uid <= 0) {
-                       throw new \RuntimeException('Metadata can only be retrieved for indexed files.', 1381590731);
+                       throw new InvalidUidException('Metadata can only be retrieved for indexed files. UID: "' . $uid . '"', 1381590731);
                }
                $record = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $this->tableName, 'file = ' . $uid . $this->getGeneralWhereClause());
 
@@ -241,4 +242,4 @@ class MetaDataRepository implements SingletonInterface {
        public static function getInstance() {
                return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
        }
-}
\ No newline at end of file
+}
index a67c7ca..9b2ed9e 100644 (file)
@@ -51,9 +51,16 @@ class UserFileInlineLabelService {
                                if (isset($params['row']['title'])) {
                                        $fullTitle = $params['row']['title'];
                                } else {
-                                       $metaDataRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
-                                       $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
-                                       $fullTitle = $metaData['title'];
+                                       try {
+                                               $metaDataRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Resource\\Index\\MetaDataRepository');
+                                               $metaData = $metaDataRepository->findByFileUid($fileRecord['uid']);
+                                               $fullTitle = $metaData['title'];
+                                       } catch (\TYPO3\CMS\Core\Resource\Exception\InvalidUidException $e) {
+                                               /**
+                                                * We just catch the exception here
+                                                * Reasoning: There is nothing an editor or even admin could do
+                                                */
+                                       }
                                }
 
                                $value = BackendUtility::getRecordTitlePrep(htmlspecialchars($fullTitle));