I've been working on an extension that import a JSON, make a PHP array of what is needed and import it with external_import. This is meant to be a command that will be run with a Cronjob.
At the moment, I recieve 2 differents errors from external_import (I don't know why the error changes).
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]
OR
User doesn't have enough rights for synchronizing table tx_something_domain_model_formation.
Here are the methods from the Command 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);
}
CodePudding user response:
I've probably found the solution.
Adding this line Bootstrap::getInstance()->initializeBackendAuthentication();
makes it works. It uses TYPO3\CMS\Core\Core\Bootstrap;