1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the AntiMattr MongoDB Migrations Bundle, a library by Matthew Fitzgerald. |
5
|
|
|
* |
6
|
|
|
* (c) 2014 Matthew Fitzgerald |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; |
13
|
|
|
|
14
|
|
|
use AntiMattr\MongoDB\Migrations\Configuration\Configuration; |
15
|
|
|
use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\Console\Application; |
|
|
|
|
17
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
18
|
|
|
use Symfony\Component\DependencyInjection\ContainerAwareInterface; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @author Matthew Fitzgerald <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
final class CommandHelper |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* configureMigrations. |
27
|
|
|
* |
28
|
|
|
* @param ContainerInterface $container |
29
|
|
|
* @param Configuration $configuration |
30
|
|
|
*/ |
31
|
|
|
public static function configureMigrations(ContainerInterface $container, Configuration $configuration) |
32
|
|
|
{ |
33
|
|
|
$dir = $container->getParameter('mongo_db_migrations.dir_name'); |
34
|
|
|
if (!file_exists($dir)) { |
35
|
|
|
mkdir($dir, 0777, true); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
$configuration->setMigrationsCollectionName($container->getParameter('mongo_db_migrations.collection_name')); |
39
|
|
|
$configuration->setMigrationsDatabaseName($container->getParameter('mongo_db_migrations.database_name')); |
40
|
|
|
$configuration->setMigrationsDirectory($dir); |
41
|
|
|
$configuration->setMigrationsNamespace($container->getParameter('mongo_db_migrations.namespace')); |
42
|
|
|
$configuration->setName($container->getParameter('mongo_db_migrations.name')); |
43
|
|
|
$configuration->registerMigrationsFromDirectory($dir); |
44
|
|
|
$configuration->setMigrationsScriptDirectory($container->getParameter('mongo_db_migrations.script_dir_name')); |
45
|
|
|
|
46
|
|
|
self::injectContainerToMigrations($container, $configuration->getMigrations()); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @param Application $application |
51
|
|
|
* @param string $dmName |
52
|
|
|
*/ |
53
|
|
|
public static function setApplicationDocumentManager(Application $application, $dmName) |
54
|
|
|
{ |
55
|
|
|
/* @var $dm \Doctrine\ODM\DocumentManager */ |
56
|
|
|
$alias = sprintf( |
57
|
|
|
'doctrine_mongodb.odm.%s', |
58
|
|
|
$dmName |
59
|
|
|
); |
60
|
|
|
$dm = $application->getKernel()->getContainer()->get($alias); |
61
|
|
|
$helperSet = $application->getHelperSet(); |
62
|
|
|
$helperSet->set(new DocumentManagerHelper($dm), 'dm'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* injectContainerToMigrations. |
67
|
|
|
* |
68
|
|
|
* Injects the container to migrations aware of it. |
69
|
|
|
* |
70
|
|
|
* @param ContainerInterface $container |
71
|
|
|
* @param array $versions |
72
|
|
|
*/ |
73
|
|
|
private static function injectContainerToMigrations(ContainerInterface $container, array $versions) |
74
|
|
|
{ |
75
|
|
|
foreach ($versions as $version) { |
76
|
|
|
$migration = $version->getMigration(); |
77
|
|
|
if ($migration instanceof ContainerAwareInterface) { |
78
|
|
|
$migration->setContainer($container); |
79
|
|
|
} |
80
|
|
|
} |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths