first commit

This commit is contained in:
2025-08-02 16:30:27 +02:00
commit 23646bfcee
14851 changed files with 1750626 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace KupShop\AdminBundle;
use KupShop\CatalogBundle\Search\FulltextElastic;
use KupShop\KupShopBundle\Context\ContextManager;
use KupShop\KupShopBundle\Context\LanguageContext;
use KupShop\KupShopBundle\Util\Compat\ServiceContainer;
trait FulltextUpdatesTrait
{
private FulltextElastic $_fulltextElastic;
private ContextManager $_contextManager;
protected function updateProductsFulltext(array $productIds): void
{
$this->forEachFulltextLanguage(function () use ($productIds) {
$this->getFulltextElastic()->updateProductFulltext($productIds);
$this->getFulltextElastic()->updateProductsAttributes($productIds);
});
}
protected function updateIndices(string $type = 'all'): void
{
$this->forEachFulltextLanguage(fn () => $this->getFulltextElastic()->updateIndex($type));
}
private function forEachFulltextLanguage(callable $callback)
{
$this->getContextManager()->deactivateUser(function () use ($callback) {
foreach ($this->getFulltextElastic()->getFulltextLanguages() as $language) {
$this->getContextManager()->activateContexts([LanguageContext::class => $language->getId()],
fn () => $callback(),
);
}
});
}
private function getFulltextElastic(): FulltextElastic
{
return $this->_fulltextElastic ??= ServiceContainer::getService(FulltextElastic::class);
}
private function getContextManager(): ContextManager
{
return $this->_contextManager ??= ServiceContainer::getService(ContextManager::class);
}
}