Completed
Push — master ( 7a93ab...e5b266 )
by Michael
03:59
created

MigrateResetCommand::run()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 9
nc 2
nop 0
1
<?php
2
3
namespace Schnittstabil\Dartisan\Commands;
4
5
use Garden\Cli\Cli;
6
use Garden\Cli\Args;
7
use Illuminate\Database\Migrations\Migrator;
8
9
class MigrateResetCommand extends Command
10
{
11
    use DatabaseAwareCommandTrait;
12
    use MigrationAwareCommandTrait;
13
14
    public static $name = 'migrate:reset';
15
    protected $args;
16
    protected $migrator;
17
    protected $migrationsPath;
18
19 View Code Duplication
    public function __construct(callable $outputFormatter, Args $args, Migrator $migrator, $migrationsPath)
20
    {
21
        parent::__construct($outputFormatter);
22
        $this->args = $args;
23
        $this->migrator = $migrator;
24
        $this->migrationsPath = $migrationsPath;
25
    }
26
27
    public function run()
28
    {
29
        if (!$this->migrator->repositoryExists()) {
30
            $this->echoError('No migration table found.');
31
            return 1;
32
        }
33
34
        $path = $this->args->getOpt('path', $this->migrationsPath);
35
        $pretend = $this->args->getOpt('pretend', false);
36
        $this->migrator->reset($path, $pretend);
37
        $this->echoNotes($this->migrator->getNotes());
38
        return 0;
39
    }
40
41
    public static function register(Cli $cli)
42
    {
43
        $cli = static::registerDatabaseOpts($cli);
44
        $cli = static::registerMigrationOpts($cli);
45
46
        return $cli
47
            ->command(static::$name)
48
            ->description('Rollback all database migrations.')
49
            ->opt('pretend', 'Dump the SQL queries that would be run.');
50
    }
51
}
52