Code Duplication    Length = 98-98 lines in 2 locations

src/Commands/MigrateResetCommand.php 1 location

@@ 11-108 (lines=98) @@
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class MigrateResetCommand extends Command
12
{
13
    use MigrationLoaderTrait;
14
15
    /**
16
     * The console command name.
17
     *
18
     * @var string
19
     */
20
    protected $name = 'module:migrate-reset';
21
22
    /**
23
     * The console command description.
24
     *
25
     * @var string
26
     */
27
    protected $description = 'Reset the modules migrations.';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return mixed
33
     */
34
    public function fire()
35
    {
36
        $module = $this->argument('module');
37
38
        if (!empty($module)) {
39
            $this->reset($module);
40
41
            return;
42
        }
43
44
        foreach (array_reverse($this->laravel['modules']->all()) as $module) {
45
            $this->line('Running for module: <info>' . $module->getName() . '</info>');
46
47
            $this->reset($module);
48
        }
49
    }
50
51
    /**
52
     * Rollback migration from the specified module.
53
     *
54
     * @param $module
55
     */
56
    public function reset($module)
57
    {
58
        if (is_string($module)) {
59
            $module = $this->laravel['modules']->findOrFail($module);
60
        }
61
62
        $migrator = new Migrator($module);
63
64
        $database = $this->option('database');
65
66
        if (!empty($database)) {
67
            $migrator->setDatabase($database);
68
        }
69
70
        $migrated = $migrator->reset();
71
72
        if (count($migrated)) {
73
            foreach ($migrated as $migration) {
74
                $this->line("Rollback: <info>{$migration}</info>");
75
            }
76
77
            return;
78
        }
79
80
        $this->comment('Nothing to rollback.');
81
    }
82
83
    /**
84
     * Get the console command arguments.
85
     *
86
     * @return array
87
     */
88
    protected function getArguments()
89
    {
90
        return array(
91
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
92
        );
93
    }
94
95
    /**
96
     * Get the console command options.
97
     *
98
     * @return array
99
     */
100
    protected function getOptions()
101
    {
102
        return array(
103
            array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
104
            array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
105
            array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
106
        );
107
    }
108
}
109

src/Commands/MigrateRollbackCommand.php 1 location

@@ 11-108 (lines=98) @@
8
use Symfony\Component\Console\Input\InputArgument;
9
use Symfony\Component\Console\Input\InputOption;
10
11
class MigrateRollbackCommand extends Command
12
{
13
    use MigrationLoaderTrait;
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 modules migrations.';
28
29
    /**
30
     * Execute the console command.
31
     *
32
     * @return mixed
33
     */
34
    public function fire()
35
    {
36
        $module = $this->argument('module');
37
38
        if (!empty($module)) {
39
            $this->rollback($module);
40
41
            return;
42
        }
43
44
        foreach (array_reverse($this->laravel['modules']->all()) as $module) {
45
            $this->line('Running for module: <info>' . $module->getName() . '</info>');
46
47
            $this->rollback($module);
48
        }
49
    }
50
51
    /**
52
     * Rollback migration from the specified module.
53
     *
54
     * @param $module
55
     */
56
    public function rollback($module)
57
    {
58
        if (is_string($module)) {
59
            $module = $this->laravel['modules']->findOrFail($module);
60
        }
61
62
        $migrator = new Migrator($module);
63
64
        $database = $this->option('database');
65
66
        if (!empty($database)) {
67
            $migrator->setDatabase($database);
68
        }
69
70
        $migrated = $migrator->rollback();
71
72
        if (count($migrated)) {
73
            foreach ($migrated as $migration) {
74
                $this->line("Rollback: <info>{$migration}</info>");
75
            }
76
77
            return;
78
        }
79
80
        $this->comment('Nothing to rollback.');
81
    }
82
83
    /**
84
     * Get the console command arguments.
85
     *
86
     * @return array
87
     */
88
    protected function getArguments()
89
    {
90
        return array(
91
            array('module', InputArgument::OPTIONAL, 'The name of module will be used.'),
92
        );
93
    }
94
95
    /**
96
     * Get the console command options.
97
     *
98
     * @return array
99
     */
100
    protected function getOptions()
101
    {
102
        return array(
103
            array('database', null, InputOption::VALUE_OPTIONAL, 'The database connection to use.'),
104
            array('force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production.'),
105
            array('pretend', null, InputOption::VALUE_NONE, 'Dump the SQL queries that would be run.'),
106
        );
107
    }
108
}
109