[BUGFIX] Prevent wrong ref_index for fields with soft references 77/37077/3
authorNicole Cordes <typo3@cordes.co>
Thu, 19 Feb 2015 09:55:13 +0000 (10:55 +0100)
committerMarkus Klein <klein.t3@reelworx.at>
Sat, 21 Feb 2015 19:07:28 +0000 (20:07 +0100)
If you add a page link to a field which is defined as softrefs, the
ReferenceIndex creates an index to a FAL record if there exists a file
record with the page id. As file links are always prefixed with 'file:'
this patch adds a proper check before generating a file ref_index.

Furthermore if you add a file or folder link, the field is referenced
twice for the FAL record. So we have to suppress the softreference for
those records.

Releases: master, 6.2
Resolves: #60226
Change-Id: Ieb9179d393e23eda4fdb1bb47ba4693bd92e75d9
Reviewed-on: http://review.typo3.org/37077
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/core/Classes/Database/ReferenceIndex.php

index 7365a5a..4a81165 100644 (file)
@@ -314,7 +314,10 @@ class ReferenceIndex {
                                                        switch ((string) $el['subst']['type']) {
                                                                case 'db':
                                                                        list($tableName, $recordId) = explode(':', $el['subst']['recordRef']);
-                                                                       $this->relations[] = $this->createEntryData($table, $uid, $fieldname, $flexpointer, $deleted, $tableName, $recordId, '', -1, $spKey, $subKey);
+                                                                       // Prevent double references for files and file relations
+                                                                       if ($tableName !== 'sys_file' && $tableName !== 'sys_file_reference') {
+                                                                               $this->relations[] = $this->createEntryData($table, $uid, $fieldname, $flexpointer, $deleted, $tableName, $recordId, '', -1, $spKey, $subKey);
+                                                                       }
                                                                        break;
                                                                case 'file_reference':
                                                                        // not used (see getRelations()), but fallback to file
@@ -607,7 +610,7 @@ class ReferenceIndex {
                                $fileArray[] = array('table' => 'sys_file', 'id' => $fileUid['uid_local']);
                        }
                        return $fileArray;
-               } elseif ($conf['type'] == 'input' && isset($conf['wizards']['link']) && trim($value)) {
+               } elseif ($conf['type'] == 'input' && isset($conf['wizards']['link']) && GeneralUtility::isFirstPartOfStr($value, 'file:')) {
                        try {
                                $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($value);
                        } catch (\Exception $e) {