|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace LaravelFreelancerNL\Aranguent\Console; |
|
6
|
|
|
|
|
7
|
|
|
use Illuminate\Console\Command; |
|
8
|
|
|
use Illuminate\Database\Console\WipeCommand as IlluminateWipeCommand; |
|
9
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
10
|
|
|
|
|
11
|
|
|
class WipeCommand extends IlluminateWipeCommand |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* The console command description. |
|
15
|
|
|
* |
|
16
|
|
|
* @var string |
|
17
|
|
|
*/ |
|
18
|
|
|
protected $description = 'Drop all tables, views, views, custom analyzers, named graphs and types'; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Execute the console command. |
|
22
|
|
|
* |
|
23
|
|
|
* @return int |
|
24
|
|
|
*/ |
|
25
|
44 |
|
public function handle() |
|
26
|
|
|
{ |
|
27
|
44 |
|
if ($this->isProhibited() || |
|
28
|
44 |
|
! $this->confirmToProceed()) { |
|
29
|
|
|
return Command::FAILURE; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
44 |
|
$database = $this->input->getOption('database'); |
|
33
|
|
|
|
|
34
|
44 |
|
$this->handleDrops($database); |
|
35
|
|
|
|
|
36
|
42 |
|
return 0; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @param string $database |
|
41
|
|
|
* @return void |
|
42
|
|
|
*/ |
|
43
|
44 |
|
protected function handleDrops($database) |
|
44
|
|
|
{ |
|
45
|
44 |
|
if ($this->option('drop-graphs') || $this->option('drop-all')) { |
|
46
|
34 |
|
$this->dropAllGraphs($database); |
|
47
|
|
|
|
|
48
|
34 |
|
$this->components->info('Dropped all named graphs successfully.'); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
44 |
|
if ($this->option('drop-views') || $this->option('drop-all')) { |
|
52
|
34 |
|
$this->dropAllViews($database); |
|
53
|
|
|
|
|
54
|
34 |
|
$this->components->info('Dropped all views successfully.'); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
44 |
|
$this->dropAllTables($database); |
|
58
|
|
|
|
|
59
|
44 |
|
$this->components->info('Dropped all tables successfully.'); |
|
60
|
|
|
|
|
61
|
44 |
|
if ($this->option('drop-types')) { |
|
62
|
2 |
|
$this->dropAllTypes($database); |
|
63
|
|
|
|
|
64
|
|
|
$this->components->info('Dropped all types successfully.'); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
42 |
|
if ($this->option('drop-analyzers') || $this->option('drop-all')) { |
|
68
|
34 |
|
$this->dropAllAnalyzers($database); |
|
69
|
|
|
|
|
70
|
34 |
|
$this->components->info('Dropped all analyzers successfully.'); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Drop all of the database analyzers. |
|
76
|
|
|
* |
|
77
|
|
|
* @param null|string $database |
|
78
|
|
|
* @return void |
|
79
|
|
|
*/ |
|
80
|
34 |
|
protected function dropAllAnalyzers($database) |
|
81
|
|
|
{ |
|
82
|
|
|
/** @phpstan-ignore offsetAccess.nonOffsetAccessible */ |
|
83
|
34 |
|
$this->laravel['db']->connection($database) |
|
84
|
34 |
|
->getSchemaBuilder() |
|
85
|
34 |
|
->dropAllAnalyzers(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Drop all of the database analyzers. |
|
90
|
|
|
* |
|
91
|
|
|
* @param null|string $database |
|
92
|
|
|
* @return void |
|
93
|
|
|
*/ |
|
94
|
34 |
|
protected function dropAllGraphs($database) |
|
95
|
|
|
{ |
|
96
|
|
|
/** @phpstan-ignore offsetAccess.nonOffsetAccessible */ |
|
97
|
34 |
|
$this->laravel['db']->connection($database) |
|
98
|
34 |
|
->getSchemaBuilder() |
|
99
|
34 |
|
->dropAllGraphs(); |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
/** |
|
103
|
|
|
* Get the console command options. |
|
104
|
|
|
* |
|
105
|
|
|
* @return array<int, array<int, int|string|null>> |
|
106
|
|
|
*/ |
|
107
|
451 |
|
protected function getOptions() |
|
108
|
|
|
{ |
|
109
|
451 |
|
return [ |
|
110
|
451 |
|
['database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use'], |
|
111
|
451 |
|
['drop-all', null, InputOption::VALUE_NONE, 'Drop all tables, views, custom analyzers and named graphs (ArangoDB only)'], |
|
112
|
451 |
|
['drop-analyzers', null, InputOption::VALUE_NONE, 'Drop all tables and custom analyzers (ArangoDB only)'], |
|
113
|
451 |
|
['drop-graphs', null, InputOption::VALUE_NONE, 'Drop all tables and named graphs (ArangoDB only)'], |
|
114
|
451 |
|
['drop-views', null, InputOption::VALUE_NONE, 'Drop all tables and views (ArangoDB only)'], |
|
115
|
451 |
|
['drop-types', null, InputOption::VALUE_NONE, 'Drop all tables and types (Postgres only)'], |
|
116
|
451 |
|
['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'], |
|
117
|
451 |
|
]; |
|
118
|
|
|
} |
|
119
|
|
|
} |
|
120
|
|
|
|