TYPO3 8.7:CLI 外部导入错误解决方案

碧海醫心
发布: 2025-08-19 16:44:00
原创
334人浏览过

typo3 8.7:cli 外部导入错误解决方案

在 TYPO3 8.7 中,当尝试通过命令行界面 (CLI) 使用 external_import 导入数据时,可能会遇到诸如权限不足或缓存写入失败等错误。这些错误通常与 CLI 环境下缺少必要的后端认证初始化有关。以下将详细介绍如何解决这些问题。

问题描述

在使用自定义 Extbase 扩展,并通过 CLI 脚本执行外部导入时,可能会遇到以下错误:

  • "The requested configuration was not found (table: tx_something_domain_model_formation, index: 0). Message: The temporary cache file "thisisthepathtothewebsites/typo3temp/var/Cache/Data/l10n/61794fcc21579208003962.temp" could not be written. [1334756737]"
  • "User doesn't have enough rights for synchronizing table tx_something_domain_model_formation."

这些错误表明在 CLI 环境中,TYPO3 缺少必要的认证信息,导致无法访问数据库或写入缓存文件。

解决方案

解决此问题的关键是在 CLI 脚本中显式地初始化后端认证。这可以通过在执行导入操作之前添加以下代码来实现:

挖错网
挖错网

一款支持文本、图片、视频纠错和AIGC检测的内容审核校对平台。

挖错网 28
查看详情 挖错网
use TYPO3\CMS\Core\Core\Bootstrap;

Bootstrap::getInstance()->initializeBackendAuthentication();
登录后复制

代码示例

以下是修改后的 Command 类示例,展示了如何集成上述解决方案:

<?php

namespace Vendor\Something\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class FormationImportCommand extends Command
{
    protected function configure()
    {
        $this->setDescription('Synchroniser les formations externe dans typo3.');
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input, $output);

        // 初始化后端认证
        Bootstrap::getInstance()->initializeBackendAuthentication();

        $arrayFormations = $this->getFormations();
        $message = $this->importFormation($arrayFormations);
        print_r($message);
        $io->writeln('Test');
        return 0;
    }

    private function getFormations()
    {
        $jsonPartOne = json_decode(file_get_contents(PATH_typo3conf . "ext/something/Ressources/Private/Assets/Json/apiPage1.json"), true);
        $jsonPartTwo = json_decode(file_get_contents(PATH_typo3conf . "ext/something/Ressources/Private/Assets/Json/apiPage2.json"), true);

        $jsonFormations = array_merge($jsonPartOne['elements'], $jsonPartTwo['elements']);

        return $jsonFormations;
    }

    private function importFormation(array $formations)
    {
        if (count($formations) === 0) {
            //TODO Erreur
            return;
        }

        $dataFormations = [];
        $dataGroupe = [];
        $dataformateurs = [];
        $dataFormationsGroupes = [];

        foreach ($formations as $formation) {
            $dataFormations[] = [
                'id_formation' => $formation['idFormation'],
                'nom' => $formation['nom'],
                'description' => $formation['description']['texteHtml'],
                'duree' => $formation['dureeFormation']['dureeEnHeures'],
            ];
        }

        $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
        $importer = $objectManager->get(\Cobweb\ExternalImport\Importer::class);
        $importer->getExtensionConfiguration();
        $importer->setContext('cli');
        $importer->setDebug(true);
        $importer->setVerbose(true);
        return $importer->import('tx_something_domain_model_formation', 0, $dataFormations);
    }
}
登录后复制

注意事项

  • 确保在 use 语句中引入 TYPO3\CMS\Core\Core\Bootstrap;。
  • Bootstrap::getInstance()->initializeBackendAuthentication(); 必须在任何需要后端认证的操作之前调用,例如访问数据库或写入缓存。
  • 此解决方案适用于 TYPO3 8.7。在其他版本中,可能需要不同的方法来初始化后端认证。

总结

通过在 CLI 脚本中添加 Bootstrap::getInstance()->initializeBackendAuthentication();,可以解决 TYPO3 8.7 中使用 external_import 时遇到的权限和缓存写入错误。这确保了外部导入功能在 CLI 环境下能够正常运行,从而实现自动化数据导入任务。在实际应用中,请根据您的具体需求调整代码,并确保所有依赖项都已正确安装和配置。

以上就是TYPO3 8.7:CLI 外部导入错误解决方案的详细内容,更多请关注php中文网其它相关文章!

最佳 Windows 性能的顶级免费优化软件
最佳 Windows 性能的顶级免费优化软件

每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号