Project

General

Profile

Actions

Bug #90214

closed

TCA maxitems is ignored

Added by Florian Rival almost 5 years ago. Updated 6 months ago.

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

0%

Estimated time:
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


Files

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

Updated by Florian Rival almost 5 years ago

  • Category set to Extbase
Actions #2

Updated by Alexander Schnitzler over 4 years ago

  • Assignee set to Alexander Schnitzler
Actions #3

Updated by Alexander Schnitzler over 4 years 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.

Actions #4

Updated by Florian Rival over 4 years 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

Actions #5

Updated by Alexander Schnitzler over 4 years 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.

Actions #6

Updated by Christian Kuhn almost 3 years ago

  • Status changed from Needs Feedback to New
Actions #7

Updated by Thomas Löffler almost 2 years ago

It seems that the upload_example of Helmut (https://github.com/helhum/upload_example/) is used here.
As the example is only coded to add files and not to replace files there is a need of adapting the example's code.

Imho it's not a bug in the Core. It's a missing feature in the example.

Actions #8

Updated by Georg Ringer 6 months ago

  • Status changed from New to Rejected

extbase doesn't care about this restriction, same like minitems. and you need to take care about that yourself. therefore I am closing this issue

regarding the upload_example: with 13 it is planned to have a solution within the core, see Feature #103511: Introduce Extbase file upload handling

Actions #9

Updated by Georg Ringer 6 months ago

  • Status changed from Rejected to Closed
Actions

Also available in: Atom PDF