[BUGFIX] Create valid file reference index data 45/26645/2
authorAlexander Stehlik <alexander.stehlik@googlemail.com>
Tue, 10 Dec 2013 12:25:03 +0000 (13:25 +0100)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 16 Jan 2014 21:52:11 +0000 (22:52 +0100)
This patch prevents the creation of sys_refindex entries that point to no
table and no record.

Additionally it fixes the array structure for the creation of
sys_refindex records for sys_file relations.

For deleted file references no reference will be created between
sys_file and the referenced table.

The configuration for the uid_foreign field was changed from a select
field for tt_content records to a normal input field to prevent the
creation of invalid refindex data. To which table uid_foreign is
pointing depends on the tablenames field.

To make sure both sides of the relation of a sys_file_reference appear
in the refindex table the exclusion of sys_file_reference as
foreign_table is removed.

Resolves: #53712
Releases: 6.2, 6.1, 6.0
Change-Id: Ic864ade10e4e97fbd9017b9c779be68d911dd626
Reviewed-on: https://review.typo3.org/26645
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/core/Configuration/TCA/sys_file_reference.php

index 6df93cd..b918c67 100644 (file)
@@ -538,10 +538,10 @@ class ReferenceIndex {
                        $dbAnalysis->start($value, $allowedTables, $conf['MM'], $uid, $table, $conf);
                        return $dbAnalysis->itemArray;
                } elseif ($conf['type'] == 'inline' && $conf['foreign_table'] == 'sys_file_reference') {
-                       $files = (array) $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid_local', 'sys_file_reference', ('tablenames=\'' . $table . '\' AND fieldname=\'' . $field . '\' AND uid_foreign=' . $uid));
-                       $fileArray = array('0' => array());
+                       $files = (array)$GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid_local', 'sys_file_reference', ('tablenames=\'' . $table . '\' AND fieldname=\'' . $field . '\' AND uid_foreign=' . $uid . ' AND deleted=0'));
+                       $fileArray = array();
                        foreach ($files as $fileUid) {
-                               $fileArray[0][] = array('table' => 'sys_file', 'id' => $fileUid);
+                               $fileArray[] = array('table' => 'sys_file', 'id' => $fileUid['uid_local']);
                        }
                        return $fileArray;
                } elseif ($conf['type'] == 'input' && isset($conf['wizards']['link']) && trim($value)) {
@@ -803,7 +803,13 @@ class ReferenceIndex {
         * @todo Define visibility
         */
        public function isReferenceField($conf) {
-               return $conf['type'] == 'group' && $conf['internal_type'] == 'db' || ($conf['type'] == 'select' || $conf['type'] == 'inline') && $conf['foreign_table'] && $conf['foreign_table'] !== 'sys_file_reference';
+               return (
+                       ($conf['type'] == 'group' && $conf['internal_type'] == 'db')
+                       || (
+                               ($conf['type'] == 'select' || $conf['type'] == 'inline')
+                               && $conf['foreign_table']
+                       )
+               );
        }
 
        /**
index b8548a4..fa54ed1 100644 (file)
@@ -93,15 +93,9 @@ return array(
                        'exclude' => 0,
                        'label' => 'LLL:EXT:lang/locallang_tca.xlf:sys_file_reference.uid_foreign',
                        'config' => array(
-                               'type' => 'select',
-                               'items' => array(
-                                       array('', 0)
-                               ),
-                               'foreign_table' => 'tt_content',
-                               'foreign_table_where' => 'ORDER BY tt_content.uid',
-                               'size' => 1,
-                               'minitems' => 0,
-                               'maxitems' => 1
+                               'type' => 'input',
+                               'size' => '10',
+                               'eval' => 'int'
                        )
                ),
                'tablenames' => array(