[+TASK] Extbase (Persistence): The storage pid is now added to relation tables define...
authorJochen Rau <j.rau@web.de>
Tue, 30 Mar 2010 09:28:58 +0000 (09:28 +0000)
committerJochen Rau <j.rau@web.de>
Tue, 30 Mar 2010 09:28:58 +0000 (09:28 +0000)
typo3/sysext/extbase/Classes/Persistence/Backend.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMap.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapFactory.php

index d02d2dc..57a1261 100644 (file)
@@ -704,6 +704,10 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                // if (isset($childTableName)) {
                //      $row['tablenames'] = $childTableName;
                // }
+               $pageIdColumnName = $dataMap->getPageIdColumnName();
+               if ($pageIdColumnName !== NULL) {
+                       $row[$pageIdColumnName] = $this->determineStoragePageIdForNewRecord();
+               }
                
                $relationTableInsertFields = $columnMap->getRelationTableInsertFields();
                if (count($relationTableInsertFields)) {
@@ -896,16 +900,16 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
         * @param Tx_Extbase_DomainObject_DomainObjectInterface $object
         * @return int the storage Page ID where the object should be stored
         */
-       protected function determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface $object) {
-               $className = get_class($object);
+       protected function determineStoragePageIdForNewRecord(Tx_Extbase_DomainObject_DomainObjectInterface $object = NULL) {
                $extbaseSettings = Tx_Extbase_Dispatcher::getExtbaseFrameworkConfiguration();
-
-               if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'])) {
-                       return (int)$extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'];
-               } else {
-                       $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['persistence']['storagePid']);
-                       return (int) $storagePidList[0];
+               if ($object !== NULL) {
+                       $className = get_class($object);
+                       if (isset($extbaseSettings['persistence']['classes'][$className]) && !empty($extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'])) {
+                               return (int)$extbaseSettings['persistence']['classes'][$className]['newRecordStoragePid'];
+                       }
                }
+               $storagePidList = t3lib_div::intExplode(',', $extbaseSettings['persistence']['storagePid']);
+               return (int) $storagePidList[0];
        }
        
        /**
index 00634da..7251011 100644 (file)
@@ -55,6 +55,11 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
        /**
         * @var string
         **/
+       protected $pageIdColumnName;
+
+       /**
+        * @var string
+        **/
        protected $modificationDateColumnName;
 
        /**
@@ -168,6 +173,27 @@ class Tx_Extbase_Persistence_Mapper_DataMap {
                return isset($this->columnMaps[$propertyName]);
        }
        
+       
+       /**
+        * Sets the name of a column holding the page id
+        *
+        * @param string The field name
+        * @return void
+        */
+       public function setPageIdColumnName($pageIdColumnName) {
+               $this->pageIdColumnName = $pageIdColumnName;
+       }
+       
+       /**
+        * Sets the name of a column holding the page id
+        *
+        * @return string The field name
+        */
+       public function getPageIdColumnName() {
+               return $this->pageIdColumnName;
+       }
+       
+
        /**
         * Sets the name of a column holding the timestamp the record was modified
         *
index 383bd80..c627483 100644 (file)
@@ -67,7 +67,6 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
                if ($tableName === NULL) {
                        $tableName = strtolower($className);
                }
-               
                $dataMap = t3lib_div::makeInstance('Tx_Extbase_Persistence_Mapper_DataMap', $className, $tableName);
                $dataMap = $this->addMetaDataColumnNames($dataMap, $tableName);
                $columnConfigurations = array();
@@ -81,7 +80,6 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
                        $columnMap = $this->setRelations($columnMap, $columnConfiguration);
                        $dataMap->addColumnMap($columnMap);
                }
-               // debug($dataMap);
                return $dataMap;
        }
 
@@ -102,6 +100,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
        
        protected function addMetaDataColumnNames(Tx_Extbase_Persistence_Mapper_DataMap $dataMap, $tableName) {
                $controlSection = $GLOBALS['TCA'][$tableName]['ctrl'];
+               $dataMap->setPageIdColumnName('pid');
                if (isset($controlSection['tstamp'])) $dataMap->setModificationDateColumnName($controlSection['tstamp']);
                if (isset($controlSection['crdate'])) $dataMap->setCreationDateColumnName($controlSection['crdate']);
                if (isset($controlSection['cruser_id'])) $dataMap->setCreatorColumnName($controlSection['cruser_id']);
@@ -208,11 +207,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
                        }
                } elseif (isset($columnConfiguration['foreign_selector'])) {
                        $columns = $this->getColumnsDefinition($columnConfiguration['foreign_table']);
-                       if (isset($columnConfiguration['foreign_selector'])) {
-                               $childKeyFieldName = $columnConfiguration['foreign_selector'];
-                       } else {
-                               $childKeyFieldName = 'uid_foreign';
-                       }
+                       $childKeyFieldName = $columnConfiguration['foreign_selector'];
                        $columnMap->setChildTableName($columns[$childKeyFieldName]['config']['foreign_table']);
                        $columnMap->setRelationTableName($columnConfiguration['foreign_table']);
                        $columnMap->setParentKeyFieldName($columnConfiguration['foreign_field']);
@@ -221,6 +216,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapFactory {
                } else {
                        throw new Tx_Extbase_Persistence_Exception_UnsupportedRelation('The given information to build a many-to-many-relation was not sufficient. Check your TCA definitions. mm-relations with IRRE must have at least a defined "MM" or "foreign_selector".', 1268817963);
                }
+               // debug($columnMap);
                return $columnMap;
        }