|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* MIT License |
|
5
|
|
|
* For full license information, please view the LICENSE file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
namespace Phinx\Console\Command; |
|
9
|
|
|
|
|
10
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
12
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
13
|
|
|
|
|
14
|
|
|
class Status extends AbstractCommand |
|
15
|
|
|
{ |
|
16
|
|
|
/** |
|
17
|
|
|
* @var string |
|
18
|
|
|
*/ |
|
19
|
|
|
protected static $defaultName = 'status'; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* {@inheritDoc} |
|
23
|
|
|
* |
|
24
|
|
|
* @return void |
|
25
|
|
|
*/ |
|
26
|
|
|
protected function configure() |
|
27
|
|
|
{ |
|
28
|
|
|
parent::configure(); |
|
29
|
|
|
|
|
30
|
|
|
$this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment.'); |
|
31
|
|
|
|
|
32
|
|
|
$this->setDescription('Show migration status') |
|
33
|
|
|
->addOption('--format', '-f', InputOption::VALUE_REQUIRED, 'The output format: text or json. Defaults to text.') |
|
34
|
|
|
->setHelp( |
|
35
|
|
|
<<<EOT |
|
36
|
|
|
The <info>status</info> command prints a list of all migrations, along with their current status |
|
37
|
|
|
|
|
38
|
|
|
<info>phinx status -e development</info> |
|
39
|
|
|
<info>phinx status -e development -f json</info> |
|
40
|
35 |
|
|
|
41
|
|
|
The <info>version_order</info> configuration option is used to determine the order of the status migrations. |
|
42
|
35 |
|
EOT |
|
43
|
|
|
); |
|
44
|
35 |
|
} |
|
45
|
|
|
|
|
46
|
35 |
|
/** |
|
47
|
35 |
|
* Show the migration status. |
|
48
|
35 |
|
* |
|
49
|
35 |
|
* @param \Symfony\Component\Console\Input\InputInterface $input Input |
|
50
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output Output |
|
51
|
|
|
* |
|
52
|
|
|
* @return int 0 if all migrations are up, or an error code |
|
53
|
|
|
*/ |
|
54
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
55
|
|
|
{ |
|
56
|
|
|
$this->bootstrap($input, $output); |
|
57
|
|
|
|
|
58
|
35 |
|
$format = $input->getOption('format'); |
|
59
|
35 |
|
|
|
60
|
|
|
$environment = $this->getEnvironment($input, $output); |
|
61
|
|
|
if ($environment === null) { |
|
62
|
|
|
return self::CODE_ERROR; |
|
63
|
|
|
} |
|
64
|
|
|
|
|
65
|
|
|
if ($format !== null) { |
|
66
|
|
|
$output->writeln('<info>using format</info> ' . $format); |
|
67
|
|
|
} |
|
68
|
4 |
|
|
|
69
|
|
|
$output->writeln('<info>ordering by </info>' . $this->getConfig()->getVersionOrder() . " time"); |
|
70
|
4 |
|
|
|
71
|
|
|
// print the status |
|
72
|
4 |
|
$result = $this->getManager()->printStatus($environment, $format); |
|
73
|
4 |
|
|
|
74
|
|
|
if ($result['hasMissingMigration']) { |
|
75
|
4 |
|
return self::CODE_STATUS_MISSING; |
|
76
|
3 |
|
} elseif ($result['hasDownMigration']) { |
|
77
|
3 |
|
return self::CODE_STATUS_DOWN; |
|
78
|
3 |
|
} |
|
79
|
1 |
|
|
|
80
|
|
|
return self::CODE_SUCCESS; |
|
81
|
4 |
|
} |
|
82
|
|
|
} |
|
83
|
|
|
|