Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from doctrine/2.0
Updating DoctrineMigrationsBundle for Doctrine Migrations 2.0
- Loading branch information
Showing
25 changed files
with
5,361 additions
and
233 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
composer.lock | ||
/vendor/ | ||
/.phpcs-cache | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
build: | ||
nodes: | ||
analysis: | ||
environment: | ||
php: | ||
version: 7.1 | ||
cache: | ||
disabled: false | ||
directories: | ||
- ~/.composer/cache | ||
project_setup: | ||
override: true | ||
tests: | ||
override: | ||
- php-scrutinizer-run | ||
- phpcs-run | ||
dependencies: | ||
override: | ||
- composer install --ignore-platform-reqs --no-interaction | ||
|
||
tools: | ||
external_code_coverage: | ||
timeout: 600 | ||
|
||
build_failure_conditions: | ||
- 'elements.rating(<= C).new.exists' # No new classes/methods with a rating of C or worse allowed | ||
- 'issues.label("coding-style").new.exists' # No new coding style issues allowed | ||
- 'issues.severity(>= MAJOR).new.exists' # New issues of major or higher severity | ||
- 'project.metric_change("scrutinizer.test_coverage", < 0)' # Code Coverage decreased from previous inspection | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\Bundle\MigrationsBundle\Command\Helper; | ||
|
||
use Doctrine\Bundle\DoctrineBundle\Command\Proxy\DoctrineCommandHelper as BaseDoctrineCommandHelper; | ||
use Doctrine\Bundle\DoctrineBundle\Registry; | ||
use Doctrine\DBAL\Sharding\PoolingShardConnection; | ||
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper; | ||
use LogicException; | ||
use Symfony\Bundle\FrameworkBundle\Console\Application; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use function count; | ||
use function sprintf; | ||
|
||
/** | ||
* Provides some helper and convenience methods to configure doctrine commands in the context of bundles | ||
* and multiple connections/entity managers. | ||
* | ||
* @author Guilherme Blanco <guilhermeblanco@hotmail.com> | ||
*/ | ||
abstract class DoctrineCommandHelper extends BaseDoctrineCommandHelper | ||
{ | ||
public static function setApplicationHelper(Application $application, InputInterface $input) | ||
public static function setApplicationHelper(Application $application, InputInterface $input) : void | ||
{ | ||
$container = $application->getKernel()->getContainer(); | ||
$doctrine = $container->get('doctrine'); | ||
|
||
/** @var Registry $doctrine */ | ||
$doctrine = $container->get('doctrine'); | ||
|
||
$managerNames = $doctrine->getManagerNames(); | ||
|
||
if ($input->getOption('db') || empty($managerNames)) { | ||
if ($input->getOption('db') !== null || count($managerNames) === 0) { | ||
self::setApplicationConnection($application, $input->getOption('db')); | ||
} else { | ||
self::setApplicationEntityManager($application, $input->getOption('em')); | ||
} | ||
|
||
if ($input->getOption('shard')) { | ||
$connection = $application->getHelperSet()->get('db')->getConnection(); | ||
if (!$connection instanceof PoolingShardConnection) { | ||
if (empty($managerNames)) { | ||
throw new \LogicException(sprintf("Connection '%s' must implement shards configuration.", $input->getOption('db'))); | ||
} else { | ||
throw new \LogicException(sprintf("Connection of EntityManager '%s' must implement shards configuration.", $input->getOption('em'))); | ||
} | ||
if ($input->getOption('shard') === null) { | ||
return; | ||
} | ||
|
||
/** @var ConnectionHelper $dbHelper */ | ||
$dbHelper = $application->getHelperSet()->get('db'); | ||
|
||
$connection = $dbHelper->getConnection(); | ||
|
||
if (! $connection instanceof PoolingShardConnection) { | ||
if (count($managerNames) === 0) { | ||
throw new LogicException(sprintf( | ||
"Connection '%s' must implement shards configuration.", | ||
$input->getOption('db') | ||
)); | ||
} | ||
|
||
$connection->connect($input->getOption('shard')); | ||
throw new LogicException(sprintf( | ||
"Connection of EntityManager '%s' must implement shards configuration.", | ||
$input->getOption('em') | ||
)); | ||
} | ||
|
||
$connection->connect($input->getOption('shard')); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.