【问题标题】:File Import in an extension扩展中的文件导入
【发布时间】:2021-06-13 15:24:40
【问题描述】:

我使用通过 JSON 从另一个应用程序将文件导入 TYPO3。导入的文件保存在特定的存储中。相关记录在 sys_file 中创建。到目前为止,一切看起来都不错。 现在我想将导入的文件添加到某个表中。为此,我根据 NewsImportService.php 使用新闻扩展 V8.5.2 的方法。有一个函数 hydraNewsRecord() 可以建立媒体(文件)关系。因此我使用以下代码:

$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();

在测试期间,我总是收到错误消息(由于持久性管理器):Table 'typo3_www.tx_zhawcontinuingeducation_domain_model_filereference' 不存在

我还包含在域/模型 FileReference.php 下并添加到 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
                }
            }
        }
    }
}

表 tx_zhawcontinuingeducation_domain_model_filereference 不是必需的,因为它已经存在于核心中。有谁知道,我错过了什么?

【问题讨论】:

  • 您使用的是哪个 TYPO3 版本?
  • 哦,是的,我忘了提。我们正在使用 TYPO3 V10.4.12

标签: typo3 typo3-10.x file-import


【解决方案1】:

自 TYPO3 10.0 以来,不再可能在 TypoScript 中映射模型类。您需要将 EXT:extension/Configuration/Extbase/Persistence/Classes.php 文件添加到您的扩展程序中,其中包含以下内容:

<?php
declare(strict_types = 1);

return [
    \Zhaw\ZhawContinuingEducation\Domain\Model\FileReference::class => [
        'tableName' => 'sys_file_reference',
        'properties' => [
            'originalFileIdentifier' => [
                'fieldName' => 'uid_local'
            ],
        ],
    ],
];

您可以在这里找到更多相关信息:https://docs.typo3.org/c/typo3/cms-core/master/en-us/Changelog/10.0/Breaking-87623-ReplaceConfigpersistenceclassesTyposcriptConfiguration.html

【讨论】:

  • 非常感谢,你让我很开心。这使我无法解决我的问题。在我更改了我的“旧”代码后,它就像一个魅力。
猜你喜欢
  • 1970-01-01
  • 2018-05-10
  • 2020-04-03
  • 1970-01-01
  • 2015-01-09
  • 2014-11-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多