Skip to content

Commit

Permalink
[TASK] Prevent superfluous filters in DataMapProcessor
Browse files Browse the repository at this point in the history
For consistency in the filterNumericIds method of DataMapProcessor,
there should only be one result be returned. This patch removes the
second parameter to invert the methods behaviour.

Resolves: #86138
Releases: master
Change-Id: I89bd4949e75818a26dd23c0884ccc0cf41401804
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/58048
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Benni Mack <benni@typo3.org>
Tested-by: Oliver Hader <oliver.hader@typo3.org>
Reviewed-by: Susanne Moog <look@susi.dev>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Reviewed-by: Oliver Hader <oliver.hader@typo3.org>
  • Loading branch information
IchHabRecht authored and ohader committed Nov 19, 2019
1 parent fa7bda8 commit 6319bd5
Showing 1 changed file with 9 additions and 12 deletions.
Expand Up @@ -549,9 +549,9 @@ protected function synchronizeInlineRelations(DataMapItem $item, string $fieldNa
// missing elements that are persisted at the language parent/source, but not translated yet
$missingAncestorIds = array_diff($suggestedAncestorIds, array_keys($dependentIdMap));
// persisted elements that should be copied or localized
$createAncestorIds = $this->filterNumericIds($missingAncestorIds, true);
$createAncestorIds = $this->filterNumericIds($missingAncestorIds);
// non-persisted elements that should be duplicated in data-map directly
$populateAncestorIds = $this->filterNumericIds($missingAncestorIds, false);
$populateAncestorIds = array_diff($missingAncestorIds, $createAncestorIds);
// this desired state map defines the final result of child elements in their parent translation
$desiredIdMap = array_combine($suggestedAncestorIds, $suggestedAncestorIds);
// update existing translations in the desired state map
Expand Down Expand Up @@ -907,8 +907,8 @@ protected function fetchDependencies(string $tableName, array $ids)
}
$fieldNamesMap = array_combine($fieldNames, $fieldNames);

$persistedIds = $this->filterNumericIds($ids, true);
$createdIds = $this->filterNumericIds($ids, false);
$persistedIds = $this->filterNumericIds($ids);
$createdIds = array_diff($ids, $persistedIds);
$dependentElements = $this->fetchDependentElements($tableName, $persistedIds, $fieldNames);

foreach ($createdIds as $createdId) {
Expand Down Expand Up @@ -969,7 +969,7 @@ protected function fetchDependencies(string $tableName, array $ids)
*/
protected function fetchDependentIdMap(string $tableName, array $ids, int $desiredLanguage)
{
$ids = $this->filterNumericIds($ids, true);
$ids = $this->filterNumericIds($ids);
$isTranslatable = BackendUtility::isTableLocalizable($tableName);
$originFieldName = ($GLOBALS['TCA'][$tableName]['ctrl']['origUid'] ?? null);

Expand Down Expand Up @@ -1049,8 +1049,6 @@ protected function fetchDependentIdMap(string $tableName, array $ids, int $desir
*/
protected function fetchDependentElements(string $tableName, array $ids, array $fieldNames)
{
$ids = $this->filterNumericIds($ids, true);

$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable($tableName);
$queryBuilder->getRestrictions()
Expand All @@ -1059,7 +1057,7 @@ protected function fetchDependentElements(string $tableName, array $ids, array $
->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class, $this->backendUser->workspace, false));

$zeroParameter = $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT);
$ids = array_filter($ids, [MathUtility::class, 'canBeInterpretedAsInteger']);
$ids = $this->filterNumericIds($ids);
$idsParameter = $queryBuilder->createNamedParameter($ids, Connection::PARAM_INT_ARRAY);

// fetch by language dependency
Expand Down Expand Up @@ -1140,15 +1138,14 @@ function (DataMapItem $item) use ($type) {
* Return only ids that are integer - so no "NEW..." values
*
* @param string[]|int[] $ids
* @param bool $numeric
* @return int[]|string[]
*/
protected function filterNumericIds(array $ids, bool $numeric = true)
protected function filterNumericIds(array $ids)
{
return array_filter(
$ids,
function ($id) use ($numeric) {
return MathUtility::canBeInterpretedAsInteger($id) === $numeric;
function ($id) {
return MathUtility::canBeInterpretedAsInteger($id);
}
);
}
Expand Down

0 comments on commit 6319bd5

Please sign in to comment.