错别字 8.7/外部导入 - 在自定义 extbase 扩展的 CLI 中使用外部导入导入时出错
Typo 8.7 / External Import - Error when importing with external import in CLI in custom extbase extension
我一直在开发一个导入 JSON 的扩展,制作一个包含所需内容的 PHP 数组,然后使用 external_import 导入它。这是一个将 运行 与 Cronjob 一起使用的命令。
目前,我从 external_import 收到 2 个不同的错误(我不知道为什么错误会改变)。
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.
以下是命令中的方法Class
protected function configure()
{
$this->setDescription('Synchroniser les formations externe dans typo3.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$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 = \TYPO3\CMS\Core\Utility\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);
}
我可能已经找到了解决方案。
添加这一行 Bootstrap::getInstance()->initializeBackendAuthentication();
使其有效。它使用 TYPO3\CMS\Core\Core\Bootstrap;
我一直在开发一个导入 JSON 的扩展,制作一个包含所需内容的 PHP 数组,然后使用 external_import 导入它。这是一个将 运行 与 Cronjob 一起使用的命令。
目前,我从 external_import 收到 2 个不同的错误(我不知道为什么错误会改变)。
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.
以下是命令中的方法Class
protected function configure()
{
$this->setDescription('Synchroniser les formations externe dans typo3.');
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$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 = \TYPO3\CMS\Core\Utility\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);
}
我可能已经找到了解决方案。
添加这一行 Bootstrap::getInstance()->initializeBackendAuthentication();
使其有效。它使用 TYPO3\CMS\Core\Core\Bootstrap;