Commit 7b9d6c82 authored by Morton Jonuschat's avatar Morton Jonuschat Committed by Oliver Hader
Browse files

[BUGFIX] DataHandler: Assign reference default values

In MySQL stric mode scenarios, relation types not using MM tables
or the foreign_field definition (IRRE) might end up in no
references at all, which is only the trigger for the actual
problem. These references result in a blank string ("") that
is casted in non-strict modes to the accordant field type
defined by the DMBS schema.

In strict mode this has to be handled more specific. Since the
system cannot determine the real meaning automatically, values
for reference that are produced in the mentioned scenario are
now casted to zero (0) or to the default value defined in the
accordant TCA configuration of the field.

Resolves: #69004
Releases: master
Change-Id: I6608f1fe0f63a99caa1208b1d3d76354b6f659cf
Reviewed-on: http://review.typo3.org/42550


Reviewed-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
Tested-by: Oliver Hader's avatarOliver Hader <oliver.hader@typo3.org>
parent c0a37749
......@@ -2079,7 +2079,7 @@ class DataHandler {
}
if (!$unsetResult) {
$newVal = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
$res['value'] = implode(',', $newVal);
$res['value'] = $this->castReferenceValue(implode(',', $newVal), $tcaFieldConf);
} else {
unset($res['value']);
}
......@@ -3151,11 +3151,12 @@ class DataHandler {
$valueArray = $dbAnalysis->getValueArray();
// Checking that the number of items is correct:
$valueArray = $this->checkValue_checkMax($tcaFieldConf, $valueArray);
$valueData = $this->castReferenceValue(implode(',', $valueArray), $tcaFieldConf);
// If a valid translation of the 'keep' mode is active, update relations in the original(!) record:
if ($keepTranslation) {
$this->updateDB($table, $transOrigPointer, array($field => implode(',', $valueArray)));
$this->updateDB($table, $transOrigPointer, array($field => $valueData));
} else {
$newValue = implode(',', $valueArray);
$newValue = $valueData;
}
}
}
......@@ -5708,6 +5709,9 @@ class DataHandler {
// If array is returned, check for maxitems condition, if string is returned this was already done:
if (is_array($newValue)) {
$newValue = implode(',', $this->checkValue_checkMax($tcaFieldConf, $newValue));
// The reference casting is only required if
// checkValue_group_select_processDBdata() returns an array
$newValue = $this->castReferenceValue($newValue, $tcaFieldConf);
}
// Update in database (list of children (csv) or number of relations (foreign_field)):
if (!empty($field)) {
......@@ -7215,6 +7219,34 @@ class DataHandler {
return $listArr;
}
/**
* Casts a reference value. In case MM relations or foreign_field
* references are used. All other configurations, as well as
* foreign_table(!) could be stored as comma-separated-values
* as well. Since the system is not able to determine the default
* value automatically then, the TCA default value is used if
* it has been defined.
*
* @param int|string $value The value to be casted (e.g. '', '0', '1,2,3')
* @param array $configuration The TCA configuration of the accordant field
* @return int|string
*/
protected function castReferenceValue($value, array $configuration) {
if ((string)$value !== '') {
return $value;
}
if (!empty($configuration['MM']) || !empty($configuration['foreign_field'])) {
return 0;
}
if (array_key_exists('default', $configuration)) {
return $configuration['default'];
}
return $value;
}
/**
* Returns TRUE if the TCA/columns field type is a DB reference field
*
......
......@@ -61,7 +61,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l10n_parent' => array(
......
......@@ -51,7 +51,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l10n_parent' => array(
......
......@@ -50,7 +50,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l10n_parent' => array(
......
......@@ -38,7 +38,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l10n_parent' => array(
......
......@@ -59,7 +59,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xlf:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xlf:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l10n_parent' => array(
......
......@@ -34,7 +34,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -35,7 +35,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -35,7 +35,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -35,7 +35,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -33,7 +33,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -34,7 +34,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -33,7 +33,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
......@@ -32,7 +32,8 @@ return array(
'items' => array(
array('LLL:EXT:lang/locallang_general.xml:LGL.allLanguages', -1),
array('LLL:EXT:lang/locallang_general.xml:LGL.default_value', 0)
)
),
'default' => 0
)
),
'l18n_parent' => array(
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment