Skip to content

Commit

Permalink
Set the server_version if there is no database connection (fixes cont…
Browse files Browse the repository at this point in the history
  • Loading branch information
leofeyer committed May 30, 2017
1 parent 98d617a commit 06f1f29
Showing 1 changed file with 47 additions and 1 deletion.
48 changes: 47 additions & 1 deletion src/ContaoManager/Plugin.php
Expand Up @@ -13,7 +13,11 @@
use Contao\ManagerPlugin\Bundle\BundlePluginInterface;
use Contao\ManagerPlugin\Bundle\Parser\ParserInterface;
use Contao\ManagerPlugin\Config\ConfigPluginInterface;
use Contao\ManagerPlugin\Config\ContainerBuilder as PluginContainerBuilder;
use Contao\ManagerPlugin\Config\ExtensionPluginInterface;
use Contao\ManagerPlugin\Routing\RoutingPluginInterface;
use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\DriverManager;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Config\Loader\LoaderResolverInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
Expand All @@ -27,7 +31,7 @@
*
* @author Andreas Schempp <https://github.com/aschempp>
*/
class Plugin implements BundlePluginInterface, ConfigPluginInterface, RoutingPluginInterface
class Plugin implements BundlePluginInterface, ConfigPluginInterface, RoutingPluginInterface, ExtensionPluginInterface
{
/**
* @var string|null
Expand Down Expand Up @@ -128,6 +132,48 @@ function (RouteCollection $carry, RouteCollection $item) {
return $collection;
}

/**
* {@inheritdoc}
*/
public function getExtensionConfig($extensionName, array $extensionConfigs, PluginContainerBuilder $container)
{
if ('doctrine' !== $extensionName) {
return $extensionConfigs;
}

$params = [];

foreach ($extensionConfigs as $extensionConfig) {
if (isset($extensionConfig['dbal']['connections']['default'])) {
$params = array_merge($params, $extensionConfig['dbal']['connections']['default']);
}
}

$parameterBag = $container->getParameterBag();

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

try {
$connection = DriverManager::getConnection($params);
$connection->connect();
$connection->close();
} catch (ConnectionException $e) {
$extensionConfigs[] = [
'dbal' => [
'connections' => [
'default' => [
'server_version' => '5.1',
],
],
],
];
}

return $extensionConfigs;
}

/**
* Sets path to enable autoloading of legacy Contao modules.
*
Expand Down

0 comments on commit 06f1f29

Please sign in to comment.