Project

General

Profile

Actions

Bug #94607

open

TcaMigration for special-value type-field in sys_file_reference triggers exception

Added by Stefan Neufeind over 3 years ago. Updated about 1 year ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
-
Target version:
-
Start date:
2021-07-21
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
10
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

For sys_file_reference the type-field does not point to a configured field directly. So TcaMigration complains with an exception.

I don't exactly know why in my special case the TCA-migration triggered checks. But imho it might simply skip checking such "special values"?

Uncaught TYPO3 Exception #1482394401: Missing "type" in TCA of field "['sys_file_reference']['uid_local:type']['config']".
thrown in file /var/www/typo3_src-10.4.17/typo3/sysext/core/Classes/Migrations/TcaMigration.php
in line 87

Definition in: typo3/sysext/core/Configuration/TCA/sys_file_reference.php

Actions #1

Updated by Stefan Neufeind over 3 years ago

Can we skip those special values?

In validateTcaType() possibly add check for ':' indicating this is no fieldName directly but points to a "sub-field".

foreach ($tableDefinition['columns'] as $fieldName => $fieldConfig) {
if ((strpos($fieldName, ':') === false) && isset($fieldConfig['config']) && is_array($fieldConfig['config']) && empty($fieldConfig['config']['type'])) {
Actions #2

Updated by Kevin Chileong Lee over 1 year ago

A Workaround that worked for me is to XClass the \TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper and override the method: getTargetType. What needs to be done is to check if the array key is present in the $row before using it:

/**
     * Returns the target type for the given row.
     *
     * @param string $className The name of the class
     * @param array $row A single array with field_name => value pairs
     * @return string The target type (a class name)
     */
    public function getTargetType($className, array $row)
    {
        $dataMap = $this->getDataMap($className);

        $targetType = $className;
        if ($dataMap->getRecordTypeColumnName() !== null) {
            foreach ($dataMap->getSubclasses() as $subclassName) {
                $recordSubtype = $this->getDataMap($subclassName)->getRecordType();

                // Check if column is present in the row
                if (array_key_exists($dataMap->getRecordTypeColumnName(), $row) && (string)$row[$dataMap->getRecordTypeColumnName()] === (string)$recordSubtype) {
                    $targetType = $subclassName;
                    break;
                }
            }
        }
        return $targetType;
    }

The method is based on TYPO3 V11.5.27

Actions #3

Updated by Mathias Brodala about 1 year ago

Seems like Extbase never did support the <relation-field>:<related-table-field> notation.

In the backend the BackendUtility::getTCAtypeValue() method can be used to resolve this. Thus a possible fix in DataMapper::getTargetType() could be using this:

+use TYPO3\CMS\Backend\Utility\BackendUtility;
-                if ((string)$row[$dataMap->getRecordTypeColumnName()] === (string)$recordSubtype) {
+                if (BackendUtility::getTCAtypeValue($this->convertClassNameToTableName($className), $row) === (string)$recordSubtype) {
Actions

Also available in: Atom PDF