Untitled
unknown
plain_text
10 days ago
3.3 kB
4
Indexable
<?php declare(strict_types=1); namespace App\Command; use Jack\Symfony\ProcessManager; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Process\Process; class SplitFluxCommand extends Command { // the name of the command (the part after "bin/console") protected static $defaultName = 'leoo:split:flux'; public array $categories = []; protected function configure(): void { $this->setHelp('Split flux reducce'); $this ->addArgument('max_parallel_processes', InputArgument::REQUIRED, 'The max parallel processes.') ->addArgument('batch', InputArgument::REQUIRED, 'The batch import.')// ... ; } protected function execute(InputInterface $input, OutputInterface $output): int { $processes = []; $path = './var/file_storage/reducce/incoming/reducticket.fr.json'; $fileContents = file_get_contents($path); $fileContents = str_replace('#cdata-section', 'cdata_section', $fileContents); $fileContents = json_decode($fileContents, true, 512, \JSON_THROW_ON_ERROR); $this->extractGere($fileContents); foreach ($this->categories as $category) { $processes[] = new Process('bin/console akeneo:batch:publish-job-to-queue ' . $input->getArgument('batch') . ' -c "{\"filePath\": \"reducticket.fr-' . $category . '.json\"}" && composer j:q'); } $proc_mgr = new ProcessManager(); $proc_mgr->runParallel($processes, $input->getArgument('max_parallel_processes'), 1); return 0; } private function extractGere(array $fileContents): void { $returnArticle = []; foreach ($fileContents['catalogues'] as $catalogues) { foreach ($catalogues['catalogue'] as $catalogue) { foreach ($catalogue['genres'] as $genres) { foreach ($genres['genre'] as $genre) { foreach ($genre['sousgenres'] as $sousgenres) { if (!empty($sousgenres['sousgenre'])) { foreach ($sousgenres['sousgenre'] as $sousgenre) { unset($catalogue['genres']); $returnArticle['catalogues']['catalogue'] = $catalogue; unset($genre['genres']); $returnArticle['catalogues']['catalogue']['genres']['genre'] = $genre; unset($sousgenre['sousgenres']); $returnArticle['catalogues']['catalogue']['genres']['genre']['sousgenres']['sousgenre'] = $sousgenre; $this->categories[] = $sousgenre['sousgenres_id']; file_put_contents('./var/file_storage/reducce/incoming/reducticket.fr-' . $sousgenre['sousgenres_id'] . '.json', json_encode($returnArticle, \JSON_PRETTY_PRINT)); } } } } } } } } }
Editor is loading...
Leave a Comment