Skip to content

Commit 2fc6596

Browse files
committed
MAGETWO-95445: Category Flat Data indexer doesnt show status as reindex required after deleting store/storeview
- Delete abandoned tables in full reindex
1 parent 1f05fd8 commit 2fc6596

File tree

2 files changed

+38
-57
lines changed
  • app/code/Magento/Catalog

2 files changed

+38
-57
lines changed

app/code/Magento/Catalog/Helper/Product/Flat/Indexer.php

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -466,17 +466,6 @@ public function getFlatTableName($storeId)
466466
return sprintf('%s_%s', $this->getTable('catalog_product_flat'), $storeId);
467467
}
468468

469-
/**
470-
* Retrieve Catalog Product Flat Table name
471-
*
472-
* @param int $storeId
473-
* @return string
474-
*/
475-
private function getCategoryFlatTableName(int $storeId): string
476-
{
477-
return sprintf('%s_store_%s', $this->getTable('catalog_category_flat'), $storeId);
478-
}
479-
480469
/**
481470
* Retrieve loaded attribute by code
482471
*
@@ -526,25 +515,4 @@ public function deleteAbandonedStoreFlatTables()
526515
$connection->dropTable($table);
527516
}
528517
}
529-
530-
/**
531-
* Delete all category flat tables for not existing stores
532-
*
533-
* @return void
534-
*/
535-
public function deleteAbandonedStoreCategoryFlatTables()
536-
{
537-
$connection = $this->_resource->getConnection();
538-
$existentTables = $connection->getTables($connection->getTableName('catalog_category_flat_store_%'));
539-
$actualStoreTables = [];
540-
foreach ($this->_storeManager->getStores() as $store) {
541-
$actualStoreTables[] = $this->getCategoryFlatTableName($store->getId());
542-
}
543-
544-
$tablesToDelete = array_diff($existentTables, $actualStoreTables);
545-
546-
foreach ($tablesToDelete as $table) {
547-
$connection->dropTable($table);
548-
}
549-
}
550518
}

app/code/Magento/Catalog/Model/Indexer/Category/Flat/Action/Full.php

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
*/
66
namespace Magento\Catalog\Model\Indexer\Category\Flat\Action;
77

8-
use Magento\Framework\App\ResourceConnection;
9-
108
/**
119
* Class for full reindex flat categories
1210
*/
@@ -24,28 +22,6 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Flat\AbstractAction
2422
*/
2523
protected $allowTableChanges = true;
2624

27-
/**
28-
* @var \Magento\Catalog\Helper\Product\Flat\Indexer
29-
*/
30-
private $indexer;
31-
32-
/**
33-
* @param ResourceConnection $resource
34-
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
35-
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
36-
* @param \Magento\Catalog\Helper\Product\Flat\Indexer $indexer
37-
*/
38-
public function __construct(
39-
ResourceConnection $resource,
40-
\Magento\Store\Model\StoreManagerInterface $storeManager,
41-
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
42-
\Magento\Catalog\Helper\Product\Flat\Indexer $indexer = null
43-
) {
44-
$this->indexer = $indexer ?: \Magento\Framework\App\ObjectManager::getInstance()
45-
->get(\Magento\Catalog\Helper\Product\Flat\Indexer::class);
46-
parent::__construct($resource, $storeManager, $resourceHelper);
47-
}
48-
4925
/**
5026
* Add suffix to table name to show it is old
5127
*
@@ -196,6 +172,43 @@ protected function switchTables(array $stores = [])
196172
return $this;
197173
}
198174

175+
/**
176+
* Retrieve all actual Catalog Product Flat Table names
177+
*
178+
* @return string[]
179+
*/
180+
private function getActualStoreTablesForCategoryFlat(): array
181+
{
182+
$actualStoreTables = [];
183+
foreach ($this->storeManager->getStores() as $store) {
184+
$actualStoreTables[] = sprintf(
185+
'%s_store_%s',
186+
$this->connection->getTableName('catalog_category_flat'), $store->getId()
187+
);
188+
}
189+
190+
return $actualStoreTables;
191+
}
192+
193+
/**
194+
* Delete all category flat tables for not existing stores
195+
*
196+
* @return void
197+
*/
198+
private function deleteAbandonedStoreCategoryFlatTables(): void
199+
{
200+
$existentTables = $this->connection->getTables(
201+
$this->connection->getTableName('catalog_category_flat_store_%')
202+
);
203+
$actualStoreTables = $this->getActualStoreTablesForCategoryFlat();
204+
205+
$tablesToDelete = array_diff($existentTables, $actualStoreTables);
206+
207+
foreach ($tablesToDelete as $table) {
208+
$this->connection->dropTable($table);
209+
}
210+
}
211+
199212
/**
200213
* Transactional rebuild flat data from eav
201214
*
@@ -211,7 +224,7 @@ public function reindexAll()
211224
$stores = $this->storeManager->getStores();
212225
$this->populateFlatTables($stores);
213226
$this->switchTables($stores);
214-
$this->indexer->deleteAbandonedStoreCategoryFlatTables();
227+
$this->deleteAbandonedStoreCategoryFlatTables();
215228
$this->allowTableChanges = true;
216229

217230
return $this;

0 commit comments

Comments
 (0)