[TASK] Limit the exported record fields in impexp 03/27303/8
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Mon, 3 Feb 2014 16:12:27 +0000 (17:12 +0100)
committerMarc Bastian Heinrichs <typo3@mbh-software.de>
Mon, 24 Feb 2014 13:25:40 +0000 (14:25 +0100)
To be able to compare mostly only the data provided in the
database fixtures, the export needs to be limited to a given
set of fields of a record type.
This will loose the strict xml comparison of all existing fields
in the database and the tests would not break whenever we
change ext:core or ext:frontend ext_tables.sql.

Resolves: #55625
Releases: 6.2
Change-Id: Ie48e540ab1c9e271b64b893353a84c34ac982a50
Reviewed-on: https://review.typo3.org/27303
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Tymoteusz Motylewski
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
typo3/sysext/impexp/Classes/ImportExport.php
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/pages.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/Database/tt_content.xml
typo3/sysext/impexp/Tests/Functional/Fixtures/ImportExport/pages-and-ttcontent.xml
typo3/sysext/impexp/Tests/Functional/ImportExport/ExportSimpleTest.php

index ad5f624..f1acc3a 100644 (file)
@@ -322,6 +322,21 @@ class ImportExport {
         */
        public $fileProcObj = '';
 
+       /**
+        * Keys are [recordname], values are an array of fields to be included
+        * in the export
+        *
+        * @var array
+        */
+       protected $recordTypesIncludeFields = array();
+
+       /**
+        * Default array of fields to be included in the export
+        *
+        * @var array
+        */
+       protected $defaultRecordIncludeFields = array('uid', 'pid');
+
        /**************************
         * Initialize
         *************************/
@@ -522,6 +537,33 @@ class ImportExport {
         *************************/
 
        /**
+        * Sets the fields of record types to be included in the export
+        *
+        * @param array $recordTypesIncludeFields Keys are [recordname], values are an array of fields to be included in the export
+        * @throws \TYPO3\CMS\Core\Exception if an array value is not type of array
+        * @return void
+        */
+       public function setRecordTypesIncludeFields(array $recordTypesIncludeFields) {
+               foreach ($recordTypesIncludeFields as $table => $fields) {
+                       if (!is_array($fields)) {
+                               throw new \TYPO3\CMS\Core\Exception('The include fields for record type ' . htmlspecialchars($table) . ' are not defined by an array.', 1391440658);
+                       }
+                       $this->setRecordTypeIncludeFields($table, $fields);
+               }
+       }
+
+       /**
+        * Sets the fields of a record type to be included in the export
+        *
+        * @param string $table The record type
+        * @param array $fields The fields to be included
+        * @return void
+        */
+       public function setRecordTypeIncludeFields($table, array $fields) {
+               $this->recordTypesIncludeFields[$table] = $fields;
+       }
+
+       /**
         * Adds the record $row from $table.
         * No checking for relations done here. Pure data.
         *
@@ -537,6 +579,7 @@ class ImportExport {
                        if ($this->checkPID($table === 'pages' ? $row['uid'] : $row['pid'])) {
                                if (!isset($this->dat['records'][($table . ':' . $row['uid'])])) {
                                        // Prepare header info:
+                                       $row = $this->filterRecordFields($table, $row);
                                        $headerInfo = array();
                                        $headerInfo['uid'] = $row['uid'];
                                        $headerInfo['pid'] = $row['pid'];
@@ -974,6 +1017,33 @@ class ImportExport {
                return $list;
        }
 
+       /**
+        * If include fields for a specific record type are set, the data
+        * are filtered out with fields are not included in the fields.
+        *
+        * @param string $table The record type to be filtered
+        * @param array $row The data to be filtered
+        * @return array The filtered record row
+        */
+       protected function filterRecordFields($table, array $row) {
+               if (isset($this->recordTypesIncludeFields[$table])) {
+                       $includeFields = array_unique(array_merge(
+                               $this->recordTypesIncludeFields[$table],
+                               $this->defaultRecordIncludeFields
+                       ));
+                       $newRow = array();
+                       foreach ($row as $key => $value) {
+                               if (in_array($key, $includeFields)) {
+                                       $newRow[$key] = $value;
+                               }
+                       }
+               } else {
+                       $newRow = $row;
+               }
+               return $newRow;
+       }
+
+
        /**************************
         * File Output
         *************************/
index b2f6e23..8f5b293 100644 (file)
@@ -4,6 +4,7 @@
                <uid>1</uid>
                <pid>0</pid>
                <title>Root</title>
+               <doktype>1</doktype>
                <deleted>0</deleted>
                <perms_everybody>15</perms_everybody>
        </pages>
@@ -11,6 +12,7 @@
                <uid>2</uid>
                <pid>1</pid>
                <title>Dummy 1-2</title>
+               <doktype>1</doktype>
                <deleted>0</deleted>
                <perms_everybody>15</perms_everybody>
        </pages>
index 49ceb10..e2d4f15 100644 (file)
@@ -1,11 +1,12 @@
 <?xml version="1.0" encoding="utf-8"?>
 <dataset>
-    <tt_content>
-        <uid>1</uid>
-        <pid>1</pid>
-        <header>Test content</header>
-        <deleted>0</deleted>
-        <t3ver_oid>0</t3ver_oid>
-        <t3ver_wsid>0</t3ver_wsid>
-    </tt_content>
+       <tt_content>
+               <uid>1</uid>
+               <pid>1</pid>
+               <CType>text</CType>
+               <header>Test content</header>
+               <deleted>0</deleted>
+               <t3ver_oid>0</t3ver_oid>
+               <t3ver_wsid>0</t3ver_wsid>
+       </tt_content>
 </dataset>
\ No newline at end of file
index 4dced36..037212d 100644 (file)
@@ -7,7 +7,7 @@
                                        <uid>1</uid>
                                        <pid>0</pid>
                                        <title>Root</title>
-                                       <size>1675</size>
+                                       <size>162</size>
                                        <relations index="rels" type="array">
                                        </relations>
                                        <softrefs type="array">
@@ -17,7 +17,7 @@
                                        <uid>2</uid>
                                        <pid>1</pid>
                                        <title>Dummy 1-2</title>
-                                       <size>1680</size>
+                                       <size>167</size>
                                        <relations index="rels" type="array">
                                        </relations>
                                        <softrefs type="array">
@@ -29,7 +29,7 @@
                                        <uid>1</uid>
                                        <pid>1</pid>
                                        <title>Test content</title>
-                                       <size>2068</size>
+                                       <size>165</size>
                                        <relations index="rels" type="array">
                                        </relations>
                                        <softrefs type="array">
                        <fieldlist index="data" type="array">
                                <field index="uid">1</field>
                                <field index="pid">0</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="t3ver_id">0</field>
-                               <field index="t3ver_wsid">0</field>
-                               <field index="t3ver_label"></field>
-                               <field index="t3ver_state">0</field>
-                               <field index="t3ver_stage">0</field>
-                               <field index="t3ver_count">0</field>
-                               <field index="t3ver_tstamp">0</field>
-                               <field index="t3ver_move_id">0</field>
-                               <field index="t3_origuid">0</field>
-                               <field index="tstamp">0</field>
-                               <field index="sorting">0</field>
                                <field index="deleted">0</field>
-                               <field index="perms_userid">0</field>
-                               <field index="perms_groupid">0</field>
-                               <field index="perms_user">0</field>
-                               <field index="perms_group">0</field>
                                <field index="perms_everybody">15</field>
-                               <field index="editlock">0</field>
-                               <field index="crdate">0</field>
-                               <field index="cruser_id">0</field>
                                <field index="hidden">0</field>
                                <field index="title">Root</field>
-                               <field index="doktype">0</field>
-                               <field index="TSconfig" type="NULL"></field>
-                               <field index="storage_pid">0</field>
-                               <field index="is_siteroot">0</field>
-                               <field index="php_tree_stop">0</field>
-                               <field index="tx_impexp_origuid">0</field>
-                               <field index="url"></field>
-                               <field index="starttime">0</field>
-                               <field index="endtime">0</field>
-                               <field index="urltype">0</field>
-                               <field index="shortcut">0</field>
-                               <field index="shortcut_mode">0</field>
-                               <field index="no_cache">0</field>
-                               <field index="fe_group">0</field>
-                               <field index="subtitle"></field>
-                               <field index="layout">0</field>
-                               <field index="url_scheme">0</field>
-                               <field index="target"></field>
-                               <field index="media" type="NULL"></field>
-                               <field index="lastUpdated">0</field>
-                               <field index="keywords" type="NULL"></field>
-                               <field index="cache_timeout">0</field>
-                               <field index="cache_tags"></field>
-                               <field index="newUntil">0</field>
-                               <field index="description" type="NULL"></field>
-                               <field index="no_search">0</field>
-                               <field index="SYS_LASTCHANGED">0</field>
-                               <field index="abstract" type="NULL"></field>
-                               <field index="module"></field>
-                               <field index="extendToSubpages">0</field>
-                               <field index="author"></field>
-                               <field index="author_email"></field>
-                               <field index="nav_title"></field>
-                               <field index="nav_hide">0</field>
-                               <field index="content_from_pid">0</field>
-                               <field index="mount_pid">0</field>
-                               <field index="mount_pid_ol">0</field>
-                               <field index="alias"></field>
-                               <field index="l18n_cfg">0</field>
-                               <field index="fe_login_mode">0</field>
-                               <field index="backend_layout"></field>
-                               <field index="backend_layout_next_level"></field>
-                               <field index="categories">0</field>
+                               <field index="doktype">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                        </related>
                        <fieldlist index="data" type="array">
                                <field index="uid">2</field>
                                <field index="pid">1</field>
-                               <field index="t3ver_oid">0</field>
-                               <field index="t3ver_id">0</field>
-                               <field index="t3ver_wsid">0</field>
-                               <field index="t3ver_label"></field>
-                               <field index="t3ver_state">0</field>
-                               <field index="t3ver_stage">0</field>
-                               <field index="t3ver_count">0</field>
-                               <field index="t3ver_tstamp">0</field>
-                               <field index="t3ver_move_id">0</field>
-                               <field index="t3_origuid">0</field>
-                               <field index="tstamp">0</field>
-                               <field index="sorting">0</field>
                                <field index="deleted">0</field>
-                               <field index="perms_userid">0</field>
-                               <field index="perms_groupid">0</field>
-                               <field index="perms_user">0</field>
-                               <field index="perms_group">0</field>
                                <field index="perms_everybody">15</field>
-                               <field index="editlock">0</field>
-                               <field index="crdate">0</field>
-                               <field index="cruser_id">0</field>
                                <field index="hidden">0</field>
                                <field index="title">Dummy 1-2</field>
-                               <field index="doktype">0</field>
-                               <field index="TSconfig" type="NULL"></field>
-                               <field index="storage_pid">0</field>
-                               <field index="is_siteroot">0</field>
-                               <field index="php_tree_stop">0</field>
-                               <field index="tx_impexp_origuid">0</field>
-                               <field index="url"></field>
-                               <field index="starttime">0</field>
-                               <field index="endtime">0</field>
-                               <field index="urltype">0</field>
-                               <field index="shortcut">0</field>
-                               <field index="shortcut_mode">0</field>
-                               <field index="no_cache">0</field>
-                               <field index="fe_group">0</field>
-                               <field index="subtitle"></field>
-                               <field index="layout">0</field>
-                               <field index="url_scheme">0</field>
-                               <field index="target"></field>
-                               <field index="media" type="NULL"></field>
-                               <field index="lastUpdated">0</field>
-                               <field index="keywords" type="NULL"></field>
-                               <field index="cache_timeout">0</field>
-                               <field index="cache_tags"></field>
-                               <field index="newUntil">0</field>
-                               <field index="description" type="NULL"></field>
-                               <field index="no_search">0</field>
-                               <field index="SYS_LASTCHANGED">0</field>
-                               <field index="abstract" type="NULL"></field>
-                               <field index="module"></field>
-                               <field index="extendToSubpages">0</field>
-                               <field index="author"></field>
-                               <field index="author_email"></field>
-                               <field index="nav_title"></field>
-                               <field index="nav_hide">0</field>
-                               <field index="content_from_pid">0</field>
-                               <field index="mount_pid">0</field>
-                               <field index="mount_pid_ol">0</field>
-                               <field index="alias"></field>
-                               <field index="l18n_cfg">0</field>
-                               <field index="fe_login_mode">0</field>
-                               <field index="backend_layout"></field>
-                               <field index="backend_layout_next_level"></field>
-                               <field index="categories">0</field>
+                               <field index="doktype">1</field>
                        </fieldlist>
                        <related index="rels" type="array">
                        </related>
                                <field index="uid">1</field>
                                <field index="pid">1</field>
                                <field index="t3ver_oid">0</field>
-                               <field index="t3ver_id">0</field>
-                               <field index="t3ver_wsid">0</field>
-                               <field index="t3ver_label"></field>
-                               <field index="t3ver_state">0</field>
-                               <field index="t3ver_stage">0</field>
-                               <field index="t3ver_count">0</field>
-                               <field index="t3ver_tstamp">0</field>
-                               <field index="t3ver_move_id">0</field>
-                               <field index="t3_origuid">0</field>
-                               <field index="tstamp">0</field>
-                               <field index="crdate">0</field>
-                               <field index="cruser_id">0</field>
                                <field index="hidden">0</field>
-                               <field index="sorting">0</field>
-                               <field index="CType" />
+                               <field index="CType">text</field>
                                <field index="header">Test content</field>
-                               <field index="header_position"></field>
-                               <field index="bodytext" type="NULL"></field>
-                               <field index="image" type="NULL"></field>
-                               <field index="imagewidth">0</field>
-                               <field index="imageorient">0</field>
-                               <field index="imagecaption" type="NULL"></field>
-                               <field index="imagecols">0</field>
-                               <field index="imageborder">0</field>
-                               <field index="media" type="NULL"></field>
-                               <field index="layout">0</field>
                                <field index="deleted">0</field>
-                               <field index="cols">0</field>
-                               <field index="records" type="NULL"></field>
-                               <field index="pages" type="NULL"></field>
-                               <field index="starttime">0</field>
-                               <field index="endtime">0</field>
-                               <field index="colPos">0</field>
-                               <field index="subheader"></field>
-                               <field index="spaceBefore">0</field>
-                               <field index="spaceAfter">0</field>
-                               <field index="fe_group">0</field>
-                               <field index="header_link"></field>
-                               <field index="imagecaption_position"></field>
-                               <field index="image_link" type="NULL"></field>
-                               <field index="image_zoom">0</field>
-                               <field index="image_noRows">0</field>
-                               <field index="image_effects">0</field>
-                               <field index="image_compression">0</field>
-                               <field index="altText" type="NULL"></field>
-                               <field index="titleText" type="NULL"></field>
-                               <field index="longdescURL" type="NULL"></field>
-                               <field index="header_layout">0</field>
-                               <field index="menu_type">0</field>
-                               <field index="list_type">0</field>
-                               <field index="table_border">0</field>
-                               <field index="table_cellspacing">0</field>
-                               <field index="table_cellpadding">0</field>
-                               <field index="table_bgColor">0</field>
-                               <field index="select_key"></field>
-                               <field index="sectionIndex">0</field>
-                               <field index="linkToTop">0</field>
-                               <field index="file_collections" type="NULL"></field>
-                               <field index="filelink_size">0</field>
-                               <field index="filelink_sorting"></field>
-                               <field index="target"></field>
-                               <field index="section_frame">0</field>
-                               <field index="date">0</field>
-                               <field index="multimedia" type="NULL"></field>
-                               <field index="image_frames">0</field>
-                               <field index="recursive">0</field>
-                               <field index="imageheight">0</field>
-                               <field index="rte_enabled">0</field>
-                               <field index="sys_language_uid">0</field>
-                               <field index="tx_impexp_origuid">0</field>
-                               <field index="pi_flexform" type="NULL"></field>
-                               <field index="accessibility_title"></field>
-                               <field index="accessibility_bypass">0</field>
-                               <field index="accessibility_bypass_text"></field>
-                               <field index="l18n_parent">0</field>
-                               <field index="l18n_diffsource" type="NULL"></field>
-                               <field index="selected_categories" type="NULL"></field>
-                               <field index="category_field"></field>
-                               <field index="categories">0</field>
                        </fieldlist>
                        <related index="rels" type="array">
                        </related>
index 4c4b166..23358b3 100644 (file)
@@ -54,7 +54,26 @@ class ExportSimpleTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
 
                /** @var $export \TYPO3\CMS\Impexp\ImportExport */
                $export = GeneralUtility::makeInstance('TYPO3\\CMS\\Impexp\\ImportExport');
-               $export->init();
+               $export->init(0, 'export');
+
+               $export->setRecordTypesIncludeFields(
+                       array(
+                               'pages' => array(
+                                       'title',
+                                       'deleted',
+                                       'doktype',
+                                       'hidden',
+                                       'perms_everybody'
+                               ),
+                               'tt_content' => array(
+                                       'CType',
+                                       'header',
+                                       'deleted',
+                                       'hidden',
+                                       't3ver_oid'
+                               )
+                       )
+               );
 
                $export->export_addRecord('pages', BackendUtility::getRecord('pages', 1));
                $export->export_addRecord('pages', BackendUtility::getRecord('pages', 2));
@@ -90,4 +109,4 @@ class ExportSimpleTest extends \TYPO3\CMS\Core\Tests\FunctionalTestCase {
                $this->assertXmlStringEqualsXmlFile(__DIR__ . '/../Fixtures/ImportExport/pages-and-ttcontent.xml', $out);
        }
 
-}
\ No newline at end of file
+}