/
Migrate.php
71 lines (66 loc) · 2.93 KB
/
Migrate.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
/**
* Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
*
* Licensed under The MIT License
* Redistributions of files must retain the above copyright notice.
*
* @copyright Copyright (c) Cake Software Foundation, Inc. (http://cakefoundation.org)
* @link http://cakephp.org CakePHP(tm) Project
* @license http://www.opensource.org/licenses/mit-license.php MIT License
*/
namespace Migrations\Command;
use Cake\Event\EventDispatcherTrait;
use Migrations\ConfigurationTrait;
use Phinx\Console\Command\Migrate as MigrateCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class Migrate extends MigrateCommand
{
use CommandTrait;
use ConfigurationTrait {
execute as parentExecute;
}
use EventDispatcherTrait;
/**
* {@inheritdoc}
*/
protected function configure()
{
$this->setName('migrate')
->setDescription('Migrate the database')
->setHelp('runs all available migrations, optionally up to a specific version')
->addOption('--target', '-t', InputOption::VALUE_REQUIRED, 'The version number to migrate to')
->addOption('--date', '-d', InputOption::VALUE_REQUIRED, 'The date to migrate to')
->addOption('--dry-run', '-x', InputOption::VALUE_NONE, 'Dump queries to standard output instead of executing it')
->addOption('--plugin', '-p', InputOption::VALUE_REQUIRED, 'The plugin containing the migrations')
->addOption('--connection', '-c', InputOption::VALUE_REQUIRED, 'The datasource connection to use')
->addOption('--source', '-s', InputOption::VALUE_REQUIRED, 'The folder where migrations are in')
->addOption('--fake', null, InputOption::VALUE_NONE, "Mark any migrations selected as run, but don't actually execute them")
->addOption(
'--no-lock',
null,
InputOption::VALUE_NONE,
'If present, no lock file will be generated after migrating'
);
}
/**
* Overrides the action execute method in order to vanish the idea of environments
* from phinx. CakePHP does not believe in the idea of having in-app environments
*
* @param \Symfony\Component\Console\Input\InputInterface $input the input object
* @param \Symfony\Component\Console\Output\OutputInterface $output the output object
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$event = $this->dispatchEvent('Migration.beforeMigrate');
if ($event->isStopped()) {
return $event->result ? BaseCommand::CODE_SUCCESS : BaseCommand::CODE_ERROR;
}
$this->parentExecute($input, $output);
$this->dispatchEvent('Migration.afterMigrate');
return BaseCommand::CODE_SUCCESS;
}
}