-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathIndexCreateCommand.php
70 lines (57 loc) · 2.22 KB
/
IndexCreateCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<?php
declare(strict_types=1);
/*
* This file is part of the CMS-IG SEAL project.
*
* (c) Alexander Schranz <alexander@sulu.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace CmsIg\Seal\Integration\Yii\Command;
use CmsIg\Seal\EngineRegistry;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
/**
* @experimental
*/
final class IndexCreateCommand extends Command
{
public function __construct(private readonly EngineRegistry $engineRegistry)
{
parent::__construct('cmsig:seal:index-create');
}
protected function configure(): void
{
$this->setDescription('Create configured search indexes.');
$this->addOption('engine', null, InputOption::VALUE_REQUIRED, 'The name of the engine to create the schema for.');
$this->addOption('index', null, InputOption::VALUE_REQUIRED, 'The name of the index to create the schema for.');
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$ui = new SymfonyStyle($input, $output);
/** @var string|null $engineName */
$engineName = $input->getOption('engine');
/** @var string|null $indexName */
$indexName = $input->getOption('index');
foreach ($this->engineRegistry->getEngines() as $name => $engine) {
if ($engineName && $engineName !== $name) {
continue;
}
if ($indexName) {
$ui->text('Creating search index "' . $indexName . '" of "' . $name . '" ...');
$task = $engine->createIndex($indexName, ['return_slow_promise_result' => true]);
$task->wait();
continue;
}
$ui->text('Creating search indexes of "' . $name . '" ...');
$task = $engine->createSchema(['return_slow_promise_result' => true]);
$task->wait();
}
$ui->success('Search indexes created.');
return Command::SUCCESS;
}
}