Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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