1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: joshgulledge |
5
|
|
|
* Date: 2/15/18 |
6
|
|
|
* Time: 3:23 PM |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace LCI\Blend\Console; |
10
|
|
|
|
11
|
|
|
use LCI\Blend\Migrations\MigrationsCreator; |
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
|
16
|
|
|
class GenerateMigration extends BaseCommand |
17
|
|
|
{ |
18
|
|
|
protected $loadMODX = false; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @see https://symfony.com/doc/current/console.html |
22
|
|
|
* |
23
|
|
|
*/ |
24
|
|
|
protected function configure() |
25
|
|
|
{ |
26
|
|
|
$this |
27
|
|
|
->setName('blend:generate') |
28
|
|
|
->setDescription('Generate a Blend Migration Class') |
29
|
|
|
->addOption( |
30
|
|
|
'name', |
31
|
|
|
'N', |
32
|
|
|
InputOption::VALUE_OPTIONAL, |
33
|
|
|
'The name of the generated migration file' |
34
|
|
|
) |
35
|
|
|
->addOption( |
36
|
|
|
'type', |
37
|
|
|
't', |
38
|
|
|
InputOption::VALUE_OPTIONAL, |
39
|
|
|
'Server type to run migrations as, default is master. Possible master, staging, dev and local', |
40
|
|
|
'master' |
41
|
|
|
) |
42
|
|
|
->addOption( |
43
|
|
|
'path', |
44
|
|
|
'p', |
45
|
|
|
InputOption::VALUE_OPTIONAL, |
46
|
|
|
'Optional set the directory path to write the migration. Note database/migrations will be added to the path and if needed created.', |
47
|
|
|
'' |
48
|
|
|
); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
/** |
52
|
|
|
* @param InputInterface $input |
53
|
|
|
* @param OutputInterface $output |
54
|
|
|
* @return int|null|void |
55
|
|
|
*/ |
56
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
57
|
|
|
{ |
58
|
|
|
$name = (string)$input->getOption('name'); |
59
|
|
|
$type = (string)$input->getOption('type'); |
60
|
|
|
$path = (string)$input->getOption('path'); |
61
|
|
|
|
62
|
|
|
$output->writeln('Generate name: '.$name); |
63
|
|
|
|
64
|
|
|
$migrationCreator = new MigrationsCreator($this->consoleUserInteractionHandler); |
65
|
|
|
|
66
|
|
|
if (empty($path)) { |
67
|
|
|
$config = $this->console->getConfig(); |
68
|
|
|
if (isset($config['BLEND_LOCAL_MIGRATION_PATH'])) { |
69
|
|
|
$path = $config['BLEND_LOCAL_MIGRATION_PATH']; |
70
|
|
|
|
71
|
|
|
} else { |
72
|
|
|
// MODX components path |
73
|
|
|
if (defined('MODX_CORE_PATH')) { |
74
|
|
|
$path = MODX_CORE_PATH; |
|
|
|
|
75
|
|
|
} else { |
76
|
|
|
$path = dirname(dirname(dirname(dirname(__DIR__)))) . DIRECTORY_SEPARATOR; |
77
|
|
|
} |
78
|
|
|
$path .= 'components/'; |
79
|
|
|
|
80
|
|
|
if (file_exists($path)) { |
81
|
|
|
$path .= 'blend/'; |
82
|
|
|
if (!file_exists($path)) { |
83
|
|
|
mkdir($path); |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
$success = $migrationCreator |
90
|
|
|
->setVerbose($output->getVerbosity()) |
91
|
|
|
->setName($name) |
92
|
|
|
->setDescription('') |
93
|
|
|
->setServerType($type) |
94
|
|
|
->setBaseMigrationsPath($path) |
95
|
|
|
->createBlankMigrationClassFile(); |
96
|
|
|
|
97
|
|
|
if (!$success) { |
98
|
|
|
$output->writeln('Could not write file'); |
99
|
|
|
} |
100
|
|
|
} |
101
|
|
|
} |