Skip to content

Commit

Permalink
Prepare first version of an OpenSearch index queue mechanism similar …
Browse files Browse the repository at this point in the history
…to portal engine
  • Loading branch information
markus-moser committed Jan 12, 2024
1 parent 4584d80 commit f641bf2
Show file tree
Hide file tree
Showing 61 changed files with 3,889 additions and 2 deletions.
12 changes: 12 additions & 0 deletions config/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
doctrine:
orm:
entity_managers:
pimcore_generic_data_index:
connection: default
mappings:
PimcoreGenericDataIndexBundle:
type: attribute
is_bundle: true
dir: "src/Entity"
prefix: Pimcore\Bundle\GenericDataIndexBundle\Entity
alias: PimcoreGenericDataIndex
2 changes: 2 additions & 0 deletions config/pimcore/config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
imports:
- { resource: messenger.yaml }
11 changes: 11 additions & 0 deletions config/pimcore/messenger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
framework:
messenger:
enabled: true
transports:
pimcore_index_queues: 'doctrine://default?queue_name=pimcore_index_queues'
routing:
Pimcore\Bundle\GenericDataIndexBundle\Message\IndexUpdateQueueMessage: pimcore_index_queues
buses:
messenger.bus.pimcore-generic-data-index:
middleware:
- 'Pimcore\Bundle\GenericDataIndexBundle\Service\Messenger\Middleware\CollectGarbageMiddleware'
3 changes: 3 additions & 0 deletions config/pimcore/routing.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pimcore_generic_data_index_homepage:
path: /pimcore_generic_data_index
defaults: { _controller: Pimcore\Bundle\GenericDataIndexBundle\Controller\DefaultController:indexAction }
24 changes: 23 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,27 @@
imports:
- { resource: 'services/search/index.yaml' }
- { resource: 'services/search/data-object/*' }
- { resource: 'services/*' }
services:
_defaults:
autowire: true
autoconfigure: true
public: false
public: false

# controllers are imported separately to make sure they're public
# and have a tag that allows actions to type-hint services
Pimcore\Bundle\GenericDataIndexBundle\Controller\:
resource: '../src/Controller'
public: true
tags: ['controller.service_arguments']

Pimcore\Bundle\GenericDataIndexBundle\MessageHandler\:
resource: '../src/MessageHandler'
tags: [ { name: messenger.message_handler, bus: messenger.bus.pimcore-generic-data-index } ]

# add more services, or override services that need manual wiring
# Pimcore\_generic-data-index-bundle\ExampleClass:
# arguments:
# - "@service_id"
# - "plain_value"
# - "%parameter%"
10 changes: 10 additions & 0 deletions config/services/commands.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

# auto-register all commands as services
Pimcore\Bundle\GenericDataIndexBundle\Command\:
resource: '../../src/Command/*'
tags: ['console.command']
7 changes: 7 additions & 0 deletions config/services/data-object.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\DataObject\SelectOptionsService: ~
7 changes: 7 additions & 0 deletions config/services/messenger.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\Messenger\Middleware\CollectGarbageMiddleware: ~
104 changes: 104 additions & 0 deletions config/services/search/data-object/field-definition-adapters.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\DefaultAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "wysiwyg" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\TextAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "input" }
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "textarea" }
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "calculatedValue" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\NumericAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "numeric" }
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "slider" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\DateAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "date" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\DateTimeAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "datetime" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\LocalizedFieldsAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "localizedfields" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\QuantityValueAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "quantityValue" }
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "inputQuantityValue" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\BooleanAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "checkbox" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\SelectAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "select" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\MultiSelectAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "multiselect" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\CountryAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "country" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\LanguageAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "language" }

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\CountryMultiSelectAdapter:
shared: false
tags:
- { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "countrymultiselect" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\LanguageMultiSelectAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "languagemultiselect" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\ManyToOneRelationAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "manyToOneRelation" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\ManyToManyObjectRelationAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "manyToManyObjectRelation" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\AdvancedManyToManyRelationAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "advancedManyToManyRelation" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\AdvancedManyToManyObjectRelationAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "advancedManyToManyObjectRelation" }

#Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionAdapter\ManyToManyRelationAdapter:
# shared: false
# tags:
# - { name: "pimcore.generic_data_index.data-object.search_index_field_definition", type: "manyToManyRelation" }
24 changes: 24 additions & 0 deletions config/services/search/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\LanguageService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\AssetIndexService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexService\DataObjectIndexService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\SearchIndexConfigService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\OpenSearchService: ~
Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\OpenSearch\BulkOperationService: ~

Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\DataObject\FieldDefinitionService:
arguments:
- '@pimcore.generic_data_index.object.search_index_field_definition_locator'

pimcore.generic_data_index.object.search_index_field_definition_locator:
class: Symfony\Component\DependencyInjection\ServiceLocator
tags: [ 'container.service_locator' ]
arguments:
- [ ]
7 changes: 7 additions & 0 deletions config/services/workflow.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

Pimcore\Bundle\GenericDataIndexBundle\Service\Workflow\WorkflowService: ~
130 changes: 130 additions & 0 deletions src/Command/Update/IndexUpdateCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
<?php

Check failure on line 1 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing strict types declaration

Strict types declaration is missing

