Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into dimension-handling
Browse files Browse the repository at this point in the history
# Conflicts:
#	Classes/Mapping/AbstractMapping.php
  • Loading branch information
Marc Neuhaus committed Feb 2, 2018
2 parents 5b0018e + ff3aee5 commit 15ab8bf
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 17 deletions.
11 changes: 6 additions & 5 deletions Classes/Command/FourallportalCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);

Expand Down Expand Up @@ -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);
Expand Down
30 changes: 22 additions & 8 deletions Classes/DynamicModel/DynamicModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand All @@ -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']);
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down
19 changes: 15 additions & 4 deletions Classes/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,7 +50,7 @@ public function import(array $data, Event $event)

return;
}
$repository->remove($object);
$this->removeObjectFromRepository($object);
unset($object);
break;
case 'update':
Expand All @@ -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
Expand Down Expand Up @@ -348,40 +354,45 @@ 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':
case 'CEIdList':
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;
}
Expand Down
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------------
Expand Down

0 comments on commit 15ab8bf

Please sign in to comment.