Skip to content

Commit

Permalink
🔧 instantiate adapter via factory
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gowrizrh committed Jun 25, 2024
1 parent 5422ab6 commit 556f3f0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 30 deletions.
15 changes: 11 additions & 4 deletions Model/Indexer/AsyncEventSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
]
Expand Down
26 changes: 0 additions & 26 deletions etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@
<type name="Aligent\AsyncEvents\Model\Indexer\AsyncEventSubscriber">
<arguments>
<argument name="dimensionProvider" xsi:type="object" shared="false">\Aligent\AsyncEvents\Model\Indexer\AsyncEventDimensionProvider</argument>
<argument name="dataMapperAdapter" xsi:type="object">dataMapperAdapter</argument>
<argument name="indexStructure" xsi:type="object">dataMapperIndexStructure</argument>
</arguments>
</type>

Expand All @@ -106,16 +104,6 @@
</arguments>
</type>

<type name="Magento\Elasticsearch\Model\Adapter\BatchDataMapper\DataMapperFactory">
<arguments>
<argument name="dataMappers" xsi:type="array">
<item name="async_event" xsi:type="string">
\Aligent\AsyncEvents\Model\Adapter\BatchDataMapper\AsyncEventLogMapper
</item>
</argument>
</arguments>
</type>

<type name="Magento\Elasticsearch\Model\Adapter\FieldMapper\FieldMapperResolver">
<arguments>
<argument name="fieldMappers" xsi:type="array">
Expand All @@ -130,18 +118,4 @@
<plugin name="map_string_scope_to_int"
type="Aligent\AsyncEvents\Plugin\MapStringScopeToInt"/>
</type>

<virtualType name="dataMapperIndexStructure" type="Magento\Elasticsearch\Model\Indexer\IndexStructure">
<arguments>
<argument name="adapter" xsi:type="object">
dataMapperAdapter
</argument>
</arguments>
</virtualType>

<virtualType name="dataMapperAdapter" type="Magento\Elasticsearch\Model\Adapter\Elasticsearch\Proxy">
<arguments>
<argument name="batchDocumentDataMapper" xsi:type="object">\Aligent\AsyncEvents\Model\Adapter\BatchDataMapper\AsyncEventLogMapper</argument>
</arguments>
</virtualType>
</config>

0 comments on commit 556f3f0

Please sign in to comment.