Skip to content
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

EZP-31203: Fixed wrong connection being used for database creation when SiteAccess option is used #2908

Merged
merged 4 commits into from
Jan 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }