[BUGFIX] Fix broken table name mapping for namespaced extension models
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Generic / Mapper / DataMapFactory.php
index e4cbd2e..bfb8d6b 100644 (file)
@@ -131,20 +131,7 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                }
                $recordType = NULL;
                $subclasses = array();
-               if (strpos($className, '\\') !== FALSE) {
-                       $classNameParts = explode('\\', $className, 4);
-                       if (isset($classNameParts[0]) && $classNameParts[0] === 'TYPO3' && isset($classNameParts[1]) && $classNameParts[1] === 'CMS') {
-                               $extensionKey = $classNameParts[2];
-                               $classNameWithoutVendorAndProduct = $classNameParts[3];
-                       } else {
-                               $extensionKey = $classNameParts[1];
-                               $classNameWithoutVendorAndProduct = $classNameParts[2];
-                       }
-                       $classNameWithoutVendorAndProduct = str_replace('\\', '_', $classNameWithoutVendorAndProduct);
-                       $tableName = strtolower('tx_' . $extensionKey . '_' . $classNameWithoutVendorAndProduct);
-               } else {
-                       $tableName = strtolower($className);
-               }
+               $tableName = $this->resolveTableName($className);
                $columnMapping = array();
                $frameworkConfiguration = $this->configurationManager->getConfiguration(\TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK);
                $classSettings = $frameworkConfiguration['persistence']['classes'][$className];
@@ -194,6 +181,28 @@ class DataMapFactory implements \TYPO3\CMS\Core\SingletonInterface {
                return $dataMap;
        }
 
+       /**
+        * Resolve the table name for the given class name
+        *
+        * @param string $className
+        * @return string The table name
+        */
+       protected function resolveTableName($className) {
+               if (strpos($className, '\\') !== FALSE) {
+                       $classNameParts = explode('\\', $className, 6);
+                       // Skip vendor and product name for core classes
+                       if (strpos($className, 'TYPO3\\CMS\\') === 0) {
+                               $classPartsToSkip = 2;
+                       } else {
+                               $classPartsToSkip = 1;
+                       }
+                       $tableName = 'tx_' . strtolower(implode('_', array_slice($classNameParts, $classPartsToSkip)));
+               } else {
+                       $tableName = strtolower($className);
+               }
+               return $tableName;
+       }
+
        /**
         * Resolves all subclasses for the given set of (sub-)classes.
         * The whole classes configuration is used to determine all subclasses recursively.