|
| 1 | +<?php |
| 2 | + |
| 3 | +/** |
| 4 | + * Copyright Skywire. All rights reserved. |
| 5 | + * See LICENSE.txt for license details. |
| 6 | + * |
| 7 | + * @author Skywire Core Team |
| 8 | + * @copyright Copyright (c) 2021 Skywire (http://www.skywire.co.uk) |
| 9 | + */ |
| 10 | +declare(strict_types=1); |
| 11 | + |
| 12 | +namespace MageGen; |
| 13 | + |
| 14 | +use MageGen\Autocomplete\ModuleAutocomplete; |
| 15 | +use MageGen\Generator\SchemaPatchGenerator; |
| 16 | +use Symfony\Component\Console\Input\InputArgument; |
| 17 | +use Symfony\Component\Console\Input\InputInterface; |
| 18 | +use Symfony\Component\Console\Input\InputOption; |
| 19 | +use Symfony\Component\Console\Output\OutputInterface; |
| 20 | +use Symfony\Component\Console\Question\Question; |
| 21 | +use Symfony\Component\Console\Style\SymfonyStyle; |
| 22 | +use Twig\Environment; |
| 23 | + |
| 24 | +/** |
| 25 | + * @method string getCommandDescription() |
| 26 | + */ |
| 27 | +class MakeSchemaPatchCommand extends AbstractCommand |
| 28 | +{ |
| 29 | + /** |
| 30 | + * @var Environment |
| 31 | + */ |
| 32 | + protected $twig; |
| 33 | + |
| 34 | + protected static $defaultName = 'make:schema-patch'; |
| 35 | + |
| 36 | + /** |
| 37 | + * @var SchemaPatchGenerator |
| 38 | + */ |
| 39 | + private $schemaPatchGenerator; |
| 40 | + |
| 41 | + |
| 42 | + public function __construct(Environment $twig, string $name = null) |
| 43 | + { |
| 44 | + parent::__construct($twig, $name); |
| 45 | + |
| 46 | + $this->schemaPatchGenerator = new SchemaPatchGenerator($twig); |
| 47 | + } |
| 48 | + |
| 49 | + protected function configure(): void |
| 50 | + { |
| 51 | + parent::configure(); |
| 52 | + $this->addOption('magepath', 'm', InputOption::VALUE_REQUIRED, 'Path to Magento installation', getcwd()); |
| 53 | + $this->addArgument('module', InputArgument::OPTIONAL, 'Module name'); |
| 54 | + $this->addArgument('patch_name', InputArgument::OPTIONAL, 'Patch Name'); |
| 55 | + } |
| 56 | + |
| 57 | + protected function execute(InputInterface $input, OutputInterface $output): int |
| 58 | + { |
| 59 | + require $input->getOption('magepath') . '/vendor/autoload.php'; |
| 60 | + |
| 61 | + $io = new SymfonyStyle($input, $output); |
| 62 | + |
| 63 | + $module = $input->getArgument('module'); |
| 64 | + if (!$module) { |
| 65 | + $module = $io->askQuestion( |
| 66 | + (new Question('Module'))->setAutocompleterValues( |
| 67 | + (new ModuleAutocomplete())->getAutocompleteValues( |
| 68 | + $input->getOption('magepath') |
| 69 | + ) |
| 70 | + ) |
| 71 | + ); |
| 72 | + } |
| 73 | + |
| 74 | + $patchName = $input->getArgument('patch_name'); |
| 75 | + if (!$patchName) { |
| 76 | + $patchName = $io->askQuestion( |
| 77 | + new Question('Patch Name') |
| 78 | + ); |
| 79 | + } |
| 80 | + |
| 81 | + [$vendor, $module] = explode('_', $module); |
| 82 | + |
| 83 | + $patchFilePath = $this->schemaPatchGenerator->createSchemaPatch( |
| 84 | + $vendor, |
| 85 | + $module, |
| 86 | + $patchName, |
| 87 | + $this->getWriter($input) |
| 88 | + ); |
| 89 | + |
| 90 | + return 0; |
| 91 | + } |
| 92 | +} |
0 commit comments