[BUGFIX] Opposite MM relation between both new entities not created 52/49352/2
authorOliver Hader <oliver@typo3.org>
Tue, 2 Aug 2016 22:32:11 +0000 (00:32 +0200)
committerOliver Hader <oliver.hader@typo3.org>
Wed, 3 Aug 2016 16:39:42 +0000 (18:39 +0200)
Scenario:
* usage in a workspace
* tt_content and sys_category records are created at the same time
  with defining an MM relation
* sys_category.items (group/db field, with MM and opposite usage
  defined) is filled with accordant tt_content record

Problem:
* the remap-stack in DataHandler does not consider references that
  are defined in a group/db field
* thus, these kind of relations are just not set, since the opposite
  reference uid cannot be resolved

Solution:
* process group/db relations with new record uids in remap-stack

Resolves: #77374
Releases: master, 7.6
Change-Id: If5e6589e2a0995dc4fce3ff49bd309f2fdb6eb24
Reviewed-on: https://review.typo3.org/49337
Reviewed-on: https://review.typo3.org/49352
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
typo3/sysext/core/Classes/DataHandling/DataHandler.php
typo3/sysext/workspaces/Tests/Functional/DataHandling/ManyToMany/Modify/DataSet/createCategoryNCreateRelation.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/ManyToMany/Publish/DataSet/createCategoryNCreateRelation.csv
typo3/sysext/workspaces/Tests/Functional/DataHandling/ManyToMany/PublishAll/DataSet/createCategoryNCreateRelation.csv

index ba72da4..9902a45 100644 (file)
@@ -2106,31 +2106,30 @@ class DataHandler
         if ($tcaFieldConf['type'] == 'group') {
             switch ($tcaFieldConf['internal_type']) {
                 case 'file_reference':
-
                 case 'file':
                     $valueArray = $this->checkValue_group_select_file($valueArray, $tcaFieldConf, $curValue, $uploadedFiles, $status, $table, $id, $recFID);
                     break;
-                case 'db':
-                    $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'group', $table, $field);
-                    break;
             }
         }
         // For select types which has a foreign table attached:
         $unsetResult = false;
