Skip to content

Commit

Permalink
Merge pull request #13 from mia3/missing-null-parameter
Browse files Browse the repository at this point in the history
Empty Properties are not synced
  • Loading branch information
Marc Neuhaus authored Feb 2, 2018
2 parents 4ed630c + b6b96a4 commit ff3aee5
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Classes/Command/FourallportalCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -820,7 +820,7 @@ public function processEvent($event, $updateEventId = true)
$event->setMessage($error->getMessage() . ' (code: ' . $error->getCode() . ')');
} catch(\Exception $exception) {
$event->setStatus('failed');
$event->setMessage($exception->getMessage() . ' (code: ' . $exception->getCode() . ')');
$event->setMessage($exception->getMessage() . ' (code: ' . $exception->getCode() . ')' . $exception->getFile() . ':' . $exception->getLine());
if ($updateEventId) {
$event->getModule()->setLastEventId(max($event->getEventId(), $event->getModule()->getLastEventId()));
}
Expand Down
9 changes: 9 additions & 0 deletions Classes/DynamicModel/DynamicModelGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,15 @@ public function set%s(%s%s)

$functionsAndProperties = '';
$objectStorageInitializations = '';
$propertyConfiguration['remoteId'] = [
"column"=> "remote_id",
"type"=> "string",
"schema" => "varchar(255) default ''",
"config" => [
"type"=> "input",
"size" => 255
]
];
foreach ($propertyConfiguration as $propertyName => $property) {

$variableType = $property['type'];
Expand Down
67 changes: 66 additions & 1 deletion Classes/Mapping/AbstractMapping.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ public function import(array $data, Event $event)
{
$repository = $this->getObjectRepository();
$objectId = $event->getObjectId();
$object = $repository->findOneByRemoteId($objectId);
$query = $repository->createQuery();
$query->getQuerySettings()->setRespectStoragePage(false);
$query->matching($query->equals('remoteId', $objectId));
$object = $query->execute()->current();

switch ($event->getEventType()) {
case 'delete':
Expand Down Expand Up @@ -91,6 +94,7 @@ protected function mapPropertiesFromDataToObject(array $data, $object, Module $m
}
$map = MappingRegister::resolvePropertyMapForMapper(static::class);
$properties = $data['result'][0]['properties'];
$properties = $this->addMissingNullProperties($properties, $module);
foreach ($properties as $importedName => $propertyValue) {
if (($map[$importedName] ?? null) === false) {
continue;
Expand Down Expand Up @@ -333,4 +337,65 @@ public function check(ApiClient $client, Module $module, array $status)
$status['description'] .= implode(chr(10), $messages);
return $status;
}

/**
* @param $properties
* @param Module $module
* @return mixed
*/
protected function addMissingNullProperties($properties, Module $module)
{
$moduleConfiguration = $module->getModuleConfiguration();
foreach ($moduleConfiguration['field_conf'] as $field) {
if (!isset($properties[$field['name']])) {
$value = '';
if (isset($field['defaultValue'])) {
switch ($field['type']) {
case 'CEVarchar':
$value = '';
break;
case 'MAMDate':
case 'CEDate':
$value = null;
break;
case 'MAMBoolean';
case 'CEBoolean':
$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;
}
}
$properties[$field['name']] = $value;
}
}

return $properties;
}
}
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 ff3aee5

Please sign in to comment.