|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Reddogs (https://github.com/reddogs-at) |
|
4
|
|
|
* |
|
5
|
|
|
* @see https://github.com/reddogs-at/reddogs-doctrine-migrations for the canonical source repository |
|
6
|
|
|
* @license https://github.com/reddogs-at/reddogs-doctrine-migrations/blob/master/LICENSE MIT License |
|
7
|
|
|
*/ |
|
8
|
|
|
namespace Reddogs\Doctrine\Migrations; |
|
9
|
|
|
|
|
10
|
|
|
use Doctrine\DBAL\Migrations\OutputWriter; |
|
11
|
|
|
use Zend\Console\Adapter\AdapterInterface; |
|
12
|
|
|
use ZF\Console\Route; |
|
13
|
|
|
|
|
14
|
|
|
class MigrateAllCommand |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* Configurations |
|
19
|
|
|
* |
|
20
|
|
|
* @var array |
|
21
|
|
|
*/ |
|
22
|
|
|
private $configurations; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* Migrations |
|
26
|
|
|
* |
|
27
|
|
|
* @var array |
|
28
|
|
|
*/ |
|
29
|
|
|
private $migrations; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Constructor |
|
33
|
|
|
* |
|
34
|
|
|
* @param array $configurations |
|
35
|
|
|
* @param array $migrations |
|
36
|
|
|
*/ |
|
37
|
|
|
public function __construct(array $configurations, array $migrations) |
|
38
|
|
|
{ |
|
39
|
|
|
$this->configurations = $configurations; |
|
40
|
|
|
$this->migrations = $migrations; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Get configurations |
|
45
|
|
|
* |
|
46
|
|
|
* return array |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getConfigurations() |
|
49
|
|
|
{ |
|
50
|
|
|
return $this->configurations; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get migrations |
|
55
|
|
|
* |
|
56
|
|
|
* @return array |
|
57
|
|
|
*/ |
|
58
|
|
|
public function getMigrations() |
|
59
|
|
|
{ |
|
60
|
|
|
return $this->migrations; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
/** |
|
64
|
|
|
* Invoke |
|
65
|
|
|
* |
|
66
|
|
|
* @param Route $route |
|
67
|
|
|
* @param AdapterInterface $console |
|
68
|
|
|
*/ |
|
69
|
|
|
public function __invoke(Route $route, AdapterInterface $console) |
|
70
|
|
|
{ |
|
71
|
|
|
$migrations = $this->getMigrations(); |
|
72
|
|
|
foreach($this->getConfigurations() as $key => $configuration) { |
|
73
|
|
|
$configuration->createMigrationTable(); |
|
74
|
|
|
$outputWriter = new OutputWriter(function($message) use ($console) { |
|
75
|
|
|
return $console->writeLine($message); |
|
76
|
|
|
}); |
|
77
|
|
|
$configuration->setOutputWriter($outputWriter); |
|
78
|
|
|
$result = $migrations[$key]->migrate(); |
|
79
|
|
|
if (empty($result)) { |
|
80
|
|
|
$console->writeLine(sprintf('module \'%1$s\': no migrations to execute', $key)); |
|
81
|
|
|
} |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
} |