Project

General

Profile

Actions

Task #90847

closed

DataMapper for array type

Added by Bill Dagou over 4 years ago. Updated about 3 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2020-03-27
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Sprint Focus:

Description

Sorry, I don't know how to choose the tracker, actually it's not a bug, but should be a suggestion.

I was working on an FE ext, and it involves in displaying the banners on the page with some access controls, like Anonymous, User Group 1, User Group 2, and etc. So, I was using array to store the group IDs, 0 for Anonymous. I can save the access array to the DB like 0,1,2, but can not get it from the DB.

After digging the core files, I found the array is mapped to string with implode() in the DataMapper::getPlainValue()

...
if (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
    $plainValueArray = [];
    foreach ($input as $inputElement) {
        $plainValueArray[] = $this->getPlainValue($inputElement, $columnMap);
    }
    $parameter = implode(',', $plainValueArray);
}
...

while in DataMapper::thawProperties(), it is

...
case 'array':
    // $propertyValue = $this->mapArray($row[$columnName]); // Not supported, yet!
    break;
...

and it's not supported since v7, maybe even earlier.

So, my suggestion is, adding more detailed if conditions in getPlainValue(), so the real array could be mapped correctly, you known like the index, the two dimensional arrays, and more.

...
if ($input instanceof \SplObjectStorage || $input instanceof Persistence\ObjectStorage) {
    $plainValueArray = [];
    foreach ($input as $inputElement) {
        $plainValueArray[] = $this->getPlainValue($inputElement, $columnMap);
    }
    $parameter = implode(',', $plainValueArray);
} elseif (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
    $parameter = serialize($input);
}
...

Thus, the array could be retrieved with unserialize() in thawProperties().

Maybe the suggestion is not as good, but I think it worthes a try.

Thank you!


Related issues 1 (0 open1 closed)

Related to TYPO3 Core - Bug #88389: ArrayConverter might not convert strings to arrayClosed2019-05-18

Actions
Actions #1

Updated by Bill Dagou over 4 years ago

  • Description updated (diff)

Sorry for the typo, should be $input instanceof Persistence\ObjectStorage instead.

Actions #2

Updated by Susanne Moog over 4 years ago

  • Related to Bug #88389: ArrayConverter might not convert strings to array added
Actions #3

Updated by Susanne Moog over 4 years ago

  • Tracker changed from Bug to Task
  • Status changed from New to Accepted

After #88389 this can be configured.

Actions #4

Updated by Benni Mack about 3 years ago

  • Status changed from Accepted to Closed

Solved with the other issue.

Actions

Also available in: Atom PDF