Completed
Pull Request — master (#1)
by Rougin
02:21
created

MigrateCommand::execute()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 33
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
dl 0
loc 33
ccs 0
cts 20
cp 0
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 18
nc 4
nop 2
crap 20
1
<?php
2
3
namespace Rougin\Refinery\Commands;
4
5
use Symfony\Component\Console\Input\InputInterface;
6
use Symfony\Component\Console\Output\OutputInterface;
7
8
/**
9
 * Migrate Command
10
 *
11
 * Migrates the list of migrations found in "application/migrations" directory.
12
 *
13
 * @package Refinery
14
 * @author  Rougin Royce Gutib <[email protected]>
15
 */
16
class MigrateCommand extends AbstractCommand
17
{
18
    /**
19
     * Sets the configurations of the specified command.
20
     *
21
     * @return void
22
     */
23 3
    protected function configure()
24
    {
25 3
        $this->setName('migrate')->setDescription('Migrates the database');
26 3
    }
27
28
    /**
29
     * Executes the command.
30
     *
31
     * @param  \Symfony\Component\Console\Input\InputInterface   $input
32
     * @param  \Symfony\Component\Console\Output\OutputInterface $output
33
     * @return object|\Symfony\Component\Console\Output\OutputInterface
34
     */
35
    protected function execute(InputInterface $input, OutputInterface $output)
36
    {
37
        list($filenames, $migrations) = $this->getMigrations(APPPATH . 'migrations');
38
39
        $current = $this->getLatestVersion();
40
        $latest  = $migrations[count($migrations) - 1];
41
42
        // Enable migration and change the current version to a latest one
43
        $this->toggleMigration(true);
44
        $this->changeVersion($current, $latest);
45
46
        $this->codeigniter->load->library('migration');
0 ignored issues
show
Bug introduced by
The property load does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
47
        $this->codeigniter->migration->current();
0 ignored issues
show
Bug introduced by
The property migration does not seem to exist in CI_Controller.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
48
49
        $this->toggleMigration();
50
51
        // Show messages of migrated files
52
        if ($current != $latest) {
53
            $count = count($migrations);
54
55
            for ($counter = 0; $counter < $count; $counter++) {
56
                if ($current >= $migrations[$counter]) {
57
                    continue;
58
                }
59
60
                $message = $filenames[$counter] . ' has been migrated to the database.';
61
62
                $output->writeln('<info>' . $message . '</info>');
63
            }
64
        } else {
65
            $output->writeln('<info>Database is up to date.</info>');
66
        }
67
    }
68
}
69