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