From 556f3f02726fcf7b1e30b0d6077f1a9faed4ae41 Mon Sep 17 00:00:00 2001 From: Gowri Date: Tue, 25 Jun 2024 09:40:00 +0930 Subject: [PATCH 1/2] :wrench: instantiate adapter via factory instantiation happens after the config check so when the search node isn't available, it early returns. the previous proxy approach worked but broke other things bc virtual types of proxy types can't seem to have constructor arguments overridden via dependency injection. --- Model/Indexer/AsyncEventSubscriber.php | 15 +++++++++++---- etc/di.xml | 26 -------------------------- 2 files changed, 11 insertions(+), 30 deletions(-) diff --git a/Model/Indexer/AsyncEventSubscriber.php b/Model/Indexer/AsyncEventSubscriber.php index c6ce5dd..eb0bf12 100644 --- a/Model/Indexer/AsyncEventSubscriber.php +++ b/Model/Indexer/AsyncEventSubscriber.php @@ -5,11 +5,12 @@ namespace Aligent\AsyncEvents\Model\Indexer; use Aligent\AsyncEvents\Helper\Config; +use Aligent\AsyncEvents\Model\Adapter\BatchDataMapper\AsyncEventLogMapper; use Aligent\AsyncEvents\Model\Indexer\DataProvider\AsyncEventSubscriberLogs; use Aligent\AsyncEvents\Model\Resolver\AsyncEvent; use ArrayIterator; use Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory; -use Magento\Elasticsearch\Model\Adapter\Elasticsearch; +use Magento\Elasticsearch\Model\Adapter\ElasticsearchFactory; use Magento\Framework\App\DeploymentConfig; use Magento\Framework\App\ObjectManager; use Magento\Framework\Indexer\ActionInterface as IndexerActionInterface; @@ -59,7 +60,8 @@ class AsyncEventSubscriber implements * @param AsyncEvent $asyncEventScopeResolver * @param IndexStructure $indexStructure * @param Config $config - * @param Elasticsearch $dataMapperAdapter + * @param ElasticsearchFactory $adapterFactory + * @param AsyncEventLogMapper $loggerMapper * @param array $data * @param int|null $batchSize * @param DeploymentConfig|null $deploymentConfig @@ -71,7 +73,8 @@ public function __construct( private readonly AsyncEvent $asyncEventScopeResolver, private readonly IndexStructureInterface $indexStructure, private readonly Config $config, - private readonly Elasticsearch $dataMapperAdapter, + private readonly ElasticsearchFactory $adapterFactory, + private readonly AsyncEventLogMapper $loggerMapper, private readonly array $data, int $batchSize = null, DeploymentConfig $deploymentConfig = null @@ -99,10 +102,14 @@ public function executeByDimensions(array $dimensions, ?Traversable $entityIds) return; } + $adapter = $this->adapterFactory->create([ + 'batchDocumentDataMapper' => $this->loggerMapper + ]); + $saveHandler = $this->indexerHandlerFactory->create( [ 'data' => $this->data, - 'adapter' => $this->dataMapperAdapter, + 'adapter' => $adapter, 'scopeResolver' => $this->asyncEventScopeResolver, 'indexStructure' => $this->indexStructure ] diff --git a/etc/di.xml b/etc/di.xml index 4dda31a..3d41b75 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -94,8 +94,6 @@ \Aligent\AsyncEvents\Model\Indexer\AsyncEventDimensionProvider - dataMapperAdapter - dataMapperIndexStructure @@ -106,16 +104,6 @@ - - - - - \Aligent\AsyncEvents\Model\Adapter\BatchDataMapper\AsyncEventLogMapper - - - - - @@ -130,18 +118,4 @@ - - - - - dataMapperAdapter - - - - - - - \Aligent\AsyncEvents\Model\Adapter\BatchDataMapper\AsyncEventLogMapper - - From 9cfeef68163e64d4f387e91f7d3a31c0a8419492 Mon Sep 17 00:00:00 2001 From: Gowri Date: Tue, 25 Jun 2024 09:50:05 +0930 Subject: [PATCH 2/2] :wrench: remove undefined reference --- etc/di.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/etc/di.xml b/etc/di.xml index 3d41b75..f969144 100644 --- a/etc/di.xml +++ b/etc/di.xml @@ -99,7 +99,6 @@ - dataMapperAdapter \Aligent\AsyncEvents\Model\Resolver\AsyncEvent