1
|
|
|
<?php |
2
|
|
|
namespace Caffeinated\Modules\Console\Commands; |
3
|
|
|
|
4
|
|
|
use Caffeinated\Modules\Modules; |
5
|
|
|
use Caffeinated\Modules\Traits\MigrationTrait; |
6
|
|
|
use Illuminate\Console\ConfirmableTrait; |
7
|
|
|
use Illuminate\Console\Command; |
8
|
|
|
use Symfony\Component\Console\Input\InputOption; |
9
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
10
|
|
|
|
11
|
|
|
class ModuleMigrateRollbackCommand extends Command |
12
|
|
|
{ |
13
|
|
|
use MigrationTrait, ConfirmableTrait; |
14
|
|
|
|
15
|
|
|
/** |
16
|
|
|
* The console command name. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $name = 'module:migrate:rollback'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* The console command description. |
24
|
|
|
* |
25
|
|
|
* @var string |
26
|
|
|
*/ |
27
|
|
|
protected $description = 'Rollback the last database migrations for a specific or all modules'; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* @var Modules |
31
|
|
|
*/ |
32
|
|
|
protected $module; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* Create a new command instance. |
36
|
|
|
* |
37
|
|
|
* @param Modules $module |
38
|
|
|
*/ |
39
|
|
|
public function __construct(Modules $module) |
40
|
|
|
{ |
41
|
|
|
parent::__construct(); |
42
|
|
|
|
43
|
|
|
$this->module = $module; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Execute the console command. |
48
|
|
|
* |
49
|
|
|
* @return mixed |
50
|
|
|
*/ |
51
|
|
|
public function fire() |
52
|
|
|
{ |
53
|
|
|
if (! $this->confirmToProceed()) return null; |
54
|
|
|
|
55
|
|
|
$slug = $this->argument('slug'); |
56
|
|
|
|
57
|
|
|
if ($slug) { |
58
|
|
|
return $this->rollback($Slug); |
|
|
|
|
59
|
|
|
} else { |
60
|
|
|
foreach ($this->module->all() as $module) { |
61
|
|
|
$this->rollback($module['slug']); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
/** |
67
|
|
|
* Run the migration rollback for the specified module. |
68
|
|
|
* |
69
|
|
|
* @param string $slug |
70
|
|
|
* @return mixed |
71
|
|
|
*/ |
72
|
|
|
protected function rollback($slug) |
73
|
|
|
{ |
74
|
|
|
$this->requireMigrations($slug); |
75
|
|
|
|
76
|
|
|
$this->call('migrate:rollback', [ |
77
|
|
|
'--database' => $this->option('database'), |
78
|
|
|
'--force' => $this->option('force'), |
79
|
|
|
'--pretend' => $this->option('pretend'), |
80
|
|
|
]); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get the console command arguments. |
85
|
|
|
* |
86
|
|
|
* @return array |
87
|
|
|
*/ |
88
|
|
|
protected function getArguments() |
89
|
|
|
{ |
90
|
|
|
return [['slug', InputArgument::OPTIONAL, 'Module slug.']]; |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* Get the console command options. |
95
|
|
|
* |
96
|
|
|
* @return array |
97
|
|
|
*/ |
98
|
|
|
protected function getOptions() |
99
|
|
|
{ |
100
|
|
|
return [ |
101
|
|
|
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'], |
102
|
|
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run while in production.'], |
103
|
|
|
['pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'] |
104
|
|
|
]; |
105
|
|
|
} |
106
|
|
|
} |
107
|
|
|
|
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.