-        if ($tcaFieldConf['type'] === 'select' && ($tcaFieldConf['foreign_table'] || isset($tcaFieldConf['special']) && $tcaFieldConf['special'] === 'languages')) {
+        if (
+            $tcaFieldConf['type'] === 'group' && $tcaFieldConf['internal_type'] === 'db'
+            || $tcaFieldConf['type'] === 'select' && ($tcaFieldConf['foreign_table'] || isset($tcaFieldConf['special']) && $tcaFieldConf['special'] === 'languages')
+        ) {
             // check, if there is a NEW... id in the value, that should be substituted later
             if (strpos($value, 'NEW') !== false) {
                 $this->remapStackRecords[$table][$id] = array('remapStackIndex' => count($this->remapStack));
                 $this->addNewValuesToRemapStackChildIds($valueArray);
                 $this->remapStack[] = array(
                     'func' => 'checkValue_group_select_processDBdata',
-                    'args' => array($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field),
+                    'args' => array($valueArray, $tcaFieldConf, $id, $status, $tcaFieldConf['type'], $table, $field),
                     'pos' => array('valueArray' => 0, 'tcaFieldConf' => 1, 'id' => 2, 'table' => 5),
                     'field' => $field
                 );
                 $unsetResult = true;
             } else {
-                $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, 'select', $table, $field);
+                $valueArray = $this->checkValue_group_select_processDBdata($valueArray, $tcaFieldConf, $id, $status, $tcaFieldConf['type'], $table, $field);
             }
         }
         if (!$unsetResult) {
@@ -5913,16 +5912,27 @@ class DataHandler
                 }
                 // Replace relations to NEW...-IDs in field value (uids of child records):
                 if (is_array($valueArray)) {
-                    $foreign_table = $tcaFieldConf['foreign_table'];
                     foreach ($valueArray as $key => $value) {
                         if (strpos($value, 'NEW') !== false) {
+                            if (strpos($value, '_') === false) {
+                                $affectedTable = $tcaFieldConf['foreign_table'];
+                                $prependTable = false;
+                            } else {
+                                $parts = explode('_', $value);
+                                $value = array_pop($parts);
+                                $affectedTable = implode('_', $parts);
+                                $prependTable = true;
+                            }
                             $value = $this->substNEWwithIDs[$value];
                             // The record is new, but was also auto-versionized and has another new id:
-                            if (isset($this->autoVersionIdMap[$foreign_table][$value])) {
-                                $value = $this->autoVersionIdMap[$foreign_table][$value];
+                            if (isset($this->autoVersionIdMap[$affectedTable][$value])) {
+                                $value = $this->autoVersionIdMap[$affectedTable][$value];
+                            }
+                            if ($prependTable) {
+                                $value = $affectedTable . '_' . $value;
                             }
                             // Set a hint that this was a new child record:
-                            $this->newRelatedIDs[$foreign_table][] = $value;
+                            $this->newRelatedIDs[$affectedTable][] = $value;
                             $valueArray[$key] = $value;
                         }
                     }
index 7d2bd70..715924a 100644 (file)
@@ -5,13 +5,14 @@ sys_category
 ,30,0,768,0,0,0,0,0,0,0,0,"Category C",0,0
 ,31,0,1024,0,0,0,0,0,0,0,0,"Category A.A",28,0
 ,32,0,128,0,0,0,1,1,0,0,0,"Testing #1",0,0
-,33,-1,128,0,0,0,1,-1,0,32,0,"Testing #1",0,0
+,33,-1,128,0,0,0,1,-1,0,32,0,"Testing #1",0,1
 sys_category_record_mm
 ,uid_local,uid_foreign,tablenames,sorting,sorting_foreign,fieldname
 ,28,297,tt_content,0,1,categories
 ,29,297,tt_content,0,2,categories
 ,29,298,tt_content,0,1,categories
 ,30,298,tt_content,0,2,categories
+,33,300,tt_content,1,0,categories
 tt_content
 ,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories
 ,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",0,2
index 1d5064a..603364d 100644 (file)
@@ -4,13 +4,14 @@ sys_category
 ,29,0,512,0,0,0,0,0,0,0,0,"Category B",0,0
 ,30,0,768,0,0,0,0,0,0,0,0,"Category C",0,0
 ,31,0,1024,0,0,0,0,0,0,0,0,"Category A.A",28,0
-,32,0,128,0,0,0,0,0,0,0,0,"Testing #1",0,0
+,32,0,128,0,0,0,0,0,0,0,0,"Testing #1",0,1
 sys_category_record_mm
 ,uid_local,uid_foreign,tablenames,sorting,sorting_foreign,fieldname
 ,28,297,tt_content,0,1,categories
 ,29,297,tt_content,0,2,categories
 ,29,298,tt_content,0,1,categories
 ,30,298,tt_content,0,2,categories
+,32,299,tt_content,1,0,categories
 tt_content
 ,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories
 ,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",0,2
index 1d5064a..603364d 100644 (file)
@@ -4,13 +4,14 @@ sys_category
 ,29,0,512,0,0,0,0,0,0,0,0,"Category B",0,0
 ,30,0,768,0,0,0,0,0,0,0,0,"Category C",0,0
 ,31,0,1024,0,0,0,0,0,0,0,0,"Category A.A",28,0
-,32,0,128,0,0,0,0,0,0,0,0,"Testing #1",0,0
+,32,0,128,0,0,0,0,0,0,0,0,"Testing #1",0,1
 sys_category_record_mm
 ,uid_local,uid_foreign,tablenames,sorting,sorting_foreign,fieldname
 ,28,297,tt_content,0,1,categories
 ,29,297,tt_content,0,2,categories
 ,29,298,tt_content,0,1,categories
 ,30,298,tt_content,0,2,categories
+,32,299,tt_content,1,0,categories
 tt_content
 ,uid,pid,sorting,deleted,sys_language_uid,l18n_parent,t3ver_wsid,t3ver_state,t3ver_stage,t3ver_oid,t3ver_move_id,header,image,categories
 ,297,89,256,0,0,0,0,0,0,0,0,"Regular Element #1",0,2