|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace HotRodCli\Commands\Classes; |
|
4
|
|
|
|
|
5
|
|
|
use HotRodCli\Commands\BaseCommand; |
|
6
|
|
|
use HotRodCli\Jobs\Filesystem\CopyFile; |
|
7
|
|
|
use HotRodCli\Jobs\Module\IsModuleExists; |
|
8
|
|
|
use HotRodCli\Jobs\Module\ReplaceText; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
12
|
|
|
|
|
13
|
|
|
class CreateUpgradeDataCommand extends BaseCommand |
|
14
|
|
|
{ |
|
15
|
|
|
protected $jobs = [ |
|
16
|
|
|
IsModuleExists::class => null, |
|
17
|
|
|
CopyFile::class => null, |
|
18
|
|
|
ReplaceText::class => null |
|
19
|
|
|
]; |
|
20
|
|
|
|
|
21
|
|
|
protected function configure() |
|
22
|
|
|
{ |
|
23
|
|
|
$this->setName('create:upgrade-data') |
|
24
|
|
|
->setDescription('Creates an upgrade data script') |
|
25
|
|
|
->addArgument( |
|
26
|
|
|
'namespace', |
|
27
|
|
|
InputArgument::REQUIRED, |
|
28
|
|
|
'What is the namespace of the module' |
|
29
|
|
|
) |
|
30
|
|
|
->setHelp('creates an upgrade data script in a given namespace'); |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
34
|
|
|
{ |
|
35
|
|
|
$this->setJobs(); |
|
36
|
|
|
|
|
37
|
|
|
try { |
|
38
|
|
|
$this->processUpgradeDataFile($input, $output); |
|
39
|
|
|
} catch (\Throwable $e) { |
|
40
|
|
|
$output->writeln('<error>' . $e->getMessage() . '</error>'); |
|
41
|
|
|
} |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
protected function processUpgradeDataFile(InputInterface $input, OutputInterface $output) |
|
45
|
|
|
{ |
|
46
|
|
|
$namespace = explode('_', $input->getArgument('namespace')); |
|
47
|
|
|
|
|
48
|
|
|
$this->jobs[IsModuleExists::class]->handle($input->getArgument('namespace'), $output); |
|
49
|
|
|
|
|
50
|
|
|
$this->jobs[CopyFile::class]->handle( |
|
51
|
|
|
$this->appContainer->get('resource_dir') . '/classes/UpgradeData.tphp', |
|
52
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/Setup/UpgradeData.php' |
|
53
|
|
|
); |
|
54
|
|
|
|
|
55
|
|
|
$this->jobs[ReplaceText::class]->handle( |
|
56
|
|
|
'{{namespace}}', |
|
57
|
|
|
str_replace('_', '\\', $input->getArgument('namespace')), |
|
58
|
|
|
$this->appContainer->get('app_dir') . '/app/code/' . $namespace[0] . '/' . $namespace[1] . '/Setup/' |
|
59
|
|
|
); |
|
60
|
|
|
|
|
61
|
|
|
$output->writeln('<info>Upgrade Data file successfully created</info>'); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|