Skip to content

Commit

Permalink
EZP-31203: Fixed wrong connection being used for database creation wh…
Browse files Browse the repository at this point in the history
…en 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
  • Loading branch information
mateuszbieniek authored and lserwatka committed Jan 16, 2020
1 parent b4ca1db commit a366ffd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}

Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,6 @@ services:
- []
- '@ezpublish.cache_pool'
- "%kernel.environment%"
- '@ezpublish.api.repository_configuration_provider'
tags:
- { name: console.command, command: ezplatform:install }

0 comments on commit a366ffd

Please sign in to comment.