|
| 1 | +<?php |
| 2 | +/** |
| 3 | + * Copyright © Magento, Inc. All rights reserved. |
| 4 | + * See COPYING.txt for license details. |
| 5 | + */ |
| 6 | + |
| 7 | +declare(strict_types=1); |
| 8 | + |
| 9 | +namespace Magento\Theme\Model\Indexer\Design; |
| 10 | + |
| 11 | +use Magento\Framework\App\ResourceConnection; |
| 12 | +use Magento\Framework\Indexer\IndexStructureInterface; |
| 13 | +use Magento\Framework\Indexer\SaveHandler\Batch; |
| 14 | +use Magento\Framework\Indexer\SaveHandler\Grid; |
| 15 | +use Magento\Framework\Indexer\ScopeResolver\FlatScopeResolver; |
| 16 | +use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver; |
| 17 | + |
| 18 | +class IndexerHandler extends Grid |
| 19 | +{ |
| 20 | + /** |
| 21 | + * @var FlatScopeResolver |
| 22 | + */ |
| 23 | + private $flatScopeResolver; |
| 24 | + |
| 25 | + public function __construct( |
| 26 | + IndexStructureInterface $indexStructure, |
| 27 | + ResourceConnection $resource, |
| 28 | + Batch $batch, |
| 29 | + IndexScopeResolver $indexScopeResolver, |
| 30 | + FlatScopeResolver $flatScopeResolver, |
| 31 | + array $data, |
| 32 | + $batchSize = 100) |
| 33 | + { |
| 34 | + parent::__construct( |
| 35 | + $indexStructure, |
| 36 | + $resource, |
| 37 | + $batch, |
| 38 | + $indexScopeResolver, |
| 39 | + $flatScopeResolver, |
| 40 | + $data, |
| 41 | + $batchSize); |
| 42 | + |
| 43 | + $this->flatScopeResolver = $flatScopeResolver; |
| 44 | + } |
| 45 | + |
| 46 | + /** |
| 47 | + * Clean index table by truncation |
| 48 | + * |
| 49 | + * @inheritdoc |
| 50 | + */ |
| 51 | + public function cleanIndex($dimensions) |
| 52 | + { |
| 53 | + $adapter = $this->resource->getConnection('write'); |
| 54 | + $tableName = $this->flatScopeResolver->resolve($this->getIndexName(), $dimensions); |
| 55 | + if ($adapter->isTableExists($tableName)) { |
| 56 | + $adapter->truncateTable($tableName); |
| 57 | + } |
| 58 | + } |
| 59 | +} |
0 commit comments