Skip to content

Commit a759a7b

Browse files
committed
first commit
0 parents  commit a759a7b

13 files changed

+463
-0
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
composer.phar
2+
vendor/
3+
4+
# Commit your application's lock file http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file
5+
# You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file
6+
composer.lock

Command/AntiMattrCommand.php

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 AntiMattr\MongoDB\Migrations\Configuration\AbstractFileConfiguration;
16+
use Symfony\Bundle\FrameworkBundle\Console\Application;
17+
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
18+
use Symfony\Component\DependencyInjection\ContainerInterface;
19+
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
20+
21+
/**
22+
* @author Matthew Fitzgerald <[email protected]>
23+
*/
24+
abstract class AntiMattrCommand extends ContainerAwareCommand
25+
{
26+
public static function configureMigrations(ContainerInterface $container, Configuration $configuration)
27+
{
28+
if (!$configuration->getMigrationsDirectory()) {
29+
$dir = $container->getParameter('doctrine_migrations.dir_name');
30+
if (!file_exists($dir)) {
31+
mkdir($dir, 0777, true);
32+
}
33+
$configuration->setMigrationsDirectory($dir);
34+
} else {
35+
$dir = $configuration->getMigrationsDirectory();
36+
// class Kernel has method getKernelParameters with some of the important path parameters
37+
$pathPlaceholderArray = array('kernel.root_dir', 'kernel.cache_dir', 'kernel.logs_dir');
38+
foreach ($pathPlaceholderArray as $pathPlaceholder) {
39+
if ($container->hasParameter($pathPlaceholder) && preg_match('/\%'.$pathPlaceholder.'\%/', $dir)) {
40+
$dir = str_replace('%'.$pathPlaceholder.'%', $container->getParameter($pathPlaceholder), $dir);
41+
}
42+
}
43+
if (!file_exists($dir)) {
44+
mkdir($dir, 0777, true);
45+
}
46+
$configuration->setMigrationsDirectory($dir);
47+
}
48+
if (!$configuration->getMigrationsNamespace()) {
49+
$configuration->setMigrationsNamespace($container->getParameter('doctrine_migrations.namespace'));
50+
}
51+
if (!$configuration->getName()) {
52+
$configuration->setName($container->getParameter('doctrine_migrations.name'));
53+
}
54+
// For backward compatibility, need use a table from parameters for overwrite the default configuration
55+
if (!$configuration->getMigrationsTableName() || !($configuration instanceof AbstractFileConfiguration)) {
56+
$configuration->setMigrationsTableName($container->getParameter('doctrine_migrations.table_name'));
57+
}
58+
// Migrations is not register from configuration loader
59+
if (!($configuration instanceof AbstractFileConfiguration)) {
60+
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
61+
}
62+
63+
self::injectContainerToMigrations($container, $configuration->getMigrations());
64+
}
65+
66+
/**
67+
* Injects the container to migrations aware of it
68+
*/
69+
private static function injectContainerToMigrations(ContainerInterface $container, array $versions)
70+
{
71+
foreach ($versions as $version) {
72+
$migration = $version->getMigration();
73+
if ($migration instanceof ContainerAwareInterface) {
74+
$migration->setContainer($container);
75+
}
76+
}
77+
}
78+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
18+
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
19+
20+
/**
21+
* @author Matthew Fitzgerald <[email protected]>
22+
*/
23+
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
24+
{
25+
protected function configure()
26+
{
27+
parent::configure();
28+
29+
$this
30+
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
31+
;
32+
}
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('dm'));
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
AntiMattrCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
40+
41+
parent::execute($input, $output);
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
18+
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
19+
20+
/**
21+
* @author Matthew Fitzgerald <[email protected]>
22+
*/
23+
class MigrationsGenerateDoctrineCommand extends GenerateCommand
24+
{
25+
protected function configure()
26+
{
27+
parent::configure();
28+
29+
$this
30+
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
31+
;
32+
}
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('dm'));
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
AntiMattrCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
40+
41+
parent::execute($input, $output);
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
18+
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
19+
20+
/**
21+
* @author Matthew Fitzgerald <[email protected]>
22+
*/
23+
class MigrationsMigrateDoctrineCommand extends MigrateCommand
24+
{
25+
protected function configure()
26+
{
27+
parent::configure();
28+
29+
$this
30+
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
31+
;
32+
}
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('dm'));
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
AntiMattrCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
40+
41+
parent::execute($input, $output);
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
18+
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
19+
20+
/**
21+
* @author Matthew Fitzgerald <[email protected]>
22+
*/
23+
class MigrationsStatusDoctrineCommand extends StatusCommand
24+
{
25+
protected function configure()
26+
{
27+
parent::configure();
28+
29+
$this
30+
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
31+
;
32+
}
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('dm'));
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
AntiMattrCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
40+
41+
parent::execute($input, $output);
42+
}
43+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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 Symfony\Component\Console\Input\InputInterface;
15+
use Symfony\Component\Console\Output\OutputInterface;
16+
use Symfony\Component\Console\Input\InputOption;
17+
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper;
18+
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
19+
20+
/**
21+
* @author Matthew Fitzgerald <[email protected]>
22+
*/
23+
class MigrationsVersionDoctrineCommand extends VersionCommand
24+
{
25+
protected function configure()
26+
{
27+
parent::configure();
28+
29+
$this
30+
->addOption('dm', null, InputOption::VALUE_OPTIONAL, 'The document manager to use for this command.')
31+
;
32+
}
33+
34+
public function execute(InputInterface $input, OutputInterface $output)
35+
{
36+
DoctrineCommandHelper::setApplicationEntityManager($this->getApplication(), $input->getOption('dm'));
37+
38+
$configuration = $this->getMigrationConfiguration($input, $output);
39+
AntiMattrCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);
40+
41+
parent::execute($input, $output);
42+
}
43+
}

DependencyInjection/Configuration.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the AntiMattr MongoDB Migrations Library, 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\DependencyInjection;
13+
14+
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
15+
use Symfony\Component\Config\Definition\ConfigurationInterface;
16+
17+
/**
18+
* @author Matthew Fitzgerald <[email protected]>
19+
*/
20+
class Configuration implements ConfigurationInterface
21+
{
22+
/**
23+
* Generates the configuration tree.
24+
*
25+
* @return \Symfony\Component\Config\Definition\Builder\TreeBuilder The config tree builder
26+
*/
27+
public function getConfigTreeBuilder()
28+
{
29+
$treeBuilder = new TreeBuilder();
30+
$rootNode = $treeBuilder->root('mongodb_migrations', 'array');
31+
32+
$rootNode
33+
->children()
34+
->scalarNode('dir_name')->defaultValue('%kernel.root_dir%/MongoDBMigrations')->cannotBeEmpty()->end()
35+
->scalarNode('namespace')->defaultValue('Application\MongoDBMigrations')->cannotBeEmpty()->end()
36+
->scalarNode('collection_name')->defaultValue('migration_versions')->cannotBeEmpty()->end()
37+
->scalarNode('name')->defaultValue('Application MongoDB Migrations')->end()
38+
->end()
39+
;
40+
41+
return $treeBuilder;
42+
}
43+
}

0 commit comments

Comments
 (0)