From 84011c6d2aa979620e6f18124ad325d65da09dfd Mon Sep 17 00:00:00 2001 From: roadiz-ci Date: Tue, 14 Jan 2025 10:20:12 +0000 Subject: [PATCH] Merge tag v2.4.5 into develop --- config/services.yaml | 2 +- src/Cache/CloudflareProxyCache.php | 12 +++--- src/DependencyInjection/Configuration.php | 8 ++-- .../RoadizCoreExtension.php | 40 +++++++++---------- .../CloudflareCacheEventSubscriber.php | 15 +++++-- 5 files changed, 40 insertions(+), 37 deletions(-) diff --git a/config/services.yaml b/config/services.yaml index 9a2c3759..3bf9b4fe 100644 --- a/config/services.yaml +++ b/config/services.yaml @@ -1,6 +1,6 @@ --- parameters: - roadiz_core.cms_version: '2.4.4' + roadiz_core.cms_version: '2.4.5' roadiz_core.cms_version_prefix: 'main' env(APP_NAMESPACE): "roadiz" env(APP_VERSION): "0.1.0" diff --git a/src/Cache/CloudflareProxyCache.php b/src/Cache/CloudflareProxyCache.php index ef602313..a4ffe4a6 100644 --- a/src/Cache/CloudflareProxyCache.php +++ b/src/Cache/CloudflareProxyCache.php @@ -10,9 +10,9 @@ public function __construct( private string $name, private string $zone, private string $version, - private string $bearer, - private string $email, - private string $key, + private ?string $bearer, + private ?string $email, + private ?string $key, private int $timeout, ) { } @@ -32,17 +32,17 @@ public function getVersion(): string return $this->version; } - public function getBearer(): string + public function getBearer(): ?string { return $this->bearer; } - public function getEmail(): string + public function getEmail(): ?string { return $this->email; } - public function getKey(): string + public function getKey(): ?string { return $this->key; } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 1cbf4f65..4ae150c6 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -144,14 +144,14 @@ protected function addSolrNode() $builder = new TreeBuilder('solr'); $node = $builder->getRootNode(); - $node->addDefaultsIfNotSet() - ->children() + $node->children() ->scalarNode('timeout')->defaultValue(3)->end() ->arrayNode('endpoints') + ->defaultValue([]) ->useAttributeAsKey('name') ->prototype('array') ->children() - ->scalarNode('host')->defaultValue('127.0.0.1')->end() + ->scalarNode('host')->isRequired()->end() ->scalarNode('username')->end() ->scalarNode('password')->end() ->scalarNode('core')->isRequired()->end() @@ -178,7 +178,6 @@ protected function addReverseProxyCacheNode() $node = $builder->getRootNode(); $node->children() ->arrayNode('frontend') - ->isRequired() ->useAttributeAsKey('name') ->prototype('array') ->children() @@ -195,7 +194,6 @@ protected function addReverseProxyCacheNode() ->end() ->end() ->arrayNode('cloudflare') - ->addDefaultsIfNotSet() ->children() ->scalarNode('version') ->defaultValue('v4') diff --git a/src/DependencyInjection/RoadizCoreExtension.php b/src/DependencyInjection/RoadizCoreExtension.php index de82ceec..be9d537a 100644 --- a/src/DependencyInjection/RoadizCoreExtension.php +++ b/src/DependencyInjection/RoadizCoreExtension.php @@ -145,10 +145,7 @@ private function registerReverseProxyCache(array $config, ContainerBuilder $cont $reverseProxyCacheFrontendsReferences[] = new Reference($definitionName); } - if ( - isset($config['reverseProxyCache']['cloudflare']) - && isset($config['reverseProxyCache']['cloudflare']['bearer']) - ) { + if (isset($config['reverseProxyCache']['cloudflare'])) { $container->setDefinition( 'roadiz_core.reverse_proxy_cache.cloudflare', (new Definition()) @@ -158,9 +155,9 @@ private function registerReverseProxyCache(array $config, ContainerBuilder $cont 'cloudflare', $config['reverseProxyCache']['cloudflare']['zone'], $config['reverseProxyCache']['cloudflare']['version'], - $config['reverseProxyCache']['cloudflare']['bearer'], - $config['reverseProxyCache']['cloudflare']['email'], - $config['reverseProxyCache']['cloudflare']['key'], + $config['reverseProxyCache']['cloudflare']['bearer'] ?? null, + $config['reverseProxyCache']['cloudflare']['email'] ?? null, + $config['reverseProxyCache']['cloudflare']['key'] ?? null, $config['reverseProxyCache']['cloudflare']['timeout'], ]) ); @@ -202,6 +199,9 @@ private function registerEntityGenerator(array $config, ContainerBuilder $contai private function registerSolr(array $config, ContainerBuilder $container): void { + if (!isset($config['solr'])) { + return; + } $solrEndpoints = []; $container->setDefinition( 'roadiz_core.solr.adapter', @@ -211,20 +211,18 @@ private function registerSolr(array $config, ContainerBuilder $container): void ->addMethodCall('setTimeout', [$config['solr']['timeout']]) ->addMethodCall('setConnectionTimeout', [$config['solr']['timeout']]) ); - if (isset($config['solr'])) { - foreach ($config['solr']['endpoints'] as $name => $endpoint) { - $container->setDefinition( - 'roadiz_core.solr.endpoints.'.$name, - (new Definition()) - ->setClass(Endpoint::class) - ->setPublic(true) - ->setArguments([ - $endpoint, - ]) - ->addMethodCall('setKey', [$name]) - ); - $solrEndpoints[] = 'roadiz_core.solr.endpoints.'.$name; - } + foreach ($config['solr']['endpoints'] as $name => $endpoint) { + $container->setDefinition( + 'roadiz_core.solr.endpoints.'.$name, + (new Definition()) + ->setClass(Endpoint::class) + ->setPublic(true) + ->setArguments([ + $endpoint, + ]) + ->addMethodCall('setKey', [$name]) + ); + $solrEndpoints[] = 'roadiz_core.solr.endpoints.'.$name; } if (count($solrEndpoints) > 0) { $logger = new Reference(SolariumLogger::class); diff --git a/src/EventSubscriber/CloudflareCacheEventSubscriber.php b/src/EventSubscriber/CloudflareCacheEventSubscriber.php index 4e2a9f76..48a6579b 100644 --- a/src/EventSubscriber/CloudflareCacheEventSubscriber.php +++ b/src/EventSubscriber/CloudflareCacheEventSubscriber.php @@ -40,7 +40,11 @@ public static function getSubscribedEvents(): array protected function supportConfig(): bool { - return null !== $this->reverseProxyCacheLocator->getCloudflareProxyCache(); + return null !== $this->reverseProxyCacheLocator->getCloudflareProxyCache() && + ( + null !== $this->reverseProxyCacheLocator->getCloudflareProxyCache()->getBearer() || + null !== $this->reverseProxyCacheLocator->getCloudflareProxyCache()->getEmail() + ); } public function onBanRequest(CachePurgeRequestEvent $event): void @@ -118,9 +122,12 @@ protected function createRequest(array $body): HttpRequestMessageInterface $headers = [ 'Content-type' => 'application/json', ]; - $headers['Authorization'] = 'Bearer '.trim($this->getCloudflareCacheProxy()->getBearer()); - $headers['X-Auth-Email'] = $this->getCloudflareCacheProxy()->getEmail(); - $headers['X-Auth-Key'] = $this->getCloudflareCacheProxy()->getKey(); + if (null !== $this->getCloudflareCacheProxy()->getBearer()) { + $headers['Authorization'] = 'Bearer '.trim($this->getCloudflareCacheProxy()->getBearer()); + } else { + $headers['X-Auth-Email'] = $this->getCloudflareCacheProxy()->getEmail(); + $headers['X-Auth-Key'] = $this->getCloudflareCacheProxy()->getKey(); + } $uri = sprintf( 'https://api.cloudflare.com/client/%s/zones/%s/purge_cache',