1
- <?php namespace Mitch \LaravelDoctrine \Console ;
1
+ <?php namespace Mitch \LaravelDoctrine \Console ;
2
2
3
3
use Illuminate \Console \Command ;
4
4
use Doctrine \ORM \Tools \SchemaTool ;
5
- use Doctrine \ORM \ Mapping \ ClassMetadataFactory ;
5
+ use Doctrine \Common \ Persistence \ ManagerRegistry ;
6
6
use Symfony \Component \Console \Input \InputOption ;
7
7
8
8
class SchemaUpdateCommand extends Command
@@ -29,18 +29,18 @@ class SchemaUpdateCommand extends Command
29
29
private $ tool ;
30
30
31
31
/**
32
- * The class metadata factory
33
- *
34
- * @var \Doctrine\ORM\Tools\SchemaTool
35
- */
36
- private $ metadata ;
32
+ * The ManagerRegistry
33
+ *
34
+ * @var \Doctrine\Common\Persistence\ManagerRegistry
35
+ */
36
+ private $ registry ;
37
37
38
- public function __construct (SchemaTool $ tool , ClassMetadataFactory $ metadata )
38
+ public function __construct (SchemaTool $ tool , ManagerRegistry $ registry )
39
39
{
40
40
parent ::__construct ();
41
41
42
42
$ this ->tool = $ tool ;
43
- $ this ->metadata = $ metadata ;
43
+ $ this ->registry = $ registry ;
44
44
}
45
45
46
46
/**
@@ -52,18 +52,21 @@ public function fire()
52
52
{
53
53
$ this ->info ('Checking if database needs updating.... ' );
54
54
$ clean = $ this ->option ('clean ' );
55
- $ sql = $ this ->tool ->getUpdateSchemaSql ($ this ->metadata ->getAllMetadata (), $ clean );
56
- if (empty ($ sql )) {
57
- $ this ->info ('No updates found. ' );
58
- return ;
59
- }
60
- if ($ this ->option ('sql ' )) {
61
- $ this ->info ('Outputting update query: ' );
62
- $ this ->info (implode ('; ' . PHP_EOL , $ sql ));
63
- } else {
64
- $ this ->info ('Updating database schema.... ' );
65
- $ this ->tool ->updateSchema ($ this ->metadata ->getAllMetadata ());
66
- $ this ->info ('Schema has been updated! ' );
55
+ foreach ($ this ->registry ->getManagerNames () as $ key => $ value ) {
56
+ $ manager = $ this ->registry ->getManager ($ key );
57
+ $ sql = $ this ->tool ->getUpdateSchemaSql ($ manager ->getMetadataFactory ()->getAllMetadata (), $ clean );
58
+ if (empty ($ sql )) {
59
+ $ this ->info ('No updates found. ' );
60
+ continue ;
61
+ }
62
+ if ($ this ->option ('sql ' )) {
63
+ $ this ->info ('Outputting update query: ' );
64
+ $ this ->info (implode ('; ' . PHP_EOL , $ sql ));
65
+ } else {
66
+ $ this ->info ('Updating database schema.... ' );
67
+ $ this ->tool ->updateSchema ($ this ->metadata ->getAllMetadata ());
68
+ $ this ->info ('Schema has been updated! ' );
69
+ }
67
70
}
68
71
}
69
72
@@ -75,4 +78,3 @@ protected function getOptions()
75
78
];
76
79
}
77
80
}
78
-
0 commit comments