Skip to content

Commit

Permalink
Updating DoctrineMigrationsBundle for Doctrine Migrations 2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jwage committed Jun 4, 2018
1 parent 04109e6 commit e5079eb
Show file tree
Hide file tree
Showing 13 changed files with 121 additions and 67 deletions.
10 changes: 7 additions & 3 deletions Command/DoctrineCommand.php
Expand Up @@ -4,8 +4,8 @@
namespace Doctrine\Bundle\MigrationsBundle\Command;

use Doctrine\Bundle\DoctrineBundle\Command\DoctrineCommand as BaseCommand;
use Doctrine\DBAL\Migrations\Configuration\AbstractFileConfiguration;
use Doctrine\DBAL\Migrations\Configuration\Configuration;
use Doctrine\Migrations\Configuration\AbstractFileConfiguration;
use Doctrine\Migrations\Configuration\Configuration;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
Expand Down Expand Up @@ -53,7 +53,11 @@ public static function configureMigrations(ContainerInterface $container, Config
}
// Migrations is not register from configuration loader
if (!($configuration instanceof AbstractFileConfiguration)) {
$configuration->registerMigrationsFromDirectory($configuration->getMigrationsDirectory());
$migrationsDirectory = $configuration->getMigrationsDirectory();

if ($migrationsDirectory !== null) {
$configuration->registerMigrationsFromDirectory($migrationsDirectory);
}
}

if (method_exists($configuration, 'getCustomTemplate') && !$configuration->getCustomTemplate()) {
Expand Down
8 changes: 4 additions & 4 deletions Command/MigrationsDiffDoctrineCommand.php
Expand Up @@ -3,7 +3,7 @@

namespace Doctrine\Bundle\MigrationsBundle\Command;

use Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand;
use Doctrine\Migrations\Tools\Console\Command\DiffCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsDiffDoctrineCommand extends DiffCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,13 +29,13 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
parent::initialize($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsExecuteDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\ExecuteCommand;
use Doctrine\Migrations\Tools\Console\Command\ExecuteCommand;

/**
* Command for executing single migrations up or down manually.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsExecuteDoctrineCommand extends ExecuteCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsGenerateDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\GenerateCommand;
use Doctrine\Migrations\Tools\Console\Command\GenerateCommand;

/**
* Command for generating new blank migration classes
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsGenerateDoctrineCommand extends GenerateCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsLatestDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\LatestCommand;
use Doctrine\Migrations\Tools\Console\Command\LatestCommand;

/**
* Command for outputting the latest version number.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsLatestDoctrineCommand extends LatestCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsMigrateDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\MigrateCommand;
use Doctrine\Migrations\Tools\Console\Command\MigrateCommand;

/**
* Command for executing a migration to a specified version or the latest available version.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsMigrateDoctrineCommand extends MigrateCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

return parent::execute($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsStatusDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\StatusCommand;
use Doctrine\Migrations\Tools\Console\Command\StatusCommand;

/**
* Command to view the status of a set of migrations.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsStatusDoctrineCommand extends StatusCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

return parent::execute($input, $output);
}
}
21 changes: 13 additions & 8 deletions Command/MigrationsVersionDoctrineCommand.php
Expand Up @@ -7,7 +7,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Input\InputOption;
use Doctrine\DBAL\Migrations\Tools\Console\Command\VersionCommand;
use Doctrine\Migrations\Tools\Console\Command\VersionCommand;

/**
* Command for manually adding and deleting migration versions from the version table.
Expand All @@ -17,7 +17,7 @@
*/
class MigrationsVersionDoctrineCommand extends VersionCommand
{
protected function configure()
protected function configure() : void
{
parent::configure();

Expand All @@ -29,18 +29,23 @@ protected function configure()
;
}

public function execute(InputInterface $input, OutputInterface $output)
public function initialize(InputInterface $input, OutputInterface $output) : void
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

Helper\DoctrineCommandHelper::setApplicationHelper($this->getApplication(), $input);

$configuration = $this->getMigrationConfiguration($input, $output);
DoctrineCommand::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration);

parent::initialize($input, $output);
}

public function execute(InputInterface $input, OutputInterface $output) : ?int
{
// EM and DB options cannot be set at same time
if (null !== $input->getOption('em') && null !== $input->getOption('db')) {
throw new InvalidArgumentException('Cannot set both "em" and "db" for command execution.');
}

return parent::execute($input, $output);
}
}
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Expand Up @@ -51,7 +51,7 @@ public function getConfigTreeBuilder()
->validate()
->ifString()
->then(function ($v) {
return constant('Doctrine\DBAL\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_'.strtoupper($v));
return constant('Doctrine\Migrations\Configuration\Configuration::VERSIONS_ORGANIZATION_'.strtoupper($v));
})
->end()
->end()
Expand All @@ -71,7 +71,7 @@ private function getOrganizeMigrationsModes()
{
$constPrefix = 'VERSIONS_ORGANIZATION_';
$prefixLen = strlen($constPrefix);
$refClass = new \ReflectionClass('Doctrine\DBAL\Migrations\Configuration\Configuration');
$refClass = new \ReflectionClass('Doctrine\Migrations\Configuration\Configuration');
$constsArray = $refClass->getConstants();
$namesArray = array();

Expand Down
10 changes: 5 additions & 5 deletions Resources/doc/index.rst
Expand Up @@ -20,7 +20,7 @@ First, install the bundle with composer:

.. code-block:: bash
$ composer require doctrine/doctrine-migrations-bundle "^1.0"
$ composer require doctrine/doctrine-migrations-bundle "^2.0"
If everything worked, the ``DoctrineMigrationsBundle`` can now be found
at ``vendor/doctrine/doctrine-migrations-bundle``.
Expand Down Expand Up @@ -116,17 +116,17 @@ like the following::

namespace Application\Migrations;

use Doctrine\DBAL\Migrations\AbstractMigration,
Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;

class Version20100621140655 extends AbstractMigration
{
public function up(Schema $schema)
public function up(Schema $schema) : void
{

}

public function down(Schema $schema)
public function down(Schema $schema) : void
{

}
Expand Down

0 comments on commit e5079eb

Please sign in to comment.