From a366ffd9f245959c6853769ddd85707e8cfbe457 Mon Sep 17 00:00:00 2001 From: Mateusz Bieniek Date: Thu, 16 Jan 2020 13:52:56 +0100 Subject: [PATCH] EZP-31203: Fixed wrong connection being used for database creation when SiteAccess option is used (#2908) * Fixed wrong connection being used for database creation when siteaccess option is used * Moved part of the code to the new getCurrentConnectionName method * Added getStorageConnectionName method to RepositoryConfigurationProvider * Fixed null connection name exception --- .../ApiLoader/RepositoryConfigurationProvider.php | 13 +++++++++++++ .../src/Command/InstallPlatformCommand.php | 12 ++++++++++-- .../src/Resources/config/services.yml | 1 + 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/eZ/Bundle/EzPublishCoreBundle/ApiLoader/RepositoryConfigurationProvider.php b/eZ/Bundle/EzPublishCoreBundle/ApiLoader/RepositoryConfigurationProvider.php index 862dbe37b75..96f056b6e9b 100644 --- a/eZ/Bundle/EzPublishCoreBundle/ApiLoader/RepositoryConfigurationProvider.php +++ b/eZ/Bundle/EzPublishCoreBundle/ApiLoader/RepositoryConfigurationProvider.php @@ -16,6 +16,10 @@ */ class RepositoryConfigurationProvider { + private const REPOSITORY_STORAGE = 'storage'; + private const REPOSITORY_CONNECTION = 'connection'; + private const DEFAULT_CONNECTION_NAME = 'default'; + /** @var \eZ\Publish\Core\MVC\ConfigResolverInterface */ private $configResolver; @@ -51,4 +55,13 @@ public function getRepositoryConfig() return ['alias' => $repositoryAlias] + $this->repositories[$repositoryAlias]; } + + public function getStorageConnectionName(): string + { + $repositoryConfig = $this->getRepositoryConfig(); + + return $repositoryConfig[self::REPOSITORY_STORAGE][self::REPOSITORY_CONNECTION] + ? $repositoryConfig[self::REPOSITORY_STORAGE][self::REPOSITORY_CONNECTION] + : self::DEFAULT_CONNECTION_NAME; + } } diff --git a/eZ/Bundle/PlatformInstallerBundle/src/Command/InstallPlatformCommand.php b/eZ/Bundle/PlatformInstallerBundle/src/Command/InstallPlatformCommand.php index 5a1f1cbff9d..c971b3cbc28 100644 --- a/eZ/Bundle/PlatformInstallerBundle/src/Command/InstallPlatformCommand.php +++ b/eZ/Bundle/PlatformInstallerBundle/src/Command/InstallPlatformCommand.php @@ -9,6 +9,7 @@ namespace EzSystems\PlatformInstallerBundle\Command; use Doctrine\DBAL\Connection; +use eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider; use Psr\Cache\CacheItemPoolInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; @@ -36,6 +37,9 @@ class InstallPlatformCommand extends Command /** @var \EzSystems\PlatformInstallerBundle\Installer\Installer[] */ private $installers = []; + /** @var \eZ\Bundle\EzPublishCoreBundle\ApiLoader\RepositoryConfigurationProvider */ + private $repositoryConfigurationProvider; + const EXIT_GENERAL_DATABASE_ERROR = 4; const EXIT_PARAMETERS_NOT_FOUND = 5; const EXIT_UNKNOWN_INSTALL_TYPE = 6; @@ -45,12 +49,14 @@ public function __construct( Connection $db, array $installers, CacheItemPoolInterface $cachePool, - $environment + $environment, + RepositoryConfigurationProvider $repositoryConfigurationProvider ) { $this->db = $db; $this->installers = $installers; $this->cachePool = $cachePool; $this->environment = $environment; + $this->repositoryConfigurationProvider = $repositoryConfigurationProvider; parent::__construct(); } @@ -127,7 +133,9 @@ private function checkCreateDatabase(OutputInterface $output) ); try { $bufferedOutput = new BufferedOutput(); - $this->executeCommand($bufferedOutput, 'doctrine:database:create --if-not-exists'); + $connectionName = $this->repositoryConfigurationProvider->getStorageConnectionName(); + $command = sprintf('doctrine:database:create --if-not-exists --connection=%s', $connectionName); + $this->executeCommand($bufferedOutput, $command); $output->writeln($bufferedOutput->fetch()); } catch (\RuntimeException $exception) { $this->output->writeln( diff --git a/eZ/Bundle/PlatformInstallerBundle/src/Resources/config/services.yml b/eZ/Bundle/PlatformInstallerBundle/src/Resources/config/services.yml index 0d5e12042f3..e607c46087c 100644 --- a/eZ/Bundle/PlatformInstallerBundle/src/Resources/config/services.yml +++ b/eZ/Bundle/PlatformInstallerBundle/src/Resources/config/services.yml @@ -38,5 +38,6 @@ services: - [] - '@ezpublish.cache_pool' - "%kernel.environment%" + - '@ezpublish.api.repository_configuration_provider' tags: - { name: console.command, command: ezplatform:install }