Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 72 additions & 36 deletions src/Command/Update/IndexUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@

private const OPTION_UPDATE_ASSET_INDEX = 'update-asset-index';

private const OPTION_UPDATE_DOCUMENT_INDEX = 'update-document-index';

private const OPTION_RECREATE_INDEX = 'recreate_index';

private const UPDATE_GLOBAL_ALIASES_ONLY = 'update-global-aliases-only';
Expand Down Expand Up @@ -84,6 +86,13 @@
'Update mapping and data for asset index',
null
)
->addOption(
self::OPTION_UPDATE_DOCUMENT_INDEX,
'd',
InputOption::VALUE_NONE,
'Update mapping and data for document index',
null
)
->addOption(
self::OPTION_RECREATE_INDEX,
'r',
Expand Down Expand Up @@ -131,52 +140,23 @@

if ($classDefinitionId) {
$updateAll = false;

try {
$classDefinition = ClassDefinition::getById($classDefinitionId);
if (!$classDefinition) {
throw new IdNotFoundException(
sprintf('ClassDefinition with id %s not found', $classDefinitionId)
);
}

$this->output->writeln(
sprintf(
'<info>Update index and indices for ClassDefinition with id %s</info>',
$classDefinitionId
),
OutputInterface::VERBOSITY_NORMAL
);

$this
->indexUpdateService
->updateClassDefinition($classDefinition);
} catch (Exception $e) {
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
}
$this->updateClassDefinition($classDefinitionId);
}

if ($input->getOption(self::OPTION_UPDATE_ASSET_INDEX)) {
$updateAll = false;
$this->updateAssets();
}

try {
$output->writeln(
'<info>Update asset index</info>',
OutputInterface::VERBOSITY_NORMAL
);

$this
->indexUpdateService
->updateAssets();
} catch (Exception $e) {
$this->output->writeln($e->getMessage());
}
if ($input->getOption(self::OPTION_UPDATE_DOCUMENT_INDEX)) {
$updateAll = false;
$this->updateDocuments();
}

if ($updateAll) {
try {
$this->output->writeln(
'<info>Update all mappings and indices for objects/assets</info>',
'<info>Update all mappings and indices for objects/assets/documents</info>',
OutputInterface::VERBOSITY_NORMAL
);

Expand All @@ -203,6 +183,62 @@
return self::SUCCESS;
}

private function updateClassDefinition(string $classDefinitionId)
{
try {
$classDefinition = ClassDefinition::getById($classDefinitionId);
if (!$classDefinition) {
throw new IdNotFoundException(
sprintf('ClassDefinition with id %s not found', $classDefinitionId)
);
}

$this->output->writeln(
sprintf(
'<info>Update index and indices for ClassDefinition with id %s</info>',
$classDefinitionId
),
OutputInterface::VERBOSITY_NORMAL
);

$this
->indexUpdateService
->updateClassDefinition($classDefinition);
} catch (Exception $e) {
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
}
}

private function updateAssets() : void {

Check warning on line 212 in src/Command/Update/IndexUpdateCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this open curly brace to the beginning of the next line.

See more on https://sonarcloud.io/project/issues?id=pimcore_generic-data-index-bundle&issues=AZroUoIlYO5B5yFl3UpL&open=AZroUoIlYO5B5yFl3UpL&pullRequest=375
try {
$this->output->writeln(
'<info>Update asset index</info>',
OutputInterface::VERBOSITY_NORMAL
);

$this
->indexUpdateService
->updateAssets();
} catch (Exception $e) {
$this->output->writeln($e->getMessage());
}
}

private function updateDocuments() : void {

Check warning on line 227 in src/Command/Update/IndexUpdateCommand.php

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Move this open curly brace to the beginning of the next line.

See more on https://sonarcloud.io/project/issues?id=pimcore_generic-data-index-bundle&issues=AZroUoIlYO5B5yFl3UpM&open=AZroUoIlYO5B5yFl3UpM&pullRequest=375
try {
$this->output->writeln(
'<info>Update document index</info>',
OutputInterface::VERBOSITY_NORMAL
);

$this
->indexUpdateService
->updateDocuments();
} catch (Exception $e) {
$this->output->writeln($e->getMessage());
}
}

private function updateGlobalIndexAliases(): void
{
$this->output->writeln(
Expand Down