|
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'); |
|
|
|
|
|
|
47
|
|
|
$this->codeigniter->migration->current(); |
|
|
|
|
|
|
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
|
|
|
|
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.