Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat various improvement #1

Open
wants to merge 23 commits into
base: 2.0.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
f5ba947
Fix locale format
PierreGauthier Jan 20, 2025
1ec2f68
[Filter] #1326616 - Add missing oro system attribute
PierreGauthier Jan 20, 2025
b369422
Dispatch event before sending bulk data to gally
PierreGauthier Jan 20, 2025
c036353
Manage "inventory_status" field
PierreGauthier Jan 21, 2025
28be6d8
Manage price without combined price list
PierreGauthier Jan 21, 2025
b322a51
Normalize datetime attribute
PierreGauthier Jan 21, 2025
d8b4ea9
Manage scheduled reindex
PierreGauthier Jan 23, 2025
92139f1
Make datagrid list extendable
PierreGauthier Jan 23, 2025
142ffea
Add comment on class path string
PierreGauthier Jan 24, 2025
cce4017
Manage sourceField of type Select in query selected fields
PierreGauthier Jan 24, 2025
8998f4a
Fix config for suggestions entities
PierreGauthier Jan 24, 2025
bbb6ddc
Manage scheduled reindex with multiple entities
PierreGauthier Jan 24, 2025
9269f33
Manage Select Attribute in Expression Visitor
PierreGauthier Jan 27, 2025
24b1b52
Convert locale format in select normalizer
PierreGauthier Jan 27, 2025
aad9e86
[Search] #1328422 - Keep value field of select attribute when buildin…
PierreGauthier Feb 4, 2025
556e8d8
[Filter] #1328245 - Encapsulate query filter
PierreGauthier Jan 31, 2025
bd819ed
[Search] #1328422 - Keep value field of select attribute when buildin…
PierreGauthier Feb 4, 2025
93d9d97
[CI] Add phpunit in github action
PierreGauthier Feb 4, 2025
044d4e7
[Filters] Fix multiple filter with same field
PierreGauthier Feb 6, 2025
85d8f93
[SourceField] Add id sourceField for all entities
PierreGauthier Feb 7, 2025
3392c0c
[Filters] Fix multiple filter with same field
PierreGauthier Feb 7, 2025
df8e6ae
[Filters] Change from DataGrid extension to Listener
PierreGauthier Feb 6, 2025
02b3815
Add management of 'NIN' comparison operator
botisSmile Feb 14, 2025
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
2 changes: 2 additions & 0 deletions .github/workflows/qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ jobs:
run: php ./vendor/bin/php-cs-fixer fix --diff --dry-run src
- name: Phpstan
run: php ./vendor/bin/phpstan --memory-limit=1G analyse
- name: Phpunit
run: php ./vendor/bin/phpunit src
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,18 @@ composer require gally/oro-plugin:dev-master
- They should also appear in your Oro frontend when searching or browsing categories.
- And you're done !

## Devlopement

If you need to update indexation behavior, you need to test various way to run the reindex process in oro
Fisrt you need to test various combinations of these options of the reindex command :
```shell
bin/console oro:website-search:reindex
bin/console oro:website-search:reindex --scheduled # Async reindex with message queue
bin/console oro:website-search:reindex --website-id=3 # Specify the websites you want to reindex
bin/console oro:website-search:reindex --ids=1000-2000 # Specify the ids range you want to reindex
bin/console oro:website-search:reindex --class="Oro\Bundle\WebCatalogBundle\Entity\ContentNode" # Specify the entities you want to reindex
```

