From 73a73667941466bcca23199c144025efc9dfa111 Mon Sep 17 00:00:00 2001 From: smoench Date: Fri, 29 Nov 2019 16:17:53 +0100 Subject: [PATCH 1/2] fix requirements + fix symfony 5 compatibility --- Command/CommandHelper.php | 45 ++++++++++++--------------- Command/MigrationsExecuteCommand.php | 9 ++++-- Command/MigrationsGenerateCommand.php | 9 ++++-- Command/MigrationsMigrateCommand.php | 9 ++++-- Command/MigrationsStatusCommand.php | 9 ++++-- Command/MigrationsVersionCommand.php | 9 ++++-- composer.json | 8 ++--- 7 files changed, 53 insertions(+), 45 deletions(-) diff --git a/Command/CommandHelper.php b/Command/CommandHelper.php index 5ef27a8..979265f 100644 --- a/Command/CommandHelper.php +++ b/Command/CommandHelper.php @@ -12,27 +12,26 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Configuration\Configuration; +use AntiMattr\MongoDB\Migrations\Version; +use Doctrine\Bundle\MongoDBBundle\ManagerRegistry; +use Doctrine\ODM\MongoDB\DocumentManager; use Doctrine\ODM\MongoDB\Tools\Console\Helper\DocumentManagerHelper; +use ErrorException; use Symfony\Bundle\FrameworkBundle\Console\Application; -use Symfony\Component\DependencyInjection\ContainerInterface; use Symfony\Component\DependencyInjection\ContainerAwareInterface; +use Symfony\Component\DependencyInjection\ContainerInterface; /** * @author Matthew Fitzgerald */ final class CommandHelper { - /** - * configureMigrations. - * - * @param ContainerInterface $container - * @param Configuration $configuration - */ - public static function configureMigrations(ContainerInterface $container, Configuration $configuration) + public static function configureMigrations(ContainerInterface $container, Configuration $configuration): void { $dir = $container->getParameter('mongo_db_migrations.dir_name'); - if (!file_exists($dir)) { - mkdir($dir, 0777, true); + if (!is_dir($dir) && !@mkdir($dir, 0777, true) && !is_dir($dir)) { + $error = error_get_last(); + throw new ErrorException(sprintf('Failed to create directory "%s" with message "%s"', $dir, $error['message'])); } $configuration->setMigrationsCollectionName($container->getParameter('mongo_db_migrations.collection_name')); @@ -47,30 +46,26 @@ public static function configureMigrations(ContainerInterface $container, Config } /** - * @param Application $application - * @param string $dmName + * @param string $dmName */ - public static function setApplicationDocumentManager(Application $application, $dmName) + public static function setApplicationDocumentManager(Application $application, $dmName): void { - /* @var $dm \Doctrine\ODM\DocumentManager */ - $alias = sprintf( - 'doctrine_mongodb.odm.%s', - $dmName - ); - $dm = $application->getKernel()->getContainer()->get($alias); + /** @var ManagerRegistry $managerRegistry */ + $managerRegistry = $application->getKernel()->getContainer()->get('doctrine_mongodb'); + + /** @var DocumentManager $dm */ + $dm = $managerRegistry->getManager($dmName); + $helperSet = $application->getHelperSet(); $helperSet->set(new DocumentManagerHelper($dm), 'dm'); } /** - * injectContainerToMigrations. - * - * Injects the container to migrations aware of it. + * @param Version[] $versions * - * @param ContainerInterface $container - * @param array $versions + * Injects the container to migrations aware of it */ - private static function injectContainerToMigrations(ContainerInterface $container, array $versions) + private static function injectContainerToMigrations(ContainerInterface $container, array $versions): void { foreach ($versions as $version) { $migration = $version->getMigration(); diff --git a/Command/MigrationsExecuteCommand.php b/Command/MigrationsExecuteCommand.php index 106ba19..31e2580 100644 --- a/Command/MigrationsExecuteCommand.php +++ b/Command/MigrationsExecuteCommand.php @@ -12,6 +12,7 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Tools\Console\Command\ExecuteCommand; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -33,11 +34,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); + /** @var Application $application */ + $application = $this->getApplication(); + CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm')); $configuration = $this->getMigrationConfiguration($input, $output); - CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration); - parent::execute($input, $output); + return parent::execute($input, $output); } } diff --git a/Command/MigrationsGenerateCommand.php b/Command/MigrationsGenerateCommand.php index 8d7bf78..2218df3 100644 --- a/Command/MigrationsGenerateCommand.php +++ b/Command/MigrationsGenerateCommand.php @@ -12,6 +12,7 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Tools\Console\Command\GenerateCommand; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -33,11 +34,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); + /** @var Application $application */ + $application = $this->getApplication(); + CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm')); $configuration = $this->getMigrationConfiguration($input, $output); - CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration); - parent::execute($input, $output); + return parent::execute($input, $output); } } diff --git a/Command/MigrationsMigrateCommand.php b/Command/MigrationsMigrateCommand.php index 66f57db..73a2ada 100644 --- a/Command/MigrationsMigrateCommand.php +++ b/Command/MigrationsMigrateCommand.php @@ -12,6 +12,7 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Tools\Console\Command\MigrateCommand; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -33,11 +34,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); + /** @var Application $application */ + $application = $this->getApplication(); + CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm')); $configuration = $this->getMigrationConfiguration($input, $output); - CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration); - parent::execute($input, $output); + return parent::execute($input, $output); } } diff --git a/Command/MigrationsStatusCommand.php b/Command/MigrationsStatusCommand.php index 67d69fc..226a849 100644 --- a/Command/MigrationsStatusCommand.php +++ b/Command/MigrationsStatusCommand.php @@ -12,6 +12,7 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Tools\Console\Command\StatusCommand; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -33,11 +34,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); + /** @var Application $application */ + $application = $this->getApplication(); + CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm')); $configuration = $this->getMigrationConfiguration($input, $output); - CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration); - parent::execute($input, $output); + return parent::execute($input, $output); } } diff --git a/Command/MigrationsVersionCommand.php b/Command/MigrationsVersionCommand.php index ff87d0a..42d262f 100644 --- a/Command/MigrationsVersionCommand.php +++ b/Command/MigrationsVersionCommand.php @@ -12,6 +12,7 @@ namespace AntiMattr\Bundle\MongoDBMigrationsBundle\Command; use AntiMattr\MongoDB\Migrations\Tools\Console\Command\VersionCommand; +use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; @@ -33,11 +34,13 @@ protected function configure() public function execute(InputInterface $input, OutputInterface $output) { - CommandHelper::setApplicationDocumentManager($this->getApplication(), $input->getOption('dm')); + /** @var Application $application */ + $application = $this->getApplication(); + CommandHelper::setApplicationDocumentManager($application, $input->getOption('dm')); $configuration = $this->getMigrationConfiguration($input, $output); - CommandHelper::configureMigrations($this->getApplication()->getKernel()->getContainer(), $configuration); + CommandHelper::configureMigrations($application->getKernel()->getContainer(), $configuration); - parent::execute($input, $output); + return parent::execute($input, $output); } } diff --git a/composer.json b/composer.json index a7b3a67..c5b32b1 100644 --- a/composer.json +++ b/composer.json @@ -13,12 +13,10 @@ }, "require": { "php": "^7.1", - "symfony/dependency-injection": "^3.4 || ^4.0 || ^5.0", - "symfony/http-kernel": "^3.4 || ^4.0 || ^5.0", - "symfony/console": "^3.4 || ^4.0 || ^5.0", - "symfony/config": "^3.4 || ^4.0 || ^5.0", "doesntmattr/mongodb-migrations": "^2.0", - "doctrine/mongodb-odm": "^1.0 || ^2.0" + "doctrine/mongodb-odm-bundle": "^3.0 || ^4.0", + "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0", + "symfony/console": "^3.4 || ^4.0 || ^5.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.0", From 8f8cc04a45cd22198f290bacccb3c16a5d2e9078 Mon Sep 17 00:00:00 2001 From: Catalin Ciobanu Date: Sat, 21 Mar 2020 21:55:23 +0200 Subject: [PATCH 2/2] Release 3.0 --- .scrutinizer.yml | 5 +++++ .travis.yml | 3 ++- README.md | 4 ++-- composer.json | 4 ++-- phpunit.xml.dist | 6 +----- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 1429c71..fcfaf9d 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -1,3 +1,8 @@ tools: external_code_coverage: timeout: 720 + +build: + environment: + php: + version: '7.4' diff --git a/.travis.yml b/.travis.yml index 2ccb8c4..9bfe407 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,9 +11,10 @@ matrix: - php: 7.1 - php: 7.2 - php: 7.3 + - php: 7.4 # Test with the lowest dependencies - - php: 7.3 + - php: 7.4 env: COMPOSER_FLAGS="--prefer-stable --prefer-lowest --prefer-dist" before_script: diff --git a/README.md b/README.md index 1466e24..a4c027a 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The original authors are @rcatlin and @matthewfitz ## PHP Version Support -If you require php 5.6 support use version `^1.0`. Version `^2.0` requires at least php 7.1. The `1.x` releases will only receive bug fixes. +If you require php 5.6 support use version `^1.0`. Version `^3.0` requires at least php 7.1. The `1.x` releases will only receive bug fixes. ## Installation @@ -25,7 +25,7 @@ Install with composer: composer require "doesntmattr/mongodb-migrations-bundle=^1.0" # For php 7.1 -composer require "doesntmattr/mongodb-migrations-bundle=^2.0" +composer require "doesntmattr/mongodb-migrations-bundle=^3.0" ``` then enable the bundle in `AppKernel.php` by including the following: diff --git a/composer.json b/composer.json index c5b32b1..b725f03 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ }, "require": { "php": "^7.1", - "doesntmattr/mongodb-migrations": "^2.0", + "doesntmattr/mongodb-migrations": "^3.0", "doctrine/mongodb-odm-bundle": "^3.0 || ^4.0", "symfony/framework-bundle": "^3.4 || ^4.0 || ^5.0", "symfony/console": "^3.4 || ^4.0 || ^5.0" @@ -35,7 +35,7 @@ }, "extra": { "branch-alias": { - "dev-master": "2.0.x-dev" + "dev-master": "3.0.x-dev" } } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 4916cde..011b4b1 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -12,11 +12,7 @@ DependencyInjection Command - MongoDBMigrationsBundle.php + MongoDBMigrationsBundle.php - - vendor - Tests -