Skip to content

Commit

Permalink
Merge tag v2.4.5 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
roadiz-ci committed Jan 14, 2025
1 parent 1f69500 commit 84011c6
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 37 deletions.
2 changes: 1 addition & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
12 changes: 6 additions & 6 deletions src/Cache/CloudflareProxyCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
) {
}
Expand All @@ -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;
}
Expand Down
8 changes: 3 additions & 5 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -178,7 +178,6 @@ protected function addReverseProxyCacheNode()
$node = $builder->getRootNode();
$node->children()
->arrayNode('frontend')
->isRequired()
->useAttributeAsKey('name')
->prototype('array')
->children()
Expand All @@ -195,7 +194,6 @@ protected function addReverseProxyCacheNode()
->end()
->end()
->arrayNode('cloudflare')
->addDefaultsIfNotSet()
->children()
->scalarNode('version')
->defaultValue('v4')
Expand Down
40 changes: 19 additions & 21 deletions src/DependencyInjection/RoadizCoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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'],
])
);
Expand Down Expand Up @@ -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',
Expand All @@ -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);
Expand Down
15 changes: 11 additions & 4 deletions src/EventSubscriber/CloudflareCacheEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down

0 comments on commit 84011c6

Please sign in to comment.