|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Phinx |
|
4
|
|
|
* |
|
5
|
|
|
* (The MIT license) |
|
6
|
|
|
* Copyright (c) 2015 Rob Morgan |
|
7
|
|
|
* |
|
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
|
9
|
|
|
* of this software and associated * documentation files (the "Software"), to |
|
10
|
|
|
* deal in the Software without restriction, including without limitation the |
|
11
|
|
|
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
|
12
|
|
|
* sell copies of the Software, and to permit persons to whom the Software is |
|
13
|
|
|
* furnished to do so, subject to the following conditions: |
|
14
|
|
|
* |
|
15
|
|
|
* The above copyright notice and this permission notice shall be included in |
|
16
|
|
|
* all copies or substantial portions of the Software. |
|
17
|
|
|
* |
|
18
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
|
19
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
|
20
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
|
21
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
22
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
23
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
|
24
|
|
|
* IN THE SOFTWARE. |
|
25
|
|
|
* |
|
26
|
|
|
* @package Phinx |
|
27
|
|
|
* @subpackage Phinx\Console |
|
28
|
|
|
*/ |
|
29
|
|
|
namespace Phinx\Console\Command; |
|
30
|
|
|
|
|
31
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
32
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
33
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
34
|
|
|
|
|
35
|
|
|
class Status extends AbstractCommand |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* {@inheritdoc} |
|
39
|
|
|
*/ |
|
40
|
35 |
View Code Duplication |
protected function configure() |
|
|
|
|
|
|
41
|
|
|
{ |
|
42
|
35 |
|
parent::configure(); |
|
43
|
|
|
|
|
44
|
35 |
|
$this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment.'); |
|
45
|
|
|
|
|
46
|
35 |
|
$this->setName('status') |
|
47
|
35 |
|
->setDescription('Show migration status') |
|
48
|
35 |
|
->addOption('--format', '-f', InputOption::VALUE_REQUIRED, 'The output format: text or json. Defaults to text.') |
|
49
|
35 |
|
->setHelp( |
|
50
|
|
|
<<<EOT |
|
51
|
|
|
The <info>status</info> command prints a list of all migrations, along with their current status |
|
52
|
|
|
|
|
53
|
|
|
<info>phinx status -e development</info> |
|
54
|
|
|
<info>phinx status -e development -f json</info> |
|
55
|
|
|
|
|
56
|
|
|
The <info>version_order</info> configuration option is used to determine the order of the status migrations. |
|
57
|
|
|
EOT |
|
58
|
35 |
|
); |
|
59
|
35 |
|
} |
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Show the migration status. |
|
63
|
|
|
* |
|
64
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
65
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
66
|
|
|
* @return int 0 if all migrations are up, or an error code |
|
67
|
|
|
*/ |
|
68
|
4 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
69
|
|
|
{ |
|
70
|
4 |
|
$this->bootstrap($input, $output); |
|
71
|
|
|
|
|
72
|
4 |
|
$environment = $input->getOption('environment'); |
|
73
|
4 |
|
$format = $input->getOption('format'); |
|
74
|
|
|
|
|
75
|
4 |
View Code Duplication |
if ($environment === null) { |
|
|
|
|
|
|
76
|
3 |
|
$environment = $this->getConfig()->getDefaultEnvironment(); |
|
77
|
3 |
|
$output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment); |
|
78
|
3 |
|
} else { |
|
79
|
1 |
|
$output->writeln('<info>using environment</info> ' . $environment); |
|
80
|
|
|
} |
|
81
|
4 |
|
|
|
82
|
1 |
|
if (!$this->getConfig()->hasEnvironment($environment)) { |
|
83
|
1 |
|
$output->writeln('<error>Invalid environment name! Please specify an environment name from your config file.</error>'); |
|
84
|
|
|
return 1; |
|
85
|
4 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
if ($format !== null) { |
|
88
|
4 |
|
$output->writeln('<info>using format</info> ' . $format); |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
$output->writeln('<info>ordering by </info>' . $this->getConfig()->getVersionOrder() . " time"); |
|
92
|
|
|
|
|
93
|
|
|
// print the status |
|
94
|
|
|
return $this->getManager()->printStatus($environment, $format); |
|
95
|
|
|
} |
|
96
|
|
|
} |
|
97
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.