|
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 InvalidArgumentException; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
|
|
15
|
|
|
class Breakpoint extends AbstractCommand |
|
16
|
|
|
{ |
|
17
|
|
|
/** |
|
18
|
|
|
* @var string |
|
19
|
|
|
*/ |
|
20
|
|
|
protected static $defaultName = 'breakpoint'; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* {@inheritDoc} |
|
24
|
|
|
* |
|
25
|
|
|
* @return void |
|
26
|
|
|
*/ |
|
27
|
|
|
protected function configure() |
|
28
|
|
|
{ |
|
29
|
|
|
parent::configure(); |
|
30
|
|
|
|
|
31
|
|
|
$this->addOption('--environment', '-e', InputOption::VALUE_REQUIRED, 'The target environment.'); |
|
32
|
|
|
|
|
33
|
|
|
$this->setDescription('Manage breakpoints') |
|
34
|
|
|
->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to target for the breakpoint') |
|
35
|
|
|
->addOption('--set', '-s', InputOption::VALUE_NONE, 'Set the breakpoint') |
|
36
|
|
|
->addOption('--unset', '-u', InputOption::VALUE_NONE, 'Unset the breakpoint') |
|
37
|
|
|
->addOption('--remove-all', '-r', InputOption::VALUE_NONE, 'Remove all breakpoints') |
|
38
|
|
|
->setHelp( |
|
39
|
|
|
<<<EOT |
|
40
|
|
|
The <info>breakpoint</info> command allows you to toggle, set, or unset a breakpoint against a specific target to inhibit rollbacks beyond a certain target. |
|
41
|
35 |
|
If no target is supplied then the most recent migration will be used. |
|
42
|
|
|
You cannot specify un-migrated targets |
|
43
|
35 |
|
|
|
44
|
|
|
<info>phinx breakpoint -e development</info> |
|
45
|
35 |
|
<info>phinx breakpoint -e development -t 20110103081132</info> |
|
46
|
|
|
<info>phinx breakpoint -e development -r</info> |
|
47
|
35 |
|
EOT |
|
48
|
35 |
|
); |
|
49
|
35 |
|
} |
|
50
|
35 |
|
|
|
51
|
35 |
|
/** |
|
52
|
|
|
* Toggle the breakpoint. |
|
53
|
|
|
* |
|
54
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input Input |
|
55
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output Output |
|
56
|
|
|
* @throws \InvalidArgumentException |
|
57
|
|
|
* @return int integer 0 on success, or an error code. |
|
58
|
|
|
*/ |
|
59
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
60
|
|
|
{ |
|
61
|
35 |
|
$this->bootstrap($input, $output); |
|
62
|
35 |
|
|
|
63
|
|
|
$environment = $input->getOption('environment'); |
|
64
|
|
|
$version = (int)$input->getOption('target') ?: null; |
|
65
|
|
|
$removeAll = $input->getOption('remove-all'); |
|
66
|
|
|
$set = $input->getOption('set'); |
|
67
|
|
|
$unset = $input->getOption('unset'); |
|
68
|
|
|
|
|
69
|
|
|
if ($environment === null) { |
|
70
|
|
|
$environment = $this->getConfig()->getDefaultEnvironment(); |
|
71
|
|
|
$output->writeln('<comment>warning</comment> no environment specified, defaulting to: ' . $environment, $this->verbosityLevel); |
|
72
|
|
|
} else { |
|
73
|
|
|
$output->writeln('<info>using environment</info> ' . $environment, $this->verbosityLevel); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
if (!$this->getConfig()->hasEnvironment($environment)) { |
|
77
|
|
|
$output->writeln(sprintf('<error>The environment "%s" does not exist</error>', $environment)); |
|
78
|
|
|
|
|
79
|
|
|
return self::CODE_ERROR; |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
if ($version && $removeAll) { |
|
|
|
|
|
|
83
|
|
|
throw new InvalidArgumentException('Cannot toggle a breakpoint and remove all breakpoints at the same time.'); |
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
if (($set && $unset) || ($set && $removeAll) || ($unset && $removeAll)) { |
|
87
|
|
|
throw new InvalidArgumentException('Cannot use more than one of --set, --unset, or --remove-all at the same time.'); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if ($removeAll) { |
|
91
|
|
|
// Remove all breakpoints. |
|
92
|
|
|
$this->getManager()->removeBreakpoints($environment); |
|
93
|
|
|
} elseif ($set) { |
|
94
|
|
|
// Set the breakpoint. |
|
95
|
|
|
$this->getManager()->setBreakpoint($environment, $version); |
|
96
|
|
|
} elseif ($unset) { |
|
97
|
|
|
// Unset the breakpoint. |
|
98
|
|
|
$this->getManager()->unsetBreakpoint($environment, $version); |
|
99
|
|
|
} else { |
|
100
|
|
|
// Toggle the breakpoint. |
|
101
|
|
|
$this->getManager()->toggleBreakpoint($environment, $version); |
|
102
|
|
|
} |
|
103
|
|
|
|
|
104
|
|
|
return self::CODE_SUCCESS; |
|
105
|
|
|
} |
|
106
|
|
|
} |
|
107
|
|
|
|
In PHP, under loose comparison (like
==, or!=, orswitchconditions), values of different types might be equal.For
integervalues, zero is a special case, in particular the following results might be unexpected: