src/Command/InitRefonte.php line 107

Open in your IDE?
  1. <?php
  2. namespace App\Command;
  3. use App\Controller\MoulinetteController;
  4. use App\Entity\Adherent\FicheServices;
  5. use App\Entity\Adherent\Magasin;
  6. use App\Entity\Adherent\MagasinCommunication;
  7. use App\Entity\Adherent\Specialite;
  8. use App\Entity\Webfactory\WebfactoryCustomPage;
  9. use App\Entity\Webfactory\WebfactoryPage;
  10. use App\Entity\Webfactory\WebfactoryWidget;
  11. use App\Entity\Webfactory\Widget\Createur\Teams;
  12. use App\Entity\Webfactory\Widget\WidgetAbstract;
  13. use Doctrine\ORM\EntityManagerInterface;
  14. use Symfony\Component\Console\Attribute\AsCommand;
  15. use Symfony\Component\Console\Command\Command;
  16. use Symfony\Component\Console\Input\InputInterface;
  17. use Symfony\Component\Console\Output\OutputInterface;
  18. use Symfony\Component\Console\Question\ConfirmationQuestion;
  19. use Symfony\Component\Console\Style\SymfonyStyle;
  20. use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
  21. use Symfony\Component\HttpFoundation\JsonResponse;
  22. use Symfony\Component\Process\Process;
  23. #[AsCommand(
  24.     name'app:init-refonte',
  25.     description'Effectue les migrations et moulinettes pour le lancement de la refonte',
  26. )]
  27. class InitRefonte extends Command
  28. {
  29.     public function __construct(private readonly EntityManagerInterface $entityManager, private readonly ParameterBagInterface $parameterBag)
  30.     {
  31.         parent::__construct();
  32.     }
  33.     protected function execute(InputInterface $inputOutputInterface $output): int
  34.     {
  35.         $io = new SymfonyStyle($input$output);
  36.         $io->title('Lancement de la refonte');
  37.         $moulinetteController = new MoulinetteController($this->entityManager$this->parameterBag);
  38.         $io->section('Migration générale');
  39.         $this->runCommand('Migration générale', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionRefonteGeneral''--up'], $output);
  40.         $io->section('Migration Notifications');
  41.         $this->runCommand('Migration Notifications', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\Version_notifications''--up'], $output);
  42.         $io->section('Mise à jour de la structure des cannaux de communication');
  43.         $moulinetteController->majCanauxCommunication(true$output);
  44.         $io->section('Mise à jour de la structure des consentements des services et spécialités');
  45.         $moulinetteController->copyConsentementServicesSpecInfosCompl(true$output);
  46.         $io->section('Mise à jour de la structure des convictions');
  47.         $moulinetteController->updateConvictions(true$output);
  48.         $io->section('Migration pour insertion des images génériques');
  49.         $this->runCommand('Migration images génériques', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionImagesGeneriques''--up'], $output);
  50.         $io->section('Mise à jour de la structure des images _1');
  51.         $moulinetteController->updateImagesOpcSructure(true$output);
  52.         $io->section('Mise à jour de la structure des images _2');
  53.         $moulinetteController->updateImageCommunicationPrint(true$output);
  54.         $io->section('Migration Jauge taux de remplissage');
  55.         $this->runCommand('Migration Jauge taux de remplissage', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionRefonteJaugeOpc''--up'], $output);
  56.         $io->section('Mise à jour de la structure des réseaux');
  57.         $this->runCommand('Migration structure des réseaux', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionRefonteMagasinReseaux''--up'], $output);
  58.         $io->section('Mise à jour des tables pour la modération progress');
  59.         $this->runCommand('Migration structure des tables pour modération', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\Version_moderation''--up'], $output);
  60.         $io->section('Mise à jour de la structure des spécialités');
  61.         $this->updateImagesSpecialtes($output);
  62.         $helper $this->getHelper('question');
  63.         $question = new ConfirmationQuestion("
  64.         Avant de continuer : Vérifier que les widgets Verbatims on bien été exporté.\n
  65.         Si ce n'est pas le cas :\n
  66.         Export verbatim classique : SELECT wa.magasin AS magasin, wa.page_custom_id AS page_custom_id, wa.page_id AS page_id, wa.lang, wa.discr AS disc, wa.widget_id AS widget_identifier, wbc.id as widget_id, wbc.author AS author, mc.conviction FROM widget_abstract wa LEFT JOIN webfactory_page wp ON wa.page_id = wp.identifier LEFT JOIN webfactory_widget ww ON wa.widget_id = ww.identifier LEFT JOIN widget_verbatim_classique wbc ON wa.id = wbc.id LEFT JOIN magasin_conviction mc ON wbc.conviction_id = mc.id WHERE ww.identifier = 'verbatim' AND wa.theme = 'Classique' dans public/documents nom : widgets_verbatim_classique.csv
  67.         Export verbatim créateur :  SELECT wa.magasin AS magasin, wa.page_custom_id AS page_custom_id, wa.page_id AS page_id, wa.lang, wa.discr AS disc, wa.widget_id AS widget_identifier, wbc.id as widget_id, wbc.author AS author, mc.conviction FROM widget_abstract wa LEFT JOIN webfactory_page wp ON wa.page_id = wp.identifier LEFT JOIN webfactory_widget ww ON wa.widget_id = ww.identifier LEFT JOIN widget_verbatim_createur wbc ON wa.id = wbc.id LEFT JOIN magasin_conviction mc ON wbc.conviction_id = mc.id WHERE ww.identifier = 'verbatim' AND wa.theme = 'Createur' dans public/documents nom : widgets_verbatim_createur.csv
  68.         "false);
  69.         if (!$helper->ask($input$output$question)) {
  70.             $io->section('Migration structure widgets Verbatim');
  71.             $this->runCommand('Migration widgets Verbatim', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionWidgetsVerbatim''--up'], $output);
  72.             $io->section('Réinsertion des widgets verbatim');
  73.             $moulinetteController->insertWidgetsVerbatims($output);
  74.             $io->section('Migration info bulles');
  75.             $this->runCommand('Migration info bulles', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionRefonteInfosBulles''--up'], $output);
  76.             $this->runCommand('Migration Last', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\VersionLast''--up'], $output);
  77.         }
  78.         $io->section('Mise à jour de la structure des articles (encart)');
  79.         $this->runCommand('Migration structure des tables pour les articles', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\Version_update_articles''--up'], $output);
  80.         $this->runCommand('Migration structure des tables pour les articles', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\Version_article_color''--up'], $output);
  81.         $io->section('Ajout de la description personalisée des marques');
  82.         $this->runCommand('Migration structure des tables pour la description personalisée des marques', ['php''bin/console''doctrine:migration:execute''DoctrineMigrations\Version_description_personalisee_marque''--up'], $output);
  83.         $output->writeln([
  84.             '<info>Commande terminée</>',
  85.             '<info>==========================</>'
  86.         ]);
  87.         return Command::SUCCESS;
  88.     }
  89.     // Execute une commande
  90.     private function runCommand($name, array $arguments = [], OutputInterface $output): void
  91.     {
  92.         $process = new Process($arguments);
  93.         $process->run(function ($type$buffer) use ($output) {
  94.             $output->write($buffer);
  95.         });
  96.         if (!$process->isSuccessful()) {
  97.             throw new \RuntimeException(sprintf('Erreur lors de l\'exécution de la commande'));
  98.         } else {
  99.             $output->writeln('Commande ' $name ' OK');
  100.         }
  101.     }
  102.     // Enleve les .svg sur les images des spécialités
  103.     private function updateImagesSpecialtes($output)
  104.     {
  105.         $specialites $this->entityManager->getRepository(Specialite::class)->findAll();
  106.         foreach ($specialites as $spe) {
  107.             if (!is_null($spe->getSvg())) {
  108.                 $spe->setSvg(str_replace('.svg'''$spe->getSvg()));
  109.                 $this->entityManager->persist($spe);
  110.             }
  111.         }
  112.         $this->entityManager->flush();
  113.         $output->writeln('Update des spécialités OK');
  114.     }
  115. }