Skip to content

Commit

Permalink
Fix the Doctrine platform recognition (see #1010)
Browse files Browse the repository at this point in the history
Description
-----------

The logic of the `ParametersYamlPass` needs to be run before the `Plugin::addDefaultServerVersion()` method, otherwise the DB connection always fails and our `'server_version' => '5.5'` workaround will always be applied. This breaks the Doctrine platform recognition (see #979).

Commits
-------

bd0c70e Move the ParametersYamlPass logic to the Plugin class
  • Loading branch information
leofeyer committed Nov 25, 2019
1 parent 236e46e commit 1c1a157
Show file tree
Hide file tree
Showing 6 changed files with 332 additions and 375 deletions.
102 changes: 97 additions & 5 deletions manager-bundle/src/ContaoManager/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,29 @@ public function getExtensionConfig($extensionName, array $extensionConfigs, Plug
case 'contao':
return $this->handlePrependLocale($extensionConfigs, $container);

case 'framework':
if (!isset($_SERVER['APP_SECRET'])) {
$container->setParameter('env(APP_SECRET)', $container->getParameter('secret'));
}

return $extensionConfigs;

case 'doctrine':
if (!isset($_SERVER['DATABASE_URL'])) {
$container->setParameter('env(DATABASE_URL)', $this->getDatabaseUrl($container));
}

return $this->addDefaultServerVersion($extensionConfigs, $container);

default:
return $extensionConfigs;
case 'swiftmailer':
if (!isset($_SERVER['MAILER_URL'])) {
$container->setParameter('env(MAILER_URL)', $this->getMailerUrl($container));
}

return $this->checkMailerTransport($extensionConfigs, $container);
}

return $extensionConfigs;
}

/**
Expand Down Expand Up @@ -291,10 +308,8 @@ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuild
$params = array_merge(...$params);
}

$parameterBag = $container->getParameterBag();

foreach ($params as $key => $value) {
$params[$key] = $parameterBag->resolveValue($value);
$params[$key] = $container->resolveEnvPlaceholders($value, true);
}

// If there are no DB credentials yet (install tool), we have to set
Expand All @@ -317,4 +332,81 @@ private function addDefaultServerVersion(array $extensionConfigs, ContainerBuild

return $extensionConfigs;
}

/**
* Changes the mail transport from "mail" to "sendmail".
*
* @return array<string,array<string,array<string,array<string,mixed>>>>
*/
private function checkMailerTransport(array $extensionConfigs, ContainerBuilder $container): array
{
if ('mail' === $container->getParameter('mailer_transport')) {
$container->setParameter('mailer_transport', 'sendmail');
}

return $extensionConfigs;
}

private function getDatabaseUrl(ContainerBuilder $container): string
{
$userPassword = '';

if ($user = $container->getParameter('database_user')) {
$userPassword = $user;

if ($password = $container->getParameter('database_password')) {
$userPassword .= ':'.$password;
}

$userPassword .= '@';
}

$dbName = '';

if ($name = $container->getParameter('database_name')) {
$dbName = '/'.$name;
}

return sprintf(
'mysql://%s%s:%s%s',
$userPassword,
$container->getParameter('database_host'),
$container->getParameter('database_port'),
$dbName
);
}

private function getMailerUrl(ContainerBuilder $container): string
{
if ('sendmail' === $container->getParameter('mailer_transport')) {
return 'sendmail://localhost';
}

$parameters = [];

if ($user = $container->getParameter('mailer_user')) {
$parameters[] = 'username='.rawurlencode($user);

if ($password = $container->getParameter('mailer_password')) {
$parameters[] = 'password='.rawurlencode($password);
}
}

if ($encryption = $container->getParameter('mailer_encryption')) {
$parameters[] = 'encryption='.rawurlencode($encryption);
}

$qs = '';

if (!empty($parameters)) {
$qs = '?'.implode('&', $parameters);
}

return sprintf(
'smtp://%s:%s%s',
rawurlencode($container->getParameter('mailer_host')),
(int) $container->getParameter('mailer_port'),
$qs
);
}
}
2 changes: 0 additions & 2 deletions manager-bundle/src/ContaoManagerBundle.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
namespace Contao\ManagerBundle;

use Contao\ManagerBundle\DependencyInjection\Compiler\ContaoManagerPass;
use Contao\ManagerBundle\DependencyInjection\Compiler\ParametersYamlPass;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\HttpKernel\Bundle\Bundle;
Expand All @@ -28,7 +27,6 @@ public function build(ContainerBuilder $container): void
parent::build($container);

$container->addCompilerPass(new ContaoManagerPass());
$container->addCompilerPass(new ParametersYamlPass());
}

/**
Expand Down
117 changes: 0 additions & 117 deletions manager-bundle/src/DependencyInjection/Compiler/ParametersYamlPass.php

This file was deleted.

0 comments on commit 1c1a157

Please sign in to comment.