|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Elasticsearch\Framework\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Connection; |
|
6
|
|
|
use OpenSearch\Client; |
|
7
|
|
|
use Shopware\Core\Framework\Increment\Exception\IncrementGatewayNotFoundException; |
|
8
|
|
|
use Shopware\Core\Framework\Increment\IncrementGatewayRegistry; |
|
9
|
|
|
use Shopware\Elasticsearch\Admin\AdminElasticsearchHelper; |
|
10
|
|
|
use Shopware\Elasticsearch\Admin\AdminSearchIndexingMessage; |
|
11
|
|
|
use Symfony\Component\Console\Attribute\AsCommand; |
|
12
|
|
|
use Symfony\Component\Console\Command\Command; |
|
|
|
|
|
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
15
|
|
|
use Symfony\Component\Console\Style\SymfonyStyle; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* @package system-settings |
|
19
|
|
|
* |
|
20
|
|
|
* @internal |
|
21
|
|
|
*/ |
|
22
|
|
|
#[AsCommand( |
|
23
|
|
|
name: 'es:admin:reset', |
|
24
|
|
|
description: 'Reset Admin Elasticsearch indexing', |
|
25
|
|
|
)] |
|
26
|
|
|
class ElasticsearchAdminResetCommand extends Command |
|
27
|
|
|
{ |
|
28
|
|
|
private Client $client; |
|
29
|
|
|
|
|
30
|
|
|
private Connection $connection; |
|
31
|
|
|
|
|
32
|
|
|
private IncrementGatewayRegistry $gatewayRegistry; |
|
33
|
|
|
|
|
34
|
|
|
private AdminElasticsearchHelper $adminEsHelper; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* @internal |
|
38
|
|
|
*/ |
|
39
|
|
|
public function __construct( |
|
40
|
|
|
Client $client, |
|
41
|
|
|
Connection $connection, |
|
42
|
|
|
IncrementGatewayRegistry $gatewayRegistry, |
|
43
|
|
|
AdminElasticsearchHelper $adminEsHelper |
|
44
|
|
|
) { |
|
45
|
|
|
parent::__construct(); |
|
46
|
|
|
$this->client = $client; |
|
47
|
|
|
$this->connection = $connection; |
|
48
|
|
|
$this->gatewayRegistry = $gatewayRegistry; |
|
49
|
|
|
$this->adminEsHelper = $adminEsHelper; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
53
|
|
|
{ |
|
54
|
|
|
$io = new SymfonyStyle($input, $output); |
|
55
|
|
|
|
|
56
|
|
|
if ($this->adminEsHelper->getEnabled() !== true) { |
|
57
|
|
|
$io->error('Admin elasticsearch is not enabled'); |
|
58
|
|
|
|
|
59
|
|
|
return self::FAILURE; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
$answer = $io->ask('Are you sure you want to reset the Admin Elasticsearch indexing?', 'yes'); |
|
63
|
|
|
|
|
64
|
|
|
if ($answer !== 'yes') { |
|
65
|
|
|
$io->error('Canceled clearing indexing process'); |
|
66
|
|
|
|
|
67
|
|
|
return self::SUCCESS; |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
$allIndices = $this->client->indices()->get(['index' => $this->adminEsHelper->getPrefix() . '*']); |
|
71
|
|
|
|
|
72
|
|
|
foreach ($allIndices as $index) { |
|
73
|
|
|
$this->client->indices()->delete(['index' => $index['settings']['index']['provided_name']]); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
$this->connection->executeStatement('TRUNCATE admin_elasticsearch_index_task'); |
|
77
|
|
|
|
|
78
|
|
|
try { |
|
79
|
|
|
$gateway = $this->gatewayRegistry->get(IncrementGatewayRegistry::MESSAGE_QUEUE_POOL); |
|
80
|
|
|
$gateway->reset('message_queue_stats', AdminSearchIndexingMessage::class); |
|
81
|
|
|
} catch (IncrementGatewayNotFoundException $exception) { |
|
82
|
|
|
// In case message_queue pool is disabled |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
$io->success('Admin Elasticsearch indices deleted and queue cleared'); |
|
86
|
|
|
|
|
87
|
|
|
return self::SUCCESS; |
|
88
|
|
|
} |
|
89
|
|
|
} |
|
90
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths