diff --git a/Classes/Command/FourallportalCommandController.php b/Classes/Command/FourallportalCommandController.php index 6e53a59..5b952ed 100644 --- a/Classes/Command/FourallportalCommandController.php +++ b/Classes/Command/FourallportalCommandController.php @@ -413,11 +413,12 @@ public function updateModelsCommand() * * @param string $entityClassName * @param bool $strict If TRUE, generates strict PHP code + * @param bool $readOnly If TRUE, generates TCA fields as read-only */ - public function generateCommand($entityClassName = null, $strict = false) + public function generateCommand($entityClassName = null, $strict = false, $readOnly = false) { $this->generateSqlSchemaCommand(); - $this->generateTableConfigurationCommand($entityClassName); + $this->generateTableConfigurationCommand($entityClassName, $readOnly); $this->generateAbstractModelClassCommand($entityClassName, $strict); } @@ -439,11 +440,12 @@ public function generateCommand($entityClassName = null, $strict = false) * Configuration/TCA/Overrides/$tableName.php file instead. * * @param string $entityClassName + * @param bool $readOnly If TRUE, generates TCA fields as read-only */ - public function generateTableConfigurationCommand($entityClassName = null) + public function generateTableConfigurationCommand($entityClassName = null, $readOnly = false) { foreach ($this->getEntityClassNames($entityClassName) as $entityClassName) { - $tca = DynamicModelGenerator::generateAutomaticTableConfigurationForModelClassName($entityClassName); + $tca = DynamicModelGenerator::generateAutomaticTableConfigurationForModelClassName($entityClassName, $readOnly); $table = $this->objectManager->get(DataMapper::class)->getDataMap($entityClassName)->getTableName(); $extensionKey = $this->getExtensionKeyFromEntityClasName($entityClassName); @@ -649,7 +651,6 @@ public function syncCommand($sync = false, $module = null, $exclude = null) /** @var Module $configuredModule */ if ($sync && $module->getLastEventId() > 0) { $module->setLastEventId(0); - } else { $moduleEvents = $this->eventRepository->findByModule($module->getUid()); foreach ($moduleEvents as $moduleEvent) { $this->eventRepository->remove($moduleEvent); diff --git a/Classes/DynamicModel/DynamicModelGenerator.php b/Classes/DynamicModel/DynamicModelGenerator.php index 33e4966..8fe344d 100644 --- a/Classes/DynamicModel/DynamicModelGenerator.php +++ b/Classes/DynamicModel/DynamicModelGenerator.php @@ -185,16 +185,17 @@ protected static function findIconFile($extensionKey, $tableName) /** * @param string $modelClassName + * @param bool $readOnly If TRUE, generates TCA fields as read-only * @return array */ - public static function generateAutomaticTableConfigurationForModelClassName($modelClassName) + public static function generateAutomaticTableConfigurationForModelClassName($modelClassName, $readOnly = false) { $modelClassNameParts = explode('\\', substr($modelClassName, 0, strpos($modelClassName, '\\Domain\\Model\\'))); $extensionName = array_pop($modelClassNameParts); $extensionKey = GeneralUtility::camelCaseToLowerCaseUnderscored($extensionName); $tableName = GeneralUtility::makeInstance(ObjectManager::class)->get(DataMapper::class)->getDataMap($modelClassName)->getTableName(); $tca = include ExtensionManagementUtility::extPath('fourallportal', 'Configuration/TCA/BoilerPlate/AutomaticTableConfiguration.php'); - $additionalColumns = \Crossmedia\Fourallportal\DynamicModel\DynamicModelGenerator::generateTableConfigurationForModuleIdentifiedByModelClassName($modelClassName); + $additionalColumns = \Crossmedia\Fourallportal\DynamicModel\DynamicModelGenerator::generateTableConfigurationForModuleIdentifiedByModelClassName($modelClassName, $readOnly); $additionalColumnNames = implode(',', array_keys($additionalColumns)); $detectedIconFile = static::findIconFile($extensionKey, $tableName); $tca['columns'] = array_replace($additionalColumns, $tca['columns']); @@ -214,9 +215,10 @@ public static function generateAutomaticTableConfigurationForModelClassName($mod /** * @param string $modelClassName + * @param bool $readOnly If TRUE, generates TCA fields as read-only * @return array */ - public static function generateTableConfigurationForModuleIdentifiedByModelClassName($modelClassName) + public static function generateTableConfigurationForModuleIdentifiedByModelClassName($modelClassName, $readOnly = false) { $cacheManager = GeneralUtility::makeInstance(CacheManager::class); $cacheManager->setCacheConfigurations($GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']); @@ -226,6 +228,9 @@ public static function generateTableConfigurationForModuleIdentifiedByModelClass if ($module->getMapper()->getEntityClassName() === $modelClassName) { $propertyConfigurations = (new static())->getPropertyConfigurationFromConnector($module); foreach ($propertyConfigurations as $propertyConfiguration) { + if ($readOnly) { + $propertyConfiguration['config']['readOnly'] = true; + } $columns[$propertyConfiguration['column']] = [ 'label' => 'Automatic model field: ' . $propertyConfiguration['column'], 'exclude' => true, @@ -559,7 +564,7 @@ protected function guessLocalTypesFromRemoteField(array $fieldConfiguration, $cu case 'CEInteger': case 'MAMNumber': case 'XMPNumber': - $dataType = 'integer'; + $dataType = 'int'; $sqlType = 'int(11) default 0 NOT NULL'; $tca = [ 'type' => 'input', @@ -902,7 +907,7 @@ protected function generateVirtualArrayGetter($propertyName, $strict = false) */ public function get%sArray()%s { - return (array) json_decode(\$this->%s ?? '', true); + return (array)json_decode(\$this->%s ?? '', true); } @@ -957,11 +962,16 @@ public function set%s(%s) $returnType = 'string'; } + $lazy = false; + if (class_exists($returnType) || strpos($returnType, 'ObjectStorage') !== false) { + $lazy = DynamicModelRegister::isLazyProperty($className, $propertyName); + } + $upperCasePropertyName = ucfirst($propertyName); $functionsAndProperties .= sprintf( $propertyTemplate, $returnType, - DynamicModelRegister::isLazyProperty($className, $propertyName) ? PHP_EOL . ' * @lazy' : '', + $lazy ? PHP_EOL . ' * @lazy' : '', $propertyName, ($property['default'] ?? null) === null ? 'null' : var_export($property['default'], true), $upperCasePropertyName, @@ -1064,8 +1074,12 @@ public function set%s(%s%s) } $defaultValueExpression = ($property['default'] ?? null) === null ? 'null' : var_export($property['default'], true); - $isLazyProperty = DynamicModelRegister::isLazyProperty($className, $propertyName); - $isLazySingleObjectRelation = $isLazyProperty && is_a($property['type'], AbstractDomainObject::class, true); + + $isLazyProperty = false; + if (class_exists(trim($returnType, '?\\'))) { + $isLazyProperty = DynamicModelRegister::isLazyProperty($className, $propertyName); + } + $isLazySingleObjectRelation = $isLazyProperty && is_a(trim($property['type'], '?'), AbstractDomainObject::class, true); $upperCasePropertyName = ucfirst($propertyName); $functionsAndProperties .= sprintf( diff --git a/Classes/Mapping/AbstractMapping.php b/Classes/Mapping/AbstractMapping.php index ce880c7..390e410 100644 --- a/Classes/Mapping/AbstractMapping.php +++ b/Classes/Mapping/AbstractMapping.php @@ -9,6 +9,7 @@ use Crossmedia\Products\Domain\Repository\ProductRepository; use TYPO3\CMS\Core\Utility\GeneralUtility; use TYPO3\CMS\Extbase\DomainObject\AbstractEntity; +use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface; use TYPO3\CMS\Extbase\Object\ObjectManager; use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper; use TYPO3\CMS\Extbase\Persistence\Generic\PersistenceManager; @@ -49,7 +50,7 @@ public function import(array $data, Event $event) return; } - $repository->remove($object); + $this->removeObjectFromRepository($object); unset($object); break; case 'update': @@ -65,6 +66,11 @@ public function import(array $data, Event $event) } } + protected function removeObjectFromRepository(DomainObjectInterface $object) + { + $this->getObjectRepository()->remove($object); + } + /** * @param array $data * @param AbstractEntity $object @@ -348,24 +354,28 @@ protected function addMissingNullProperties($properties, Module $module) if (isset($field['defaultValue'])) { switch ($field['type']) { case 'CEVarchar': - $value = trim($field['defaultValue'], '\''); + $value = ''; break; case 'MAMDate': case 'CEDate': + $value = null; break; case 'MAMBoolean'; case 'CEBoolean': - $value = strtolower($field['defaultValue']) == 'true'; + $value = false; break; case 'CEDouble': + $value = 0.0; break; case 'CETimestamp': case 'CEInteger': case 'MAMNumber': case 'XMPNumber': + $value = 0; break; case 'MAMList': case 'CEVarcharList': + $value = []; break; case 'FIELD_LINK': case 'CEExternalIdList': @@ -373,15 +383,16 @@ protected function addMissingNullProperties($properties, Module $module) case 'MANY_TO_MANY': case 'ONE_TO_MANY': case 'MANY_TO_ONE': + $value = null; break; case 'CEId': case 'CEExternalId': case 'ONE_TO_ONE': + $value = null; break; default: break; } -// dump($field['name'] . ':' . $field['type'], $value); } $properties[$field['name']] = $value; } diff --git a/README.md b/README.md index 2658349..5f91cdd 100644 --- a/README.md +++ b/README.md @@ -684,6 +684,13 @@ The second way is to flush the TYPO3 system caches. This also triggers a model r and is intended as a way to let developers quickly trigger the rebuild on demand. Note that the rebuild only happens if you flush the "all" or "system" caches. +##### Dimension Handling + +This extension supports the import of Fields that contain differents dimension values. +To map Dimension Values to specific TYPO3 Languages you need to configure Mappings in the +Backend of TYPO3 in the Server Configuration. For each Language you want to map a Dimension +to you need to create an Inline DimensionMapping Record that specifies the Language this +Dimension should be mapped to and the Name/Value pairs to identify a specific Dimension. Adding a scheduled task -----------------------