custom/plugins/UandiAvailabilityFilter/src/Service/ElasticsearchHelperDecorator.php line 83

Open in your IDE?
  1. <?php declare(strict_types=1);
  2. namespace Uandi\UandiAvailabilityFilter\Service;
  3. use ONGR\ElasticsearchDSL\Search;
  4. use Shopware\Core\Framework\Context;
  5. use Shopware\Core\Framework\DataAbstractionLayer\EntityDefinition;
  6. use Shopware\Core\Framework\DataAbstractionLayer\Search\Criteria;
  7. use Shopware\Elasticsearch\Framework\ElasticsearchHelper;
  8. use Swag\EnterpriseSearch\Relevance\InvalidContextSourceException;
  9. use Swag\EnterpriseSearch\Relevance\TermQueryBuilder;
  10. /**
  11.  * Implement decorator using EnterpriseSearch as code base
  12.  *  to handle logging in `logAndThrowException()` method.
  13.  *
  14.  * @deprecated: Seems to be implemented already in the same way by Shopware.
  15.  *
  16.  * @see \Swag\EnterpriseSearch\Relevance\Bridge\ElasticsearchHelperDecorator
  17.  */
  18. class ElasticsearchHelperDecorator extends ElasticsearchHelper
  19. {
  20.     private ElasticsearchHelper $decorated;
  21.     private $termQueryBuilder;
  22.     /**
  23.      * @param ElasticsearchHelper $decorated
  24.      * @param TermQueryBuilder $termQueryBuilder
  25.      */
  26.     public function __construct(
  27.         ElasticsearchHelper $decorated,
  28.         TermQueryBuilder $termQueryBuilder
  29.     ) {
  30.         $this->decorated $decorated;
  31.         $this->termQueryBuilder $termQueryBuilder;
  32.     }
  33.     public function addTerm(Criteria $criteriaSearch $searchContext $context, ?EntityDefinition $definition null): void
  34.     {
  35.         if ($definition) {
  36.             try {
  37.                 $this->termQueryBuilder->addTermQuery($definition$criteria$search$context);
  38.             } catch (InvalidContextSourceException $e) {
  39.                 $this->decorated->addTerm($criteria$search$context$definition);
  40.             }
  41.             return;
  42.         }
  43.         $this->decorated->addTerm($criteria$search$context$definition);
  44.     }
  45.     public function logOrThrowException(\Throwable $exception): bool
  46.     {
  47.         return $this->decorated->logOrThrowException($exception);
  48.     }
  49.     /**
  50.      * @throws \Throwable
  51.      */
  52.     public function logAndThrowException(\Throwable $exception): bool
  53.     {
  54.         if (method_exists($this->decorated'logAndThrowException')) {
  55.             return $this->decorated->logAndThrowException($exception);
  56.         }
  57.         return false;
  58.     }
  59.     public function getIndexName(EntityDefinition $definitionstring $languageId): string
  60.     {
  61.         return $this->decorated->getIndexName($definition$languageId);
  62.     }
  63.     public function allowIndexing(): bool
  64.     {
  65.         return $this->decorated->allowIndexing();
  66.     }
  67.     public function allowSearch(EntityDefinition $definitionContext $context): bool
  68.     {
  69.         return $this->decorated->allowSearch($definition$context);
  70.     }
  71.     public function handleIds(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  72.     {
  73.         $this->decorated->handleIds($definition$criteria$search$context);
  74.     }
  75.     public function addFilters(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  76.     {
  77.         $this->decorated->addFilters($definition$criteria$search$context);
  78.     }
  79.     public function addPostFilters(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  80.     {
  81.         $this->decorated->addPostFilters($definition$criteria$search$context);
  82.     }
  83.     public function addQueries(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  84.     {
  85.         $this->decorated->addQueries($definition$criteria$search$context);
  86.     }
  87.     public function addSortings(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  88.     {
  89.         $this->decorated->addSortings($definition$criteria$search$context);
  90.     }
  91.     public function addAggregations(EntityDefinition $definitionCriteria $criteriaSearch $searchContext $context): void
  92.     {
  93.         $this->decorated->addAggregations($definition$criteria$search$context);
  94.     }
  95.     public function setEnabled(bool $enabled): ElasticsearchHelper
  96.     {
  97.         return $this->decorated->setEnabled($enabled);
  98.     }
  99.     public function isSupported(EntityDefinition $definition): bool
  100.     {
  101.         return $this->decorated->isSupported($definition);
  102.     }
  103. }