1 | <?php |
||||
2 | |||||
3 | namespace Locastic\Loggastic\Command; |
||||
4 | |||||
5 | use Elasticsearch\Common\Exceptions\BadRequest400Exception; |
||||
6 | use Locastic\Loggastic\Bridge\Elasticsearch\Index\ElasticsearchIndexFactoryInterface; |
||||
7 | use Locastic\Loggastic\Metadata\LoggableContext\Factory\LoggableContextCollectionFactoryInterface; |
||||
8 | use Symfony\Component\Console\Attribute\AsCommand; |
||||
9 | use Symfony\Component\Console\Command\Command; |
||||
10 | use Symfony\Component\Console\Input\InputInterface; |
||||
11 | use Symfony\Component\Console\Output\OutputInterface; |
||||
12 | use Symfony\Component\Console\Style\SymfonyStyle; |
||||
13 | |||||
14 | #[AsCommand('locastic:activity-logs:create-loggable-indexes')] |
||||
15 | final class CreateLoggableIndexesCommand extends Command |
||||
16 | { |
||||
17 | public function __construct(private readonly LoggableContextCollectionFactoryInterface $loggableContextCollectionFactory, private readonly ElasticsearchIndexFactoryInterface $elasticsearchIndexFactory) |
||||
18 | { |
||||
19 | parent::__construct(); |
||||
20 | } |
||||
21 | |||||
22 | protected function execute(InputInterface $input, OutputInterface $output): int |
||||
23 | { |
||||
24 | $io = new SymfonyStyle($input, $output); |
||||
25 | |||||
26 | $io->title('Creating activity log indexes ...'); |
||||
27 | $loggableContextCollection = $this->loggableContextCollectionFactory->create(); |
||||
28 | |||||
29 | foreach ($loggableContextCollection->getIterator() as $loggableClass => $config) { |
||||
30 | $io->writeln('Creating '.$loggableClass.' activity_log index'); |
||||
31 | |||||
32 | try { |
||||
33 | $this->elasticsearchIndexFactory->createActivityLogIndex($loggableClass); |
||||
0 ignored issues
–
show
Bug
introduced
by
![]() |
|||||
34 | } catch (BadRequest400Exception $e) { |
||||
35 | if (strpos($e->getMessage(), 'resource_already_exists_exception')) { |
||||
36 | $output->writeln('Index already exists, skipping.'); |
||||
37 | } else { |
||||
38 | throw $e; |
||||
39 | } |
||||
40 | } |
||||
41 | |||||
42 | $io->writeln('Creating '.$loggableClass.' current_data_tracker index'); |
||||
43 | |||||
44 | try { |
||||
45 | $this->elasticsearchIndexFactory->createCurrentDataTrackerLogIndex($loggableClass); |
||||
0 ignored issues
–
show
It seems like
$loggableClass can also be of type null and true ; however, parameter $className of Locastic\Loggastic\Bridg...ntDataTrackerLogIndex() does only seem to accept string , maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
![]() |
|||||
46 | } catch (BadRequest400Exception $e) { |
||||
47 | if (strpos($e->getMessage(), 'resource_already_exists_exception')) { |
||||
48 | $output->writeln('Index already exists, skipping.'); |
||||
49 | } else { |
||||
50 | throw $e; |
||||
51 | } |
||||
52 | } |
||||
53 | } |
||||
54 | |||||
55 | $io->success('Done!'); |
||||
56 | |||||
57 | return Command::SUCCESS; |
||||
58 | } |
||||
59 | } |
||||
60 |