Fixed bug #5704: IRRE - Children on the table pages get the pid of the parent page...
authorOliver Hader <oliver.hader@typo3.org>
Sat, 14 Jul 2007 14:07:06 +0000 (14:07 +0000)
committerOliver Hader <oliver.hader@typo3.org>
Sat, 14 Jul 2007 14:07:06 +0000 (14:07 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@2412 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
t3lib/class.t3lib_tceforms_inline.php
t3lib/class.t3lib_tcemain.php

index a8d2fae..a330145 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,6 @@
+2007-07-14  Oliver Hader  <oh@inpublica.de>
+
+       * Fixed bug #5704: IRRE - Children on the table pages get the pid of the parent page in pagetree
 
 2007-07-14  Martin Kutschker  <martin.t.kutschker@blackbox.net>
 
index e336fb1..5c0984d 100755 (executable)
@@ -158,11 +158,14 @@ class t3lib_TCEforms_inline {
                                $inlineView = unserialize($GLOBALS['BE_USER']->uc['inlineView']);
                                $this->inlineView = $inlineView[$table][$row['uid']];
                        }
-                               // if pid is negative, fetch the previous record and take its pid
-                       if ($row['pid'] < 0) {
+                               // If the parent is a page, use the uid(!) of the (new?) page as pid for the child records:
+                       if ($table == 'pages') {
+                               $this->inlineFirstPid = $row['uid'];
+                               // If pid is negative, fetch the previous record and take its pid:
+                       } elseif ($row['pid'] < 0) {
                                $prevRec = t3lib_BEfunc::getRecord($table, abs($row['pid']));
                                $this->inlineFirstPid = $prevRec['pid'];
-                               // take the pid as it is
+                               // Take the pid as it is:
                        } else {
                                $this->inlineFirstPid = $row['pid'];
                        }
@@ -1305,15 +1308,22 @@ class t3lib_TCEforms_inline {
 
                        // If the command is to create a NEW record...:
                if ($cmd=='new') {
-                       $calcPRec = t3lib_BEfunc::getRecord('pages',$this->inlineFirstPid);
-                       if(!is_array($calcPRec)) {
-                               return false;
-                       }
-                       $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);        // Permissions for the parent page
-                       if ($table=='pages')    {       // If pages:
-                               $hasAccess = $CALC_PERMS&8 ? 1 : 0; // Are we allowed to create new subpages?
+                               // If the pid is numerical, check if it's possible to write to this page:
+                       if (t3lib_div::testInt($this->inlineFirstPid)) {
+                               $calcPRec = t3lib_BEfunc::getRecord('pages', $this->inlineFirstPid);
+                               if(!is_array($calcPRec)) {
+                                       return false;
+                               }
+                               $CALC_PERMS = $GLOBALS['BE_USER']->calcPerms($calcPRec);        // Permissions for the parent page
+                               if ($table=='pages')    {       // If pages:
+                                       $hasAccess = $CALC_PERMS&8 ? 1 : 0; // Are we allowed to create new subpages?
+                               } else {
+                                       $hasAccess = $CALC_PERMS&16 ? 1 : 0; // Are we allowed to edit content on this page?
+                               }
+                               // If the pid is a NEW... value, the access will be checked on creating the page:
+                               // (if the page with the same NEW... value could be created in TCEmain, this child record can neither)
                        } else {
-                               $hasAccess = $CALC_PERMS&16 ? 1 : 0; // Are we allowed to edit content on this page?
+                               $hasAccess = 1;
                        }
                } else {        // Edit:
                        $calcPRec = t3lib_BEfunc::getRecord($table,$theUid);
index 58732c0..aece98a 100755 (executable)
@@ -333,6 +333,7 @@ class t3lib_TCEmain {
        var $removeFilesStore=array();                          // For accumulation of files which must be deleted after processing of all input content
        var $uploadedFileArray = array();                       // Uploaded files, set by process_uploads()
        var $registerDBList=array();                            // Used for tracking references that might need correction after operations
+       var $registerDBPids=array();                            // Used for tracking references that might need correction in pid field after operations (e.g. IRRE)
        var $copyMappingArray = Array();                        // Used by the copy action to track the ids of new pages so subpages are correctly inserted! THIS is internally cleared for each executed copy operation! DO NOT USE THIS FROM OUTSIDE! Read from copyMappingArray_merged instead which is accumulating this information.
        var $remapStack = array();                                      // array used for remapping uids and values at the end of process_datamap
        var $remapStackRecords = array();                       // array used for remapping uids and values at the end of process_datamap (e.g. $remapStackRecords[<table>][<uid>] = <index in $remapStack>)
@@ -2868,6 +2869,15 @@ class t3lib_TCEmain      {
                                } else {
                                        $newId = $this->copyRecord_raw($v['table'], $v['id'], $realDestPid);
                                }
+
+                                       // If the current field is set on a page record, update the pid of related child records:
+                               if ($table == 'pages') {
+                                       $this->registerDBPids[$v['table']][$v['id']] = $uid;
+                                       // If the current field has ancestors that have a field on a page record, update the pid of related child records:
+                               } elseif (isset($this->registerDBPids[$table][$uid])) {
+                                       $this->registerDBPids[$v['table']][$v['id']] = $this->registerDBPids[$table][$uid];
+                               }
+
                                $dbAnalysis->itemArray[$k]['id'] = $newId;
                        }
 
@@ -4381,7 +4391,7 @@ $this->log($table,$id,6,0,0,'Stage raised...',30,array('comment'=>$comment,'stag
         * @param       string          $value: Field value
         * @param       integer         $uid: The uid of the ORIGINAL record
         * @param       string          $table: Table name
-        * @return      string          The value to be updated on the table field in the database
+        * @return      void
         */
        function remapListedDBRecords_procInline($conf, $value, $uid, $table) {
                $theUidToUpdate = $this->copyMappingArray_merged[$table][$uid];
@@ -4389,14 +4399,37 @@ $this->log($table,$id,6,0,0,'Stage raised...',30,array('comment'=>$comment,'stag
                if ($conf['foreign_table']) {
                        $inlineType = $this->getInlineFieldType($conf);
 
-                       if ($inlineType == 'field') {
+                       if ($inlineType == 'mm') {
+                               $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table);
+
+                       } elseif ($inlineType !== false) {
                                $dbAnalysis = t3lib_div::makeInstance('t3lib_loadDBGroup');
-                               $dbAnalysis->start($value, $conf['foreign_table'], $conf['MM'], 0, $table, $conf);
+                               $dbAnalysis->start($value, $conf['foreign_table'], '', 0, $table, $conf);
+
+                                       // If the current field is set on a page record, update the pid of related child records:
+                               if ($table == 'pages') {
+                                       $thePidToUpdate = $theUidToUpdate;
+                                       // If the current field has ancestors that have a field on a page record, update the pid of related child records:
+                               } elseif (isset($this->registerDBPids[$table][$uid])) {
+                                       $thePidToUpdate = $this->registerDBPids[$table][$uid];
+                                       $thePidToUpdate = $this->copyMappingArray_merged['pages'][$thePidToUpdate];
+                               }
 
-                               $dbAnalysis->writeForeignField($conf, $uid, $theUidToUpdate);
-                       } elseif ($inlineType == 'mm') {
-                               $vArray = $this->remapListedDBRecords_procDBRefs($conf, $value, $theUidToUpdate, $table);
-                       }
+                                       // Update child records if using pointer fields ('foreign_field'):
+                               if ($inlineType == 'field') {
+                                       $dbAnalysis->writeForeignField($conf, $uid, $theUidToUpdate);
+                               }
+
+                                       // Update child records if change to pid is required: 
+                               if ($thePidToUpdate) {
+                                       $updateValues = array('pid' => $thePidToUpdate);
+                                       foreach ($dbAnalysis->itemArray as $v) {
+                                               if ($v['id'] && $v['table']) {
+                                                       $GLOBALS['TYPO3_DB']->exec_UPDATEquery($v['table'], 'uid='.intval($v['id']), $updateValues);
+                                               }
+                                       }
+                               }
+                       }                       
                }
        }