Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
IndexHandler.php
Go to the documentation of this file.
1 <?php
6 declare(strict_types=1);
7 
9 
15 
20 {
24  private $indexNameResolver;
25 
29  private $batch;
30 
34  private $resourceConnection;
35 
39  private $batchSize;
40 
47  public function __construct(
48  IndexNameResolverInterface $indexNameResolver,
49  Batch $batch,
50  ResourceConnection $resourceConnection,
51  $batchSize
52  ) {
53  $this->indexNameResolver = $indexNameResolver;
54  $this->batch = $batch;
55  $this->resourceConnection = $resourceConnection;
56  $this->batchSize = $batchSize;
57  }
58 
62  public function saveIndex(IndexName $indexName, \Traversable $documents, string $connectionName): void
63  {
64  $connection = $this->resourceConnection->getConnection($connectionName);
65  $tableName = $this->indexNameResolver->resolveName($indexName);
66 
68  foreach ($this->batch->getItems($documents, $this->batchSize) as $batchDocuments) {
69  $connection->insertArray($tableName, $columns, $batchDocuments);
70  }
71  }
72 
76  public function cleanIndex(IndexName $indexName, \Traversable $documents, string $connectionName): void
77  {
78  $connection = $this->resourceConnection->getConnection($connectionName);
79  $tableName = $this->indexNameResolver->resolveName($indexName);
80  $connection->delete($tableName, ['sku IN (?)' => iterator_to_array($documents)]);
81  }
82 }
$tableName
Definition: trigger.php:13
saveIndex(IndexName $indexName, \Traversable $documents, string $connectionName)
cleanIndex(IndexName $indexName, \Traversable $documents, string $connectionName)
$columns
Definition: default.phtml:15
__construct(IndexNameResolverInterface $indexNameResolver, Batch $batch, ResourceConnection $resourceConnection, $batchSize)
$connection
Definition: bulk.php:13