Skip to content

Commit fc36e59

Browse files
committed
feat: hide elasticsearch tab if not installed, fixes #131
1 parent 91b430d commit fc36e59

File tree

5 files changed

+44
-1
lines changed

5 files changed

+44
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
namespace Frosh\Tools\Components\Elasticsearch;
4+
5+
use Symfony\Component\HttpKernel\Event\ResponseEvent;
6+
7+
final class AdminInfoSubscriber
8+
{
9+
private bool $elasticsearchEnabled;
10+
11+
public function __construct(bool $elasticsearchEnabled)
12+
{
13+
$this->elasticsearchEnabled = $elasticsearchEnabled;
14+
}
15+
16+
public function __invoke(ResponseEvent $event): void
17+
{
18+
if ($event->getRequest()->attributes->get('_route') !== 'api.info.config') {
19+
return;
20+
}
21+
22+
/** @var array{'version': string} $json */
23+
$json = json_decode((string) $event->getResponse()->getContent(), true, 512, \JSON_THROW_ON_ERROR);
24+
25+
$json['settings']['elasticsearchEnabled'] = $this->elasticsearchEnabled;
26+
27+
$event->getResponse()->setContent(json_encode($json, \JSON_THROW_ON_ERROR));
28+
}
29+
30+
}

src/DependencyInjection/DisableElasticsearchCompilerPass.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,13 @@ class DisableElasticsearchCompilerPass implements CompilerPassInterface
1313
public function process(ContainerBuilder $container): void
1414
{
1515
if ($container->hasDefinition(Client::class)) {
16+
$container->setParameter('frosh_tools.elasticsearch.enabled', true);
1617
return;
1718
}
1819

1920
$manager = $container->getDefinition(ElasticsearchManager::class);
2021
$manager->setClass(DisabledElasticsearchManager::class);
2122
$manager->setArguments([]);
23+
$container->setParameter('frosh_tools.elasticsearch.enabled', false);
2224
}
2325
}

src/Resources/app/administration/src/module/frosh-tools/page/index/index.js

+6
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,10 @@ const { Component } = Shopware;
55

66
Component.register('frosh-tools-index', {
77
template,
8+
9+
computed: {
10+
elasticsearchAvailable() {
11+
return Shopware.State.get('context').app.config.settings?.elasticsearchEnabled || false;
12+
}
13+
}
814
});

src/Resources/app/administration/src/module/frosh-tools/page/index/template.twig

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
{{ $tc('frosh-tools.tabs.files.title') }}
3131
</sw-tabs-item>
3232

33-
<sw-tabs-item :route="{ name: 'frosh.tools.index.elasticsearch' }">
33+
<sw-tabs-item :route="{ name: 'frosh.tools.index.elasticsearch' }" v-if="elasticsearchAvailable">
3434
{{ $tc('frosh-tools.tabs.elasticsearch.title') }}
3535
</sw-tabs-item>
3636

src/Resources/config/services/elasticsearch.xml

+5
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,10 @@
2525
<argument>%frosh_tools.elasticsearch.product_fields%</argument>
2626
<argument>%frosh_tools.elasticsearch.product_minimum_should_match%</argument>
2727
</service>
28+
29+
<service id="Frosh\Tools\Components\Elasticsearch\AdminInfoSubscriber">
30+
<argument>%frosh_tools.elasticsearch.enabled%</argument>
31+
<tag name="kernel.event_listener"/>
32+
</service>
2833
</services>
2934
</container>

0 commit comments

Comments
 (0)