Bug #90214

TCA maxitems is ignored

Added by Florian Rival 9 months ago. Updated 6 months ago.

Status:
Needs Feedback
Priority:
Should have
Category:
Extbase
Target version:
-
Start date:
2020-01-27
Due date:
% Done:

0%

TYPO3 Version:
9
PHP Version:
7.2
Tags:
Complexity:
Is Regression:
Yes
Sprint Focus:

Description

Hi,

When setting TCA maxitems to 1 for INLINE relations, and update the record from FE form, maxitems is ignored, many relations are created in sys_file_reference where there should be only one.

New relation is inserted but old relation is not deleted.

Sample TCA :

    'cv' => [
        'exclude' => false,
        'label' => 'cv',
        'config' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getFileFieldTCAConfig(
            'cv',
            [
                'minitems' => 0,
                'maxitems' => 1,
                'foreign_match_fields' => [
                    'fieldname' => 'cv',
                    'tablenames' => 'fe_users',
                    'table_local' => 'sys_file',
                ]
            ],
            'pdf'
        ),
    ]

And update with :

$this->userRepository->update($user);

The bug appeared in Typo3 9.5.13 but wasn't present in previous V9 versions (don't know exactly which one).

Florian

Bug maxitems.jpg View (51.3 KB) Florian Rival, 2020-01-27 12:59

History

#1 Updated by Florian Rival 9 months ago

  • Category set to Extbase

#2 Updated by Alexander Schnitzler 6 months ago

  • Assignee set to Alexander Schnitzler

#3 Updated by Alexander Schnitzler 6 months ago

  • Status changed from New to Needs Feedback

I am not sure about this ticket. Can you explain what exactly worked and stopped working suddenly?
With a more detailed description I could search for code that changed.

Besides that: maxitems is not evaluted by Extbase to validate the amount of records being stored.
maxitems is used to determine the exact type of relation between tables, but nothing more.

#4 Updated by Florian Rival 6 months ago

Hi Alexander,

The use case is :

  • I have a record with a file attached (a user with a CV for example, look sample TCA in bug description)
  • In FE, I want to edit informations for this record with actions : editAction() and updateAction()
function editAction() {
    $uid = GeneralUtility::makeInstance(Context::class)->getPropertyFromAspect('frontend.user', 'id', 0);
    $user = $this->userRepository->findByIdentifier($uid);
    $this->view->assign('user', $user);
}

Then in Edit.html the form look like this :

<f:form action="update" name="user" object="{user}" >
    <f:form.upload property="cv" additionalAttributes="{accept :'application/pdf'}" />
</f:form>

And in update action :

public function initializeUpdateAction(): void
{
    $fileUploadConfiguration = [
        UploadedFileReferenceConverter::CONFIGURATION_FILE_VALIDATORS => ['application/pdf'],
        UploadedFileReferenceConverter::CONFIGURATION_UPLOAD_FOLDER => $this->settings['folders']['cvFolder'],
    ];

    /** @var PropertyMappingConfiguration $newUserConfiguration */
    $newUserConfiguration = $this->arguments['user']->getPropertyMappingConfiguration();

    $newUserConfiguration->forProperty('cv')->setTypeConverterOptions(UploadedFileReferenceConverter::class, $fileUploadConfiguration);
}

public function updateAction(User $user): void
{
    $this->userRepository->update($user);
}
  • so, in FE form, I upload a new file (CV) and this new file should replace the old one
  • but the result is not as expected :
    - new file is attached to record : so far so good
    - old file is not removed for this record
  • the you have two files attached to that record instead of one - have a look at picture in description

Hope it help,
Florian

#5 Updated by Alexander Schnitzler 6 months ago

Hi Florian,

with that code attached I understand your use case much better.

I am still not quite sure where we would find the error exactly. I would need to debug the data mapper and the property mapper to see what exactly happens here and why the current object storage does not completely override the old one. That does not even have anything to do with maxitems here. It seems that property relations are merged. I currently don't know what the desired behaviour would be (for all), what actually makes sense and why things are like they are.

Also available in: Atom PDF