I use to import files from another application via JSON into TYPO3. The imported files are saved in a specific storage. The associated records are created in sys_file. So far everything looks good. Now I'd like to add the imported files to a certain table. For that I use the approach of the news extension V8.5.2 according NewsImportService.php. There is a function hydrateNewsRecord() which makes media (file) relation. Therefor I use following code:
$media = $objectManager->get(\Zhaw\ZhawContinuingEducation\Domain\Model\FileReference::class);
$media->setFileUid($file->getUid());
\\ add new file to field
$newCourse->addContactImage1($media);
...
\\ add to table course
$courseRepo->add($newCourse);
...
$persistenceManager->persistAll();
During test I always get the error (due to persistence manager): Table 'typo3_www.tx_zhawcontinuingeducation_domain_model_filereference' doesn't exist
I also included under domain/model FileReference.php and added in setup.typoscript:
objects {
TYPO3\CMS\Extbase\Domain\Model\FileReference.className = Zhaw\ZhawContinuingEducation\Domain\Model\FileReference
}
persistence {
storagePid =
classes {
Zhaw\ZhawContinuingEducation\Domain\Model\FileReference {
mapping {
tableName = sys_file_reference
columns {
uid_local.mapOnProperty = originalFileIdentifier
}
}
}
}
}
The table tx_zhawcontinuingeducation_domain_model_filereference is not necessary, because it already exists in the core. Does anybody know, what I'm missing?
Mapping model classes like that in TypoScript isn't possible anymore since TYPO3 10.0. You'll need to add a EXT:extension/Configuration/Extbase/Persistence/Classes.php
file to your extension with the following content:
<?php
declare(strict_types = 1);
return [
\Zhaw\ZhawContinuingEducation\Domain\Model\FileReference::class => [
'tableName' => 'sys_file_reference',
'properties' => [
'originalFileIdentifier' => [
'fieldName' => 'uid_local'
],
],
],
];
More about this you can find here: https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/10.0/Breaking-87623-ReplaceConfigpersistenceclassesTyposcriptConfiguration.html