From 67c7b188cdb3e056bdce582da2fd5360b6c30c9a Mon Sep 17 00:00:00 2001 From: Leo Feyer Date: Thu, 3 Dec 2020 08:42:38 +0100 Subject: [PATCH] Backport the doctrine-cache-bundle changes (see #2534) Description ----------- Backports the changes from #1916 to Contao 4.9 to make it compatible with PHP 8 (see #2263). Commits ------- ba9d21f1 Backport the doctrine-cache-bundle changes d1103e9d CS --- composer.json | 1 - core-bundle/composer.json | 1 - core-bundle/src/ContaoManager/Plugin.php | 2 -- .../tests/ContaoManager/PluginTest.php | 2 -- manager-bundle/composer.json | 2 +- manager-bundle/src/ContaoManager/Plugin.php | 2 -- .../src/Resources/skeleton/config/config.yml | 33 +++++++------------ .../Resources/skeleton/config/services.yml | 10 ++++++ .../tests/ContaoManager/PluginTest.php | 29 +++++++--------- 9 files changed, 35 insertions(+), 47 deletions(-) create mode 100644 manager-bundle/src/Resources/skeleton/config/services.yml diff --git a/composer.json b/composer.json index 0fa2f195bfa..20f15740321 100644 --- a/composer.json +++ b/composer.json @@ -49,7 +49,6 @@ "contao/manager-plugin": "^2.6.2", "doctrine/dbal": "^2.10", "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/doctrine-cache-bundle": "^1.3.1", "doctrine/orm": "^2.6.3", "dragonmantank/cron-expression": "^2.3", "friendsofsymfony/http-cache": "^2.6", diff --git a/core-bundle/composer.json b/core-bundle/composer.json index 2907dfd0fd2..9c2443f1303 100644 --- a/core-bundle/composer.json +++ b/core-bundle/composer.json @@ -48,7 +48,6 @@ "contao/imagine-svg": "^0.2.3 || ^1.0", "doctrine/dbal": "^2.10", "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/doctrine-cache-bundle": "^1.3.1", "doctrine/orm": "^2.6.3", "dragonmantank/cron-expression": "^2.3", "friendsofsymfony/http-cache": "^2.6", diff --git a/core-bundle/src/ContaoManager/Plugin.php b/core-bundle/src/ContaoManager/Plugin.php index 83ca8cdade5..2549706a02d 100644 --- a/core-bundle/src/ContaoManager/Plugin.php +++ b/core-bundle/src/ContaoManager/Plugin.php @@ -18,7 +18,6 @@ use Contao\ManagerPlugin\Bundle\Parser\ParserInterface; use Contao\ManagerPlugin\Routing\RoutingPluginInterface; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle; use Knp\Bundle\MenuBundle\KnpMenuBundle; use Knp\Bundle\TimeBundle\KnpTimeBundle; use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle; @@ -59,7 +58,6 @@ public function getBundles(ParserInterface $parser): array MonologBundle::class, SwiftmailerBundle::class, DoctrineBundle::class, - DoctrineCacheBundle::class, KnpMenuBundle::class, KnpTimeBundle::class, LexikMaintenanceBundle::class, diff --git a/core-bundle/tests/ContaoManager/PluginTest.php b/core-bundle/tests/ContaoManager/PluginTest.php index e0fd8f3c0bd..62713b0eda9 100644 --- a/core-bundle/tests/ContaoManager/PluginTest.php +++ b/core-bundle/tests/ContaoManager/PluginTest.php @@ -17,7 +17,6 @@ use Contao\ManagerPlugin\Bundle\Config\BundleConfig; use Contao\ManagerPlugin\Bundle\Parser\DelegatingParser; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle; use Knp\Bundle\MenuBundle\KnpMenuBundle; use Knp\Bundle\TimeBundle\KnpTimeBundle; use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle; @@ -76,7 +75,6 @@ public function testReturnsTheBundles(): void $this->assertSame( [ DoctrineBundle::class, - DoctrineCacheBundle::class, KnpMenuBundle::class, KnpTimeBundle::class, LexikMaintenanceBundle::class, diff --git a/manager-bundle/composer.json b/manager-bundle/composer.json index 593f8f4bd66..39f87814076 100644 --- a/manager-bundle/composer.json +++ b/manager-bundle/composer.json @@ -22,13 +22,13 @@ "contao/manager-plugin": "^2.4", "doctrine/dbal": "^2.10", "doctrine/doctrine-bundle": "^1.8 || ^2.0", - "doctrine/doctrine-cache-bundle": "^1.3.1", "friendsofsymfony/http-cache": "^2.6", "friendsofsymfony/http-cache-bundle": "^2.6", "lexik/maintenance-bundle": "^2.1.3", "nelmio/cors-bundle": "^1.5.3 || ^2.0.1", "nelmio/security-bundle": "^2.2", "ocramius/proxy-manager": "^2.1", + "symfony/cache": "4.4.*", "symfony/config": "4.4.*", "symfony/console": "4.4.*", "symfony/debug": "4.4.*", diff --git a/manager-bundle/src/ContaoManager/Plugin.php b/manager-bundle/src/ContaoManager/Plugin.php index 7e7e06af3cc..c570ea48656 100644 --- a/manager-bundle/src/ContaoManager/Plugin.php +++ b/manager-bundle/src/ContaoManager/Plugin.php @@ -31,7 +31,6 @@ use Contao\ManagerPlugin\Dependency\DependentPluginInterface; use Contao\ManagerPlugin\Routing\RoutingPluginInterface; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Exception\DriverException; use FOS\HttpCacheBundle\FOSHttpCacheBundle; @@ -96,7 +95,6 @@ public function getBundles(ParserInterface $parser) BundleConfig::create(MonologBundle::class), BundleConfig::create(SwiftmailerBundle::class), BundleConfig::create(DoctrineBundle::class), - BundleConfig::create(DoctrineCacheBundle::class), BundleConfig::create(LexikMaintenanceBundle::class), BundleConfig::create(NelmioCorsBundle::class), BundleConfig::create(NelmioSecurityBundle::class), diff --git a/manager-bundle/src/Resources/skeleton/config/config.yml b/manager-bundle/src/Resources/skeleton/config/config.yml index c8ceceed74f..e5d63f0837d 100644 --- a/manager-bundle/src/Resources/skeleton/config/config.yml +++ b/manager-bundle/src/Resources/skeleton/config/config.yml @@ -1,6 +1,7 @@ imports: - { resource: parameters.yml } - { resource: security.yml } + - { resource: services.yml } # Put parameters here that don't need to change on each machine where the app is deployed # http://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration @@ -24,6 +25,12 @@ framework: handler_id: ~ cookie_secure: auto fragments: { path: /_fragment } + cache: + pools: + doctrine.result_cache_pool: + adapter: cache.app + doctrine.system_cache_pool: + adapter: cache.system # Contao configuration contao: @@ -57,29 +64,13 @@ doctrine: naming_strategy: doctrine.orm.naming_strategy.default metadata_cache_driver: type: service - id: doctrine_cache.providers.doctrine_metadata_cache - result_cache_driver: - type: service - id: doctrine_cache.providers.doctrine_result_cache + id: app.doctrine_system_cache_provider query_cache_driver: type: service - id: doctrine_cache.providers.doctrine_query_cache - -# Doctrine cache configuration -doctrine_cache: - providers: - doctrine_metadata_cache: - file_system: - extension: .cache - directory: '%kernel.cache_dir%/doctrine/metadata' - doctrine_result_cache: - file_system: - extension: .cache - directory: '%kernel.cache_dir%/doctrine/result' - doctrine_query_cache: - file_system: - extension: .cache - directory: '%kernel.cache_dir%/doctrine/query' + id: app.doctrine_system_cache_provider + result_cache_driver: + type: service + id: app.doctrine_result_cache_provider # SwiftMailer configuration swiftmailer: diff --git a/manager-bundle/src/Resources/skeleton/config/services.yml b/manager-bundle/src/Resources/skeleton/config/services.yml new file mode 100644 index 00000000000..149c6b808e9 --- /dev/null +++ b/manager-bundle/src/Resources/skeleton/config/services.yml @@ -0,0 +1,10 @@ +services: + app.doctrine_result_cache_provider: + class: Symfony\Component\Cache\DoctrineProvider + arguments: + - '@doctrine.result_cache_pool' + + app.doctrine_system_cache_provider: + class: Symfony\Component\Cache\DoctrineProvider + arguments: + - '@doctrine.system_cache_pool' diff --git a/manager-bundle/tests/ContaoManager/PluginTest.php b/manager-bundle/tests/ContaoManager/PluginTest.php index 904cf6b401a..3c4512cabdb 100644 --- a/manager-bundle/tests/ContaoManager/PluginTest.php +++ b/manager-bundle/tests/ContaoManager/PluginTest.php @@ -22,7 +22,6 @@ use Contao\ManagerPlugin\PluginLoader; use Contao\TestCase\ContaoTestCase; use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; -use Doctrine\Bundle\DoctrineCacheBundle\DoctrineCacheBundle; use Doctrine\DBAL\Connection; use FOS\HttpCacheBundle\FOSHttpCacheBundle; use Lexik\Bundle\MaintenanceBundle\LexikMaintenanceBundle; @@ -84,7 +83,7 @@ public function testReturnsTheBundles(): void /** @var array $bundles */ $bundles = $plugin->getBundles(new DelegatingParser()); - $this->assertCount(14, $bundles); + $this->assertCount(13, $bundles); $this->assertSame(FrameworkBundle::class, $bundles[0]->getName()); $this->assertSame([], $bundles[0]->getReplace()); @@ -110,39 +109,35 @@ public function testReturnsTheBundles(): void $this->assertSame([], $bundles[5]->getReplace()); $this->assertSame([], $bundles[5]->getLoadAfter()); - $this->assertSame(DoctrineCacheBundle::class, $bundles[6]->getName()); + $this->assertSame(LexikMaintenanceBundle::class, $bundles[6]->getName()); $this->assertSame([], $bundles[6]->getReplace()); $this->assertSame([], $bundles[6]->getLoadAfter()); - $this->assertSame(LexikMaintenanceBundle::class, $bundles[7]->getName()); + $this->assertSame(NelmioCorsBundle::class, $bundles[7]->getName()); $this->assertSame([], $bundles[7]->getReplace()); $this->assertSame([], $bundles[7]->getLoadAfter()); - $this->assertSame(NelmioCorsBundle::class, $bundles[8]->getName()); + $this->assertSame(NelmioSecurityBundle::class, $bundles[8]->getName()); $this->assertSame([], $bundles[8]->getReplace()); $this->assertSame([], $bundles[8]->getLoadAfter()); - $this->assertSame(NelmioSecurityBundle::class, $bundles[9]->getName()); + $this->assertSame(FOSHttpCacheBundle::class, $bundles[9]->getName()); $this->assertSame([], $bundles[9]->getReplace()); $this->assertSame([], $bundles[9]->getLoadAfter()); - $this->assertSame(FOSHttpCacheBundle::class, $bundles[10]->getName()); + $this->assertSame(ContaoManagerBundle::class, $bundles[10]->getName()); $this->assertSame([], $bundles[10]->getReplace()); - $this->assertSame([], $bundles[10]->getLoadAfter()); + $this->assertSame([ContaoCoreBundle::class], $bundles[10]->getLoadAfter()); - $this->assertSame(ContaoManagerBundle::class, $bundles[11]->getName()); + $this->assertSame(DebugBundle::class, $bundles[11]->getName()); $this->assertSame([], $bundles[11]->getReplace()); - $this->assertSame([ContaoCoreBundle::class], $bundles[11]->getLoadAfter()); + $this->assertSame([], $bundles[11]->getLoadAfter()); + $this->assertFalse($bundles[11]->loadInProduction()); - $this->assertSame(DebugBundle::class, $bundles[12]->getName()); + $this->assertSame(WebProfilerBundle::class, $bundles[12]->getName()); $this->assertSame([], $bundles[12]->getReplace()); $this->assertSame([], $bundles[12]->getLoadAfter()); $this->assertFalse($bundles[12]->loadInProduction()); - - $this->assertSame(WebProfilerBundle::class, $bundles[13]->getName()); - $this->assertSame([], $bundles[13]->getReplace()); - $this->assertSame([], $bundles[13]->getLoadAfter()); - $this->assertFalse($bundles[13]->loadInProduction()); } public function testRegistersModuleBundles(): void @@ -167,7 +162,7 @@ static function ($resource): array { $plugin = new Plugin(); $configs = $plugin->getBundles($parser); - $this->assertCount(16, $configs); + $this->assertCount(15, $configs); $this->assertContains('foo1', $configs); $this->assertContains('foo2', $configs); $this->assertNotContains('foo3', $configs);