
在 TYPO3 8.7 中,当尝试通过 CLI 命令行工具,使用 external_import 扩展导入数据时,可能会遇到诸如 "User doesn't have enough rights for synchronizing table..." 或 "The temporary cache file could not be written" 等错误。这些错误通常与权限验证和缓存写入有关。
这些问题通常发生在 CLI 环境下,因为 CLI 环境与后端环境的初始化方式不同。后端环境通常会自动处理权限验证和缓存配置,但在 CLI 环境下,这些都需要手动进行初始化。
解决这些问题的关键在于在 CLI 脚本中手动初始化后端认证。以下是具体的步骤:
引入 Bootstrap 类: 首先,在你的 Command 类中引入 TYPO3\CMS\Core\Core\Bootstrap 类。
use TYPO3\CMS\Core\Core\Bootstrap;
初始化后端认证: 在你的 Command 类的 execute() 方法中,或者在调用 external_import 之前,调用 Bootstrap::getInstance()->initializeBackendAuthentication() 方法。
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;
}这段代码确保了在执行数据导入操作之前,TYPO3 的后端认证已经正确初始化,从而解决了权限不足的问题。
以下是一个完整的示例代码,展示了如何在 Command 类中使用 external_import 扩展,并解决权限和缓存问题:
<?php
namespace Cobweb\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;
use TYPO3\CMS\Extbase\Object\ObjectManager;
class ImportFormationCommand 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(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);
}
}通过在 CLI 脚本中初始化后端认证,可以有效解决 TYPO3 8.7 中使用 external_import 扩展导入数据时遇到的权限不足和缓存写入失败的问题。确保你的 CLI 脚本具有足够的权限,并且缓存配置正确,可以确保数据导入顺利进行。
以上就是TYPO3 8.7 CLI 外部导入错误:权限与缓存问题解决方案的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号