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

Instantiate adapter via factory #63

Merged
merged 2 commits into from
Jun 25, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
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>
Loading