[BUGFIX] Prevent wrong ref_index for fields with soft references 72/37372/2
authorNicole Cordes <typo3@cordes.co>
Thu, 19 Feb 2015 09:55:13 +0000 (10:55 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 28 Feb 2015 20:09:05 +0000 (21:09 +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.

Because the functional tests of impexp extension still use a hardcoded
file path for the header_link field the patch corrects the value to
refer to a file.

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: I969224e2a291491cb7ece1f61b375071bf0eaebc
Reviewed-on: http://review.typo3.org/37372
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/core/Classes/Database/ReferenceIndex.php
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/tt_content.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExportXml/pages-and-ttcontent.xml
typo3/sysext/impexp/Tests/Functional/Import/PagesAndTtContent/DataSet/Assertion/importPagesAndRelatedTtContent.csv

index 86f87e4..16cafe8 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Core\Database;
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
  * Reference index processing and relation extraction
@@ -325,7 +326,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
@@ -618,7 +622,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']) && StringUtility::beginsWith($value, 'file:')) {
                        try {
                                $file = \TYPO3\CMS\Core\Resource\ResourceFactory::getInstance()->retrieveFileOrFolderObject($value);
                        } catch (\Exception $e) {
index 6a7a7b6..420f7cb 100644 (file)
@@ -5,7 +5,7 @@
                <pid>1</pid>
                <CType>text</CType>
                <header>Test content</header>
-               <header_link>fileadmin/user_upload/typo3_image3.jpg</header_link>
+               <header_link>file:2</header_link>
                <deleted>0</deleted>
                <t3ver_oid>0</t3ver_oid>
                <t3ver_wsid>0</t3ver_wsid>
@@ -15,7 +15,7 @@
                <pid>1</pid>
                <CType>text</CType>
                <header>Test content 2</header>
-               <header_link>typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html</header_link>
+               <header_link>file:4</header_link>
                <deleted>0</deleted>
                <t3ver_oid>0</t3ver_oid>
                <t3ver_wsid>0</t3ver_wsid>
index 9c839ba..2a1be52 100644 (file)
@@ -29,7 +29,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test content</title>
-                                       <size>230</size>
+                                       <size>197</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:2" type="array">
                                                        <table>sys_file</table>
                                                </element>
                                        </relations>
                                        <softrefs type="array">
+                                               <softref_element index="header_link:typolink:2487ce518ed56d22f20f259928ff43f1:0" type="array">
+                                                       <field>header_link</field>
+                                                       <spKey>typolink</spKey>
+                                                       <matchString>file:2</matchString>
+                                                       <subst type="array">
+                                                               <type>db</type>
+                                                               <recordRef>sys_file:2</recordRef>
+                                                               <tokenID>2487ce518ed56d22f20f259928ff43f1</tokenID>
+                                                               <tokenValue>file:2</tokenValue>
+                                                       </subst>
+                                               </softref_element>
                                        </softrefs>
                                </rec>
                                <rec index="2" type="array">
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Test content 2</title>
-                                       <size>264</size>
+                                       <size>199</size>
                                        <relations index="rels" type="array">
                                                <element index="sys_file:4" type="array">
                                                        <table>sys_file</table>
                                                <softref_element index="header_link:typolink:81b8b33df54ef433f1cbc7c3e513e6c4:0" type="array">
                                                        <field>header_link</field>
                                                        <spKey>typolink</spKey>
-                                                       <matchString>typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html</matchString>
+                                                       <matchString>file:4</matchString>
+                                                       <subst type="array">
+                                                               <type>db</type>
+                                                               <recordRef>sys_file:4</recordRef>
+                                                               <tokenID>81b8b33df54ef433f1cbc7c3e513e6c4</tokenID>
+                                                               <tokenValue>file:4</tokenValue>
+                                                       </subst>
                                                </softref_element>
                                        </softrefs>
                                </rec>
                                <field index="CType">text</field>
                                <field index="header">Test content</field>
                                <field index="deleted">0</field>
-                               <field index="header_link">fileadmin/user_upload/typo3_image3.jpg</field>
+                               <field index="header_link">file:2</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="header_link" type="array">
                                                        <id>2</id>
                                                </element>
                                        </relations>
+                                       <softrefs type="array">
+                                               <keys type="array">
+                                                       <softref_key index="typolink" type="array">
+                                                               <softref_element index="2487ce518ed56d22f20f259928ff43f1:0" type="array">
+                                                                       <matchString>file:2</matchString>
+                                                                       <subst type="array">
+                                                                               <type>db</type>
+                                                                               <recordRef>sys_file:2</recordRef>
+                                                                               <tokenID>2487ce518ed56d22f20f259928ff43f1</tokenID>
+                                                                               <tokenValue>file:2</tokenValue>
+                                                                       </subst>
+                                                               </softref_element>
+                                                       </softref_key>
+                                               </keys>
+                                               <tokenizedContent>{softref:2487ce518ed56d22f20f259928ff43f1}</tokenizedContent>
+                                       </softrefs>
                                </field>
                        </related>
                </tablerow>
                                <field index="CType">text</field>
                                <field index="header">Test content 2</field>
                                <field index="deleted">0</field>
-                               <field index="header_link">typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html</field>
+                               <field index="header_link">file:4</field>
                        </fieldlist>
                        <related index="rels" type="array">
                                <field index="header_link" type="array">
                                                <keys type="array">
                                                        <softref_key index="typolink" type="array">
                                                                <softref_element index="81b8b33df54ef433f1cbc7c3e513e6c4:0" type="array">
-                                                                       <matchString>typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html</matchString>
+                                                                       <matchString>file:4</matchString>
+                                                                       <subst type="array">
+                                                                               <type>db</type>
+                                                                               <recordRef>sys_file:4</recordRef>
+                                                                               <tokenID>81b8b33df54ef433f1cbc7c3e513e6c4</tokenID>
+                                                                               <tokenValue>file:4</tokenValue>
+                                                                       </subst>
                                                                </softref_element>
                                                        </softref_key>
                                                </keys>
+                                               <tokenizedContent>{softref:81b8b33df54ef433f1cbc7c3e513e6c4}</tokenizedContent>
                                        </softrefs>
                                </field>
                        </related>
index 8c3a3db..45e833e 100644 (file)
@@ -4,8 +4,8 @@
 ,2,1,256,0,"Dummy 1-2"
 "tt_content"
 ,"uid","pid","sorting","deleted","header","header_link"
-,1,1,256,0,"Test content 2","typo3conf/ext/template_extension/Resources/Public/Templates/Empty.html"
-,2,1,128,0,"Test content","fileadmin/user_upload/typo3_image3.jpg"
+,1,1,256,0,"Test content 2","file:2"
+,2,1,128,0,"Test content","file:1"
 "sys_file"
 ,"uid","pid","storage","type","identifier","identifier_hash","folder_hash","extension","mime_type","name","sha1","size"
 ,1,0,1,2,"/user_upload/typo3_image3.jpg","25777b72e5e1cbed2d1b33e4fe5b737304b5bd28","19669f1e02c2f16705ec7587044c66443be70725","jpg","image/jpeg","typo3_image3.jpg","e873c1e2ffd0f191e183a1057de3eef4d62e782d","5565"