-
Notifications
You must be signed in to change notification settings - Fork 3
add dbal related code from DoctrineBundle #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
36 commits
Select commit
Hold shift + click to select a range
99e4572
add dbal config & extension
dmaicher 3a589e9
cleanup config: remove orm stuff
dmaicher dfca364
require doctrine/dbal
dmaicher 193d4ec
move more dbal related things
dmaicher afcbb2c
add data collector + some fixes
dmaicher 300d236
fix data collector
dmaicher 5f7fec1
add ProfilerController
dmaicher 6d75488
add ConnectionRegistry
dmaicher d7d6ce7
use registry
dmaicher 20b3cb2
start adding tests
dmaicher ebe8d49
add some more tests
dmaicher 7356d86
add some more tests
dmaicher c944ac6
adjust composer requirements
dmaicher af74eec
adjust composer requirements
dmaicher 7630931
CS fixes
dmaicher 4f5ec77
add more tests
dmaicher 2c6f5bd
add schema + extension tests
dmaicher 98fb67e
cleanup
dmaicher 4f78716
more cleanup
dmaicher 25dc5ad
address first review comments
dmaicher ded7eb8
add RunSqlDoctrineCommand proxy
dmaicher bd278bf
cs fix
dmaicher cdc3fd4
add 2 more commands + tests
dmaicher ea8b8be
define command services + cleanup
dmaicher ed66ca2
cleanup
dmaicher 1a3d3e6
use correct version of factory from 2.0.x
dmaicher d05284d
fix CS
dmaicher 479e43f
remove unused class
dmaicher fe82cd8
fix registry + add test
dmaicher 4ccb226
drop support for phpunit 7
dmaicher 1c46aa5
fix phpunit 7 compat
dmaicher 4d595a3
fix phpunit warnings
dmaicher 5436c29
fix CS
dmaicher 4df8eea
fix deprecations for doctrine/dbal >= 2.11
dmaicher 8d51194
fix CS
dmaicher a7361d8
fix comments
dmaicher File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,53 @@ | ||
| <?xml version="1.0"?> | ||
| <ruleset> | ||
| <arg name="basepath" value=""/> | ||
| <arg name="extensions" value="php"/> | ||
| <arg name="parallel" value="80"/> | ||
| <arg name="cache" value=".phpcs-cache"/> | ||
| <arg name="colors"/> | ||
|
|
||
| <!-- Ignore warnings, show progress of the run and show sniff names --> | ||
| <arg value="nps"/> | ||
|
|
||
| <file>.</file> | ||
| <exclude-pattern>vendor/*</exclude-pattern> | ||
|
|
||
| <rule ref="Doctrine"> | ||
| <exclude name="SlevomatCodingStandard.Classes.ClassConstantVisibility"/> | ||
| <exclude name="SlevomatCodingStandard.Exceptions.ReferenceThrowableOnly"/> | ||
| <exclude name="SlevomatCodingStandard.Namespaces.ReferenceUsedNamesOnly.ReferenceViaFallbackGlobalName"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.DeclareStrictTypes"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.NullableTypeForNullDefaultValue"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingParameterTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingReturnTypeHint"/> | ||
| <exclude name="SlevomatCodingStandard.ControlStructures.RequireNullCoalesceOperator.NullCoalesceOperatorNotUsed"/> | ||
| <exclude name="SlevomatCodingStandard.Classes.SuperfluousInterfaceNaming.SuperfluousSuffix"/> | ||
| <exclude name="SlevomatCodingStandard.Classes.SuperfluousAbstractClassNaming.SuperfluousPrefix"/> | ||
| </rule> | ||
|
|
||
| <rule ref="PSR1.Classes.ClassDeclaration.MultipleClasses"> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="Squiz.Classes.ClassFileName.NoMatch"> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedProperty"> | ||
| <exclude-pattern>tests/Fixtures/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableParameterTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversablePropertyTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| <rule ref="SlevomatCodingStandard.TypeHints.TypeHintDeclaration.MissingTraversableReturnTypeHintSpecification"> | ||
| <exclude-pattern>src/DependencyInjection/*</exclude-pattern> | ||
| <exclude-pattern>src/Twig/DoctrineDBALExtension.php</exclude-pattern> | ||
| <exclude-pattern>tests/*</exclude-pattern> | ||
| </rule> | ||
| </ruleset> |
This file contains hidden or 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,23 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
|
|
||
| <!-- https://phpunit.de/manual/current/en/appendixes.configuration.html --> | ||
| <phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.1/phpunit.xsd" | ||
| backupGlobals="false" | ||
| colors="true" | ||
| bootstrap="vendor/autoload.php" | ||
| failOnRisky="true" | ||
| > | ||
| <testsuites> | ||
| <testsuite name="Doctrine DBAL Bundle Test Suite"> | ||
| <directory>tests/</directory> | ||
| <exclude>tests/Fixtures</exclude> | ||
| </testsuite> | ||
| </testsuites> | ||
|
|
||
| <filter> | ||
| <whitelist> | ||
| <directory>./src/</directory> | ||
| </whitelist> | ||
| </filter> | ||
| </phpunit> |
This file contains hidden or 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,120 @@ | ||
| <?php | ||
|
|
||
| namespace Doctrine\Bundle\DBALBundle\Command; | ||
|
|
||
| use Doctrine\Bundle\DBALBundle\ConnectionRegistry; | ||
| use Doctrine\DBAL\DriverManager; | ||
| use Exception; | ||
| use InvalidArgumentException; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
|
|
||
| final class CreateDatabaseCommand extends Command | ||
| { | ||
| /** @var ConnectionRegistry */ | ||
| private $registry; | ||
|
|
||
| public function __construct(ConnectionRegistry $registry) | ||
| { | ||
| parent::__construct(); | ||
| $this->registry = $registry; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| protected function configure() | ||
| { | ||
| $this | ||
| ->setName('doctrine:database:create') | ||
| ->setDescription('Creates the configured database') | ||
| ->addOption('shard', null, InputOption::VALUE_REQUIRED, 'The shard connection to use for this command') | ||
| ->addOption('connection', null, InputOption::VALUE_OPTIONAL, 'The connection to use for this command') | ||
| ->addOption('if-not-exists', null, InputOption::VALUE_NONE, 'Don\'t trigger an error, when the database already exists') | ||
| ->setHelp(<<<EOT | ||
| The <info>%command.name%</info> command creates the default connections database: | ||
|
|
||
| <info>php %command.full_name%</info> | ||
|
|
||
| You can also optionally specify the name of a connection to create the database for: | ||
|
|
||
| <info>php %command.full_name% --connection=default</info> | ||
| EOT | ||
| ); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritDoc} | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| $connectionName = $input->getOption('connection'); | ||
| if (empty($connectionName)) { | ||
| $connectionName = $this->registry->getDefaultConnectionName(); | ||
| } | ||
| $connection = $this->registry->getConnection($connectionName); | ||
|
|
||
| $ifNotExists = $input->getOption('if-not-exists'); | ||
|
|
||
| $params = $connection->getParams(); | ||
| if (isset($params['master'])) { | ||
| $params = $params['master']; | ||
| } | ||
|
|
||
| // Cannot inject `shard` option in parent::getDoctrineConnection | ||
| // cause it will try to connect to a non-existing database | ||
| if (isset($params['shards'])) { | ||
| $shards = $params['shards']; | ||
| // Default select global | ||
| $params = array_merge($params, $params['global']); | ||
| unset($params['global']['dbname'], $params['global']['path'], $params['global']['url']); | ||
| if ($input->getOption('shard')) { | ||
| foreach ($shards as $i => $shard) { | ||
| if ($shard['id'] === (int) $input->getOption('shard')) { | ||
| // Select sharded database | ||
| $params = array_merge($params, $shard); | ||
| unset($params['shards'][$i]['dbname'], $params['shards'][$i]['path'], $params['shards'][$i]['url'], $params['id']); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| $hasPath = isset($params['path']); | ||
| $name = $hasPath ? $params['path'] : (isset($params['dbname']) ? $params['dbname'] : false); | ||
| if (! $name) { | ||
| throw new InvalidArgumentException("Connection does not contain a 'path' or 'dbname' parameter and cannot be created."); | ||
| } | ||
| // Need to get rid of _every_ occurrence of dbname from connection configuration and we have already extracted all relevant info from url | ||
| unset($params['dbname'], $params['path'], $params['url']); | ||
|
|
||
| $tmpConnection = DriverManager::getConnection($params); | ||
| $tmpConnection->connect($input->getOption('shard')); | ||
| $shouldNotCreateDatabase = $ifNotExists && in_array($name, $tmpConnection->getSchemaManager()->listDatabases()); | ||
|
|
||
| // Only quote if we don't have a path | ||
| if (! $hasPath) { | ||
| $name = $tmpConnection->getDatabasePlatform()->quoteSingleIdentifier($name); | ||
| } | ||
|
|
||
| $error = false; | ||
| try { | ||
| if ($shouldNotCreateDatabase) { | ||
| $output->writeln(sprintf('<info>Database <comment>%s</comment> for connection named <comment>%s</comment> already exists. Skipped.</info>', $name, $connectionName)); | ||
| } else { | ||
| $tmpConnection->getSchemaManager()->createDatabase($name); | ||
| $output->writeln(sprintf('<info>Created database <comment>%s</comment> for connection named <comment>%s</comment></info>', $name, $connectionName)); | ||
| } | ||
| } catch (Exception $e) { | ||
| $output->writeln(sprintf('<error>Could not create database <comment>%s</comment> for connection named <comment>%s</comment></error>', $name, $connectionName)); | ||
| $output->writeln(sprintf('<error>%s</error>', $e->getMessage())); | ||
| $error = true; | ||
| } | ||
|
|
||
| $tmpConnection->close(); | ||
|
|
||
| return $error ? 1 : 0; | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.