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
|
33 |
|
protected function configure() |
24
|
|
|
{ |
25
|
33 |
|
$this->setName('migrate')->setDescription('Migrates the database'); |
26
|
33 |
|
} |
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
|
9 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
36
|
|
|
{ |
37
|
9 |
|
list($filenames, $migrations) = $this->getMigrations(APPPATH . 'migrations'); |
38
|
|
|
|
39
|
9 |
|
$current = $this->getLatestVersion(); |
40
|
9 |
|
$latest = $migrations[count($migrations) - 1]; |
41
|
|
|
|
42
|
|
|
// Enable migration and change the current version to a latest one |
43
|
9 |
|
$this->toggleMigration(true); |
44
|
9 |
|
$this->changeVersion($current, $latest); |
45
|
|
|
|
46
|
9 |
|
$this->codeigniter->load->library('migration'); |
|
|
|
|
47
|
9 |
|
$this->codeigniter->migration->current(); |
|
|
|
|
48
|
|
|
|
49
|
9 |
|
$this->toggleMigration(); |
50
|
|
|
|
51
|
9 |
|
$messages = $this->getMessages($migrations, $filenames, $current, $latest); |
52
|
|
|
|
53
|
9 |
|
foreach ($messages as $message) { |
54
|
9 |
|
$output->writeln('<info>' . $message . '</info>'); |
55
|
9 |
|
} |
56
|
9 |
|
} |
57
|
|
|
|
58
|
|
|
/** |
59
|
|
|
* Generates messages for successful migrations. |
60
|
|
|
* |
61
|
|
|
* @param array $migrations |
62
|
|
|
* @param string $current |
63
|
|
|
* @param string $latest |
64
|
|
|
* @return boolean |
65
|
|
|
*/ |
66
|
9 |
|
protected function getMessages(array $migrations, array $filenames, $current, $latest) |
67
|
|
|
{ |
68
|
9 |
|
$messages = []; |
69
|
|
|
|
70
|
9 |
|
($current != $latest) || array_push($messages, 'Database is up to date.'); |
71
|
|
|
|
72
|
9 |
|
$count = count($migrations); |
73
|
|
|
|
74
|
9 |
|
for ($counter = 0; $counter < $count; $counter++) { |
75
|
9 |
|
if ($current <= $migrations[$counter]) { |
76
|
9 |
|
$message = $filenames[$counter] . ' has been migrated to the database.'; |
77
|
|
|
|
78
|
9 |
|
array_push($messages, $message); |
79
|
9 |
|
} |
80
|
9 |
|
} |
81
|
|
|
|
82
|
9 |
|
return $messages; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
|
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.