/**
* Pimcore
*
* This source file is available under following license:
* - Pimcore Commercial License (PCL)
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\GenericDataIndexBundle\Command\Update;

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Class path doesn't match project structure

Namespace name doesn't match the PSR-0/PSR-4 project structure

use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexQueueService;
use Pimcore\Bundle\GenericDataIndexBundle\Service\SearchIndex\IndexUpdateService;
use Pimcore\Console\AbstractCommand;
use Pimcore\Model\DataObject\ClassDefinition;
use Symfony\Component\Console\Command\LockableTrait;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Contracts\Service\Attribute\Required;

class IndexUpdateCommand extends AbstractCommand
{
use LockableTrait;

const OPTION_CLASS_DEFINITION_ID = 'class-definition-id';

Check notice on line 29 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Access modifiers shall be defined

\[EA\] 'OPTION_CLASS_DEFINITION_ID' should be declared with access modifier.

Check notice on line 29 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing visibility

PSR-12: Missing visibility definition
const OPTION_UPDATE_ASSET_INDEX = 'update-asset-index';

Check notice on line 30 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Access modifiers shall be defined

\[EA\] 'OPTION_UPDATE_ASSET_INDEX' should be declared with access modifier.

Check notice on line 30 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing visibility

PSR-12: Missing visibility definition
const OPTION_RECREATE_INDEX = 'recreate_index';

Check notice on line 31 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Access modifiers shall be defined

\[EA\] 'OPTION_RECREATE_INDEX' should be declared with access modifier.

Check notice on line 31 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing visibility

PSR-12: Missing visibility definition

protected IndexUpdateService $indexUpdateService;
protected IndexQueueService $indexQueueService;


protected function configure()

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing return type declaration

Missing function's return type declaration

Check notice on line 37 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Return type hint can be used

\[EA\] ': void' can be declared as return type hint (please use change signature intention to fix this).
{
$this
->setName('generic-data-index:update:index')
->addOption(self::OPTION_CLASS_DEFINITION_ID, 'cid', InputOption::VALUE_OPTIONAL, 'Update mapping and data for specific data object classDefinition', null)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
->addOption(self::OPTION_UPDATE_ASSET_INDEX, 'a', InputOption::VALUE_NONE, 'Update mapping and data for asset index', null)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
->addOption(self::OPTION_RECREATE_INDEX, 'r', InputOption::VALUE_NONE, 'Delete OpenSearch index and recreate it', null)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
->setDescription('Updates index/mapping for all classDefinitions/asset without deleting them. Adds there elements to index queue.');

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)
}

/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @throws \Exception

Check notice on line 51 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import
*
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Missing return type declaration

Missing function's return type declaration

Check notice on line 55 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Return type hint can be used

\[EA\] ': int' can be declared as return type hint (please use change signature intention to fix this).
{
if (!$this->lock()) {
throw new \Exception('The command is already running in another process.');

Check notice on line 58 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import

Check notice on line 58 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

General exception is thrown

\[EA\] \\Exception is too general. Consider throwing one of SPL exceptions instead.
}

$this->indexUpdateService->setReCreateIndex($input->getOption(self::OPTION_RECREATE_INDEX));

$updateAll = true;

/** @var string|null $classDefinitionId */
$classDefinitionId = $input->getOption(self::OPTION_CLASS_DEFINITION_ID);

if ($classDefinitionId) {
$updateAll = false;

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

Check notice on line 74 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import

Check notice on line 74 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

General exception is thrown

\[EA\] \\Exception is too general. Consider throwing one of SPL exceptions instead.
}

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

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

$this
->indexUpdateService
->updateClassDefinition($classDefinition);
} catch (\Exception $e) {

Check notice on line 82 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import
$this->output->writeln('<error>' . $e->getMessage() . '</error>');
}
}

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

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

$this
->indexUpdateService
->updateAssets();
} catch (\Exception $e) {

Check notice on line 96 in src/Command/Update/IndexUpdateCommand.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import
$this->output->writeln($e->getMessage());
}
}

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

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

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

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Line is longer than allowed by code style

Line is longer than allowed by code style (\> 120 columns)

$this
->indexUpdateService
->updateAll();
}

$this->indexQueueService->dispatchQueueMessages($output);

$this->release();

$this->output->writeln('<info>Finished</info>', OutputInterface::VERBOSITY_VERBOSE);

return self::SUCCESS;
}

#[Required]
public function setIndexUpdateService(IndexUpdateService $indexUpdateService): void
{
$this->indexUpdateService = $indexUpdateService;
}

#[Required]
public function setIndexQueueService(IndexQueueService $indexQueueService): void
{
$this->indexQueueService = $indexQueueService;
}

}
2 changes: 1 addition & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* @license http://www.pimcore.org/license PCL
*/

namespace Pimcore\Bundle\xTemplateBundlex\Controller;
namespace Pimcore\Bundle\GenericDataIndexBundle\Controller;

Check warning on line 14 in src/Controller/DefaultController.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Class path doesn't match project structure

Namespace name doesn't match the PSR-0/PSR-4 project structure

use Symfony\Component\HttpFoundation\Response;

Expand Down
Loading

0 comments on commit f641bf2

Please sign in to comment.