1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the SVN-Buddy library. |
4
|
|
|
* For the full copyright and license information, please view |
5
|
|
|
* the LICENSE file that was distributed with this source code. |
6
|
|
|
* |
7
|
|
|
* @copyright Alexander Obuhovich <[email protected]> |
8
|
|
|
* @link https://github.com/console-helpers/svn-buddy |
9
|
|
|
*/ |
10
|
|
|
|
11
|
|
|
namespace ConsoleHelpers\SVNBuddy\Command\Dev; |
12
|
|
|
|
13
|
|
|
|
14
|
|
|
use ConsoleHelpers\DatabaseMigration\MigrationManager; |
15
|
|
|
use ConsoleHelpers\SVNBuddy\Command\AbstractCommand; |
16
|
|
|
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext; |
17
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
18
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
19
|
|
|
use Symfony\Component\Console\Input\InputOption; |
20
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
21
|
|
|
|
22
|
|
|
class MigrationCreateCommand extends AbstractCommand |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Migration manager. |
27
|
|
|
* |
28
|
|
|
* @var MigrationManager |
29
|
|
|
*/ |
30
|
|
|
private $_migrationManager; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* {@inheritdoc} |
34
|
|
|
*/ |
35
|
|
|
protected function configure() |
36
|
|
|
{ |
37
|
|
|
$this |
38
|
|
|
->setName('dev:migration-create') |
39
|
|
|
->setDescription( |
40
|
|
|
'Creates new database migration' |
41
|
|
|
) |
42
|
|
|
->addArgument( |
43
|
|
|
'name', |
44
|
|
|
InputArgument::REQUIRED, |
45
|
|
|
'Migration name' |
46
|
|
|
) |
47
|
|
|
->addOption( |
48
|
|
|
'extension', |
49
|
|
|
'e', |
50
|
|
|
InputOption::VALUE_REQUIRED, |
51
|
|
|
'Migration file extension', |
52
|
|
|
'sql' |
53
|
|
|
); |
54
|
|
|
|
55
|
|
|
parent::configure(); |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Prepare dependencies. |
60
|
|
|
* |
61
|
|
|
* @return void |
62
|
|
|
*/ |
63
|
|
|
protected function prepareDependencies() |
64
|
|
|
{ |
65
|
|
|
parent::prepareDependencies(); |
66
|
|
|
|
67
|
|
|
$container = $this->getContainer(); |
68
|
|
|
|
69
|
|
|
$this->_migrationManager = $container['migration_manager']; |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Return possible values for the named option |
74
|
|
|
* |
75
|
|
|
* @param string $optionName Option name. |
76
|
|
|
* @param CompletionContext $context Completion context. |
77
|
|
|
* |
78
|
|
|
* @return array |
79
|
|
|
*/ |
80
|
|
|
public function completeOptionValues($optionName, CompletionContext $context) |
81
|
|
|
{ |
82
|
|
|
$ret = parent::completeOptionValues($optionName, $context); |
83
|
|
|
|
84
|
|
|
if ( $optionName === 'extension' ) { |
85
|
|
|
return $this->_migrationManager->getMigrationFileExtensions(); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
return $ret; |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* {@inheritdoc} |
93
|
|
|
*/ |
94
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
95
|
|
|
{ |
96
|
|
|
$migration_name = $this->_migrationManager->createMigration( |
97
|
|
|
$this->io->getArgument('name'), |
|
|
|
|
98
|
|
|
$this->io->getOption('extension') |
|
|
|
|
99
|
|
|
); |
100
|
|
|
|
101
|
|
|
$this->io->writeln('Migration <info>' . $migration_name . '</info> created.'); |
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
} |
105
|
|
|
|