|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
|
|
3
|
|
|
namespace Shopware\Elasticsearch\Framework\Command; |
|
4
|
|
|
|
|
5
|
|
|
use Shopware\Core\Framework\Adapter\Console\ShopwareStyle; |
|
6
|
|
|
use Shopware\Core\Framework\DataAbstractionLayer\Command\ConsoleProgressTrait; |
|
7
|
|
|
use Shopware\Core\Framework\Log\Package; |
|
8
|
|
|
use Shopware\Elasticsearch\Admin\AdminIndexingBehavior; |
|
9
|
|
|
use Shopware\Elasticsearch\Admin\AdminSearchRegistry; |
|
10
|
|
|
use Symfony\Component\Console\Command\Command; |
|
11
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
12
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
13
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
14
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* @internal |
|
18
|
|
|
*/ |
|
19
|
|
|
#[Package('system-settings')] |
|
20
|
|
|
final class ElasticsearchAdminIndexingCommand extends Command implements EventSubscriberInterface |
|
21
|
|
|
{ |
|
22
|
|
|
use ConsoleProgressTrait; |
|
23
|
|
|
|
|
24
|
|
|
protected static $defaultName = 'es:admin:index'; |
|
25
|
|
|
|
|
26
|
|
|
protected static $defaultDescription = 'Index the elasticsearch for the admin search'; |
|
27
|
|
|
|
|
28
|
|
|
private AdminSearchRegistry $registry; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @internal |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct(AdminSearchRegistry $registry) |
|
34
|
|
|
{ |
|
35
|
|
|
parent::__construct(); |
|
36
|
|
|
$this->registry = $registry; |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* {@inheritdoc} |
|
41
|
|
|
*/ |
|
42
|
|
|
protected function configure(): void |
|
43
|
|
|
{ |
|
44
|
|
|
$this->addOption('no-queue', null, null, 'Do not use the queue for indexing'); |
|
45
|
|
|
$this->addOption('skip', null, InputArgument::OPTIONAL, 'Comma separated list of entity names to be skipped'); |
|
46
|
|
|
$this->addOption('only', null, InputArgument::OPTIONAL, 'Comma separated list of entity names to be generated'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
protected function execute(InputInterface $input, OutputInterface $output): int |
|
50
|
|
|
{ |
|
51
|
|
|
$this->io = new ShopwareStyle($input, $output); |
|
52
|
|
|
|
|
53
|
|
|
$skip = \is_string($input->getOption('skip')) ? explode(',', $input->getOption('skip')) : []; |
|
54
|
|
|
$only = \is_string($input->getOption('only')) ? explode(',', $input->getOption('only')) : []; |
|
55
|
|
|
|
|
56
|
|
|
$this->registry->iterate( |
|
57
|
|
|
new AdminIndexingBehavior( |
|
58
|
|
|
(bool) $input->getOption('no-queue'), |
|
59
|
|
|
$skip, |
|
60
|
|
|
$only |
|
61
|
|
|
) |
|
62
|
|
|
); |
|
63
|
|
|
|
|
64
|
|
|
return self::SUCCESS; |
|
65
|
|
|
} |
|
66
|
|
|
} |
|
67
|
|
|
|