-
Notifications
You must be signed in to change notification settings - Fork 142
Expand file tree
/
Copy pathMigrateRollbackCommand.php
More file actions
102 lines (84 loc) · 2.38 KB
/
Copy pathMigrateRollbackCommand.php
File metadata and controls
102 lines (84 loc) · 2.38 KB
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace Pingpong\Modules\Commands;
use Illuminate\Console\Command;
use Pingpong\Modules\Migrations\Migrator;
use Pingpong\Modules\Traits\MigrationLoaderTrait;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
class MigrateRollbackCommand extends Command
{
use MigrationLoaderTrait;
/**
* The console command name.
*
* @var string
*/
protected $name = 'module:migrate-rollback';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Rollback the modules migrations.';
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$module = $this->argument('module');
if (!empty($module)) {
$this->rollback($module);
return;
}
foreach (array_reverse($this->laravel['modules']->all()) as $module) {
$this->line('Running for module: <info>'.$module->getName().'</info>');
$this->rollback($module);
}
}
/**
* Rollback migration from the specified module.
*
* @param $module
*/
public function rollback($module)
{
if (is_string($module)) {
$module = $this->laravel['modules']->findOrFail($module);
}
$migrator = new Migrator($module);
$migrated = $migrator->rollback();
if (count($migrated)) {
foreach ($migrated as $migration) {
$this->line("Rollback: <info>{$migration}</info>");
}
return;
}
$this->comment('Nothing to rollback.');
}
/**
* Get the console command arguments.
*
* @return array
*/
protected function getArguments()
{
return array(
array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
);
}
/**
* Get the console command options.
*
* @return array
*/
protected function getOptions()
{
return array(
array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
);
}
}