Then you need to test update of product of contentNode from oro backend (you need to have an active consumer for this).
You can run a consumer with the command `bin/console oro:message-queue:consume`.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "*",
"phpstan/phpstan": "*",
"phpunit/phpunit": "*"
"phpunit/phpunit": "~9"
},
"autoload": {
"psr-4": {
Expand Down
37 changes: 37 additions & 0 deletions src/Convertor/LocalizationConvertor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <[email protected]>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Convertor;

use Oro\Bundle\LocaleBundle\Entity\Localization;

class LocalizationConvertor
{
public static function getLocaleFormattingCode(Localization $localization): string
{
$pattern = '/^[a-z]{2}_[A-Z]{2}$/';

if (preg_match($pattern, $localization->getFormattingCode())) {
return $localization->getFormattingCode();
}

$code = $localization->getParentLocalization()?->getFormattingCode();

if (preg_match($pattern, $code)) {
return $code;
}

return 'en_US';
}
}
84 changes: 84 additions & 0 deletions src/Decorator/AddIndexNameInContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <[email protected]>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Decorator;

use Gally\OroPlugin\Indexer\Registry\IndexRegistry;
use Oro\Bundle\WebsiteSearchBundle\Engine\AsyncMessaging\ReindexMessageGranularizer;
use Oro\Bundle\WebsiteSearchBundle\Engine\Context\ContextTrait;

/**
* Add index name and message count in message before add them in the queue.
*/
class AddIndexNameInContext extends ReindexMessageGranularizer
{
use ContextTrait;

public function __construct(
private ReindexMessageGranularizer $decorated,
private IndexRegistry $indexRegistry,
) {
}

/**
* {@inheritDoc}
*/
public function setChunkSize($chunkSize)
{
$this->decorated->setChunkSize($chunkSize);
}

/**
* {@inheritDoc}
*/
public function process($entities, array $websites, array $context): iterable
{
$entityIds = $this->getContextEntityIds($context);
$isFullIndexation = empty($entityIds);

// Add index names in queue message in order to be able to update existing index.
if (!isset($context['indices_by_locale'])) {
$context['indices_by_locale'] = $this->indexRegistry->getIndicesByLocale();
}

$messageCount = [];
$childMessages = [];
foreach ($this->decorated->process($entities, $websites, $context) as $childMessage) {
$entityClass = reset($childMessage['class']);

foreach ($childMessage['context']['websiteIds'] ?? [] as $websiteId) {
if (!isset($messageCount[$entityClass][$websiteId])) {
$messageCount[$entityClass][$websiteId] = 0;
}
++$messageCount[$entityClass][$websiteId];
}

if (!isset($messageCount[$entityClass]['global'])) {
$messageCount[$entityClass]['global'] = 0;
}
++$messageCount[$entityClass]['global'];

$childMessages[] = $childMessage;
}

foreach ($childMessages as $childMessage) {
$entityClass = reset($childMessage['class']);
$childMessage['context']['indices_by_locale'] = $context['indices_by_locale'];
$childMessage['context']['message_count'] = $messageCount[$entityClass];
$childMessage['context']['is_full_indexation'] = $isFullIndexation;

yield $childMessage;
}
}
}
78 changes: 78 additions & 0 deletions src/Decorator/AddIndexNameInReindexMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <[email protected]>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Decorator;

use Oro\Bundle\WebsiteSearchBundle\Engine\Context\ContextTrait;
use Oro\Bundle\WebsiteSearchBundle\Engine\IndexerInputValidator;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* Add gally specific data validation for reindex messages.
*/
class AddIndexNameInReindexMessage extends IndexerInputValidator
{
use ContextTrait;

public function __construct(
private IndexerInputValidator $decorated,
) {
}

public function validateRequestParameters(array|string|null $classOrClasses, array $context): array
{
$parameters = $this->validateClassAndContext(['class' => $classOrClasses, 'context' => $context]);

return [$parameters['class'], $this->getContextWebsiteIds($parameters['context'])];
}

public function validateClassAndContext(array $parameters): array
{
$resolver = $this->decorated->getOptionResolver();
$this->configureClassOptions($resolver);
$this->configureGranulizeOptions($resolver);
$this->configureContextOptions($resolver);

return $resolver->resolve($parameters);
}

public function configureContextOptions(OptionsResolver $optionsResolver): void
{
$this->decorated->configureContextOptions($optionsResolver);

$optionsResolver->setDefault('context', function (OptionsResolver $resolver) {
$resolver->setDefined('indices_by_locale');
$resolver->setDefined('message_count');
$resolver->setDefined('is_full_indexation');
$resolver->setAllowedTypes('indices_by_locale', ['array']);
$resolver->setAllowedTypes('message_count', ['array']);
$resolver->setAllowedTypes('is_full_indexation', ['bool']);
});
}

public function configureClassOptions(OptionsResolver $optionsResolver): void
{
$this->decorated->configureClassOptions($optionsResolver);
}

public function configureEntityOptions(OptionsResolver $optionsResolver): void
{
$this->decorated->configureEntityOptions($optionsResolver);
}

public function configureGranulizeOptions(OptionsResolver $optionsResolver): void
{
$this->decorated->configureGranulizeOptions($optionsResolver);
}
}
1 change: 0 additions & 1 deletion src/Decorator/ProductIndexFieldsProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public function addForceIndexed(string $field): void

public function isForceIndexed(string $field): bool
{
// return true;
return $this->contextProvider->isGallyContext() || $this->productIndexAttributeProvider->isForceIndexed($field);
}
}
1 change: 1 addition & 0 deletions src/DependencyInjection/GallyOroExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.yml');
$loader->load('controllers.yml');

// Use class path in a string because this class might not exist if enterprise bundles are not installed.
if (class_exists('Oro\Bundle\WarehouseBundle\Provider\EnabledWarehousesProvider')) {
$loader->load('services/enterprise.yml');
}
Expand Down
62 changes: 62 additions & 0 deletions src/Entity/IndexBatchCount.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <[email protected]>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* Entity that record the messages received for an index in order to know when to install it.
*/
#[ORM\Entity]
#[ORM\Table(name: 'gally_index_batch_count')]
class IndexBatchCount
{
#[ORM\Id]
#[ORM\Column(name: 'index_name', type: 'string', length: 255)]
private string $indexName;

#[ORM\Column(name: 'message_count', type: 'integer')]
private int $messageCount = 1;

public function __construct(string $indexName)
{
$this->indexName = $indexName;
}

public function increment(): void
{
++$this->messageCount;
}

public function getIndexName(): string
{
return $this->indexName;
}

public function setIndexName(string $indexName): void
{
$this->indexName = $indexName;
}

public function getMessageCount(): int
{
return $this->messageCount;
}

public function setMessageCount(int $messageCount): void
{
$this->messageCount = $messageCount;
}
}
43 changes: 43 additions & 0 deletions src/Indexer/Event/BeforeSaveIndexDataEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade Gally to newer versions in the future.
*
* @package Gally
* @author Gally Team <[email protected]>
* @copyright 2024-present Smile
* @license Open Software License v. 3.0 (OSL-3.0)
*/

declare(strict_types=1);

namespace Gally\OroPlugin\Indexer\Event;

use Symfony\Contracts\EventDispatcher\Event;

class BeforeSaveIndexDataEvent extends Event
{
public const NAME = 'gally.indexer.before_save_index_data';

public function __construct(
private string $class,
private array $data
) {
}

public function setData(array $data): void
{
$this->data = $data;
}

public function getData(): array
{
return $this->data;
}

public function getClass(): string
{
return $this->class;
}
}
4 changes: 4 additions & 0 deletions src/Indexer/IndexDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@ private function prepareIndexData(
);
}

/**
* @var string $fieldName
* @var array $values
*/
foreach ($this->toArray($fieldsValues) as $fieldName => $values) {
$singleValueFieldName = $this->cleanFieldName((string) $fieldName);
foreach ($this->toArray($values) as $value) {
Expand Down
Loading