fritzmg / contao-store-uuid

Mini extension which integrates a storeFormData and a updatePersonalData hook to automatically convert uploaded file paths to UUIDs.
GNU General Public License v2.0
0 stars 1 forks source link

Error Message: Data too long #7

Open eBlick opened 2 years ago

eBlick commented 2 years ago

It does not seem to work properly with the chosen table.

"file" attribute is a binary(16) field but it seems that still the path is considered and not the uuid.

[2021-12-06 09:46:55] request.CRITICAL: Uncaught PHP Exception Doctrine\DBAL\Exception\DriverException: "An exception occurred while executing 'INSERT INTO tl_test (tstamp,file) VALUES (1638780415, 'files/files/Bildschirmfoto 2021-12-06 um 08.50.25.png')': SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'file' at row 1" at /kunden/webseiten/testumgebungx3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php line 128 {"exception":"[object] (Doctrine\\DBAL\\Exception\\DriverException(code: 0): An exception occurred while executing 'INSERT INTO tl_test (tstamp,file) VALUES (1638780415, 'files/files/Bildschirmfoto 2021-12-06 um 08.50.25.png')':\n\nSQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'file' at row 1 at /kunden/webseiten/testumgebungx3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php:128, Doctrine\\DBAL\\Driver\\PDO\\Exception(code: 22001): SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'file' at row 1 at /kunden/webseiten/testumgebungx3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDO/Exception.php:18, PDOException(code: 22001): SQLSTATE[22001]: String data, right truncated: 1406 Data too long for column 'file' at row 1 at /kunden/webseiten/testumgebungx3/vendor/doctrine/dbal/lib/Doctrine/DBAL/Driver/PDOConnection.php:141)"} []

fritzmg commented 2 years ago

Please post the DCA configuration of your tl_test table.

eBlick commented 2 years ago

It's a dynamic DCA from CustomCatalog. Obviously it won't work here (like MetaModels).

fritzmg commented 2 years ago

This extension only works for tables generated by a regular DCA. Dynamic DCAs from Custom Catalog or Meta Models likely won't work (see also #4).

In your case you should just implement a storeFormData hook yourself and transform the values to your needs (i.e. convert the file path to a UUID).

fritzmg commented 2 years ago

Should be as simple as this in your case:

// src/EventListener/StoreFormDataListener.php
namespace App\EventListener;

use Contao\CoreBundle\ServiceAnnotation\Hook;
use Contao\FilesModel;
use Contao\Form;

/**
 * @Hook("storeFormData")
 */
class StoreFormDataListener
{
    public function __invoke(array $data, Form $form): array
    {
        if ('tl_test' !== $form->targetTable) {
            return $data;
        }

        $file = FilesModel::findByPath($data['file']);

        if (null === $file) {
            return $data;
        }

        $data['file'] = $file->uuid;

        return $data;
    }
}
eBlick commented 2 years ago

Thanks alot. Will try!