From 089788bbb4bd05c9dca1423e36846e42fa7ea825 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Wed, 7 Jun 2017 08:36:20 +0300 Subject: [PATCH 1/5] MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching --- .../Model/ResourceModel/Indexer/Stock.php | 35 +------ .../ResourceModel/Selection/Collection.php | 95 +----------------- .../Selection/CollectionTest.php | 17 +--- app/code/Magento/Bundle/composer.json | 3 +- app/code/Magento/Bundle/etc/di.xml | 12 +-- .../Category/Product/AbstractAction.php | 14 +-- .../Indexer/Category/Product/Action/Full.php | 46 +++------ .../Indexer/Product/Eav/AbstractAction.php | 17 +--- .../Model/Indexer/Product/Eav/Action/Full.php | 19 +++- .../Indexer/Product/Price/AbstractAction.php | 17 +--- .../Indexer/Product/Price/Action/Full.php | 29 ++++-- .../Indexer/ActiveTableSwitcher.php | 48 +++++++++ .../ResourceModel/Layer/Filter/Attribute.php | 31 ------ .../ResourceModel/Layer/Filter/Decimal.php | 31 ------ .../ResourceModel/Layer/Filter/Price.php | 19 +--- .../Catalog/Model/ResourceModel/Product.php | 17 +--- .../ResourceModel/Product/Collection.php | 28 +----- .../Product/Indexer/Eav/AbstractEav.php | 37 +------ .../Product/Indexer/Eav/Source.php | 10 +- ...LinkedProductSelectBuilderByIndexPrice.php | 13 +-- .../Product/Indexer/Price/DefaultPrice.php | 27 +---- .../Catalog/Model/ResourceModel/Url.php | 14 +-- .../Magento/Catalog/Setup/UpgradeSchema.php | 79 ++++++++------- .../Product/Eav/AbstractActionTest.php | 15 +-- .../Indexer/Product/Eav/Action/FullTest.php | 15 ++- .../Unit/Model/Product/Type/PriceTest.php | 10 -- .../Indexer/ActiveTableSwitcherTest.php | 47 +++++++++ .../Layer/Filter/AttributeTest.php | 44 --------- .../Layer/Filter/DecimalTest.php | 44 --------- .../ResourceModel/Layer/Filter/PriceTest.php | 18 ++-- .../Product/Indexer/Eav/SourceTest.php | 61 ------------ ...edProductSelectBuilderByIndexPriceTest.php | 15 +-- .../Indexer/Price/DefaultPriceTest.php | 21 +--- app/code/Magento/Catalog/etc/di.xml | 72 -------------- .../Model/Indexer/Stock/AbstractAction.php | 13 +-- .../Model/Indexer/Stock/Action/Full.php | 21 ++-- .../Model/Indexer/Stock/CacheCleaner.php | 14 +-- .../Indexer/Stock/DefaultStock.php | 42 +------- .../StockStatusBaseSelectProcessor.php | 17 +--- .../Stock/Item/StockItemCriteriaMapper.php | 14 +-- .../Model/ResourceModel/Stock/Status.php | 19 +--- .../CatalogInventory/Setup/UpgradeSchema.php | 10 +- .../Model/Indexer/Stock/CacheCleanerTest.php | 18 +--- .../Indexer/Stock/DefaultStockTest.php | 67 ------------- .../StockStatusBaseSelectProcessorTest.php | 16 +-- .../Model/ResourceModel/Stock/StatusTest.php | 50 ---------- .../Magento/CatalogInventory/composer.json | 3 +- app/code/Magento/CatalogInventory/etc/di.xml | 37 ------- .../Mysql/Aggregation/DataProvider.php | 40 +------- .../Adapter/Mysql/Dynamic/DataProvider.php | 13 +-- .../Adapter/Mysql/Filter/Preprocessor.php | 14 +-- .../Aggregation/Category/DataProvider.php | 15 +-- .../ResourceModel/Advanced/Collection.php | 11 +-- .../ResourceModel/Fulltext/Collection.php | 11 +-- .../Search/FilterMapper/ExclusionStrategy.php | 29 +----- .../FilterMapper/TermDropdownStrategy.php | 24 +---- .../Model/Search/IndexBuilder.php | 11 +-- .../Mysql/Aggregation/DataProviderTest.php | 39 +------- .../Mysql/Dynamic/DataProviderTest.php | 11 --- .../Adapter/Mysql/Filter/PreprocessorTest.php | 18 ---- .../ResourceModel/Advanced/CollectionTest.php | 20 ---- .../ResourceModel/Fulltext/CollectionTest.php | 5 - .../FilterMapper/ExclusionStrategyTest.php | 21 +--- .../FilterMapper/TermDropdownStrategyTest.php | 24 ++--- .../Unit/Model/Search/IndexBuilderTest.php | 14 --- app/code/Magento/CatalogSearch/composer.json | 1 - app/code/Magento/CatalogSearch/etc/di.xml | 29 ------ .../Model/Rule/Condition/Product.php | 13 +-- .../Unit/Model/Rule/Condition/ProductTest.php | 15 --- app/code/Magento/CatalogWidget/composer.json | 1 - app/code/Magento/CatalogWidget/etc/di.xml | 5 - .../Indexer/Stock/Configurable.php | 35 +------ .../Magento/ConfigurableProduct/composer.json | 3 +- .../Magento/ConfigurableProduct/etc/di.xml | 5 - .../ResourceModel/Indexer/Stock/Grouped.php | 36 +------ app/code/Magento/GroupedProduct/composer.json | 1 - app/code/Magento/GroupedProduct/etc/di.xml | 5 - app/code/Magento/Indexer/Model/Indexer.php | 4 - .../Magento/Indexer/Model/Indexer/State.php | 21 ---- .../Model/ResourceModel/FrontendResource.php | 81 --------------- .../Magento/Indexer/Setup/UpgradeSchema.php | 53 ---------- .../ResourceModel/FrontendResourceTest.php | 98 ------------------- .../Model/ResourceModel/Indexer/StockTest.php | 7 +- .../Product/Indexer/Eav/SourceTest.php | 10 +- .../Model/Indexer/Stock/Action/FullTest.php | 7 +- .../Model/Indexer/Stock/Action/RowTest.php | 7 +- .../Model/Indexer/Stock/Action/RowsTest.php | 7 +- .../Indexer/Stock/ConfigurableTest.php | 7 +- .../Product/Indexer/Stock/GroupedTest.php | 7 +- .../Framework/Indexer/StateInterface.php | 2 - 90 files changed, 329 insertions(+), 1812 deletions(-) create mode 100644 app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php create mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php delete mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/AttributeTest.php delete mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/DecimalTest.php delete mode 100644 app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php delete mode 100644 app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Indexer/Stock/DefaultStockTest.php delete mode 100644 app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Stock/StatusTest.php delete mode 100644 app/code/Magento/Indexer/Model/ResourceModel/FrontendResource.php delete mode 100644 app/code/Magento/Indexer/Setup/UpgradeSchema.php delete mode 100644 app/code/Magento/Indexer/Test/Unit/Model/ResourceModel/FrontendResourceTest.php diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php index f9fbfa0ac59ef..cdba9e1d62d62 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php @@ -6,6 +6,7 @@ namespace Magento\Bundle\Model\ResourceModel\Indexer; use Magento\Catalog\Api\Data\ProductInterface; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; /** @@ -15,36 +16,6 @@ */ class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - - /** - * Class constructor - * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param string $connectionName - * @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource - */ - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null - ) { - parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName, $stateFactory); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); - } - /** * Retrieve table name for temporary bundle option stock index * @@ -67,8 +38,8 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT $this->_cleanBundleOptionStockData(); $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() - : $this->indexerStockFrontendResource->getMainTable(); + ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $connection = $this->getConnection(); $select = $connection->select()->from( diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php index 9db1024eb4537..bb790816a94ca 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Selection/Collection.php @@ -44,99 +44,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection */ private $websiteScopePriceJoined = false; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - - /** - * Collection constructor. - * @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory - * @param \Psr\Log\LoggerInterface $logger - * @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy - * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\ResourceConnection $resource - * @param \Magento\Eav\Model\EntityFactory $eavEntityFactory - * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper - * @param \Magento\Framework\Validator\UniversalFactory $universalFactory - * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Framework\Module\Manager $moduleManager - * @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory - * @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl - * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate - * @param \Magento\Customer\Model\Session $customerSession - * @param \Magento\Framework\Stdlib\DateTime $dateTime - * @param GroupManagementInterface $groupManagement - * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection - * @param ProductLimitationFactory|null $productLimitationFactory - * @param MetadataPool|null $metadataPool - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerStockFrontendResource - * - * @SuppressWarnings(PHPMD.ExcessiveParameterList) - * @SuppressWarnings(Magento.TypeDuplication) - */ - public function __construct( - \Magento\Framework\Data\Collection\EntityFactory $entityFactory, - \Psr\Log\LoggerInterface $logger, - \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\ResourceConnection $resource, - \Magento\Eav\Model\EntityFactory $eavEntityFactory, - \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, - \Magento\Framework\Validator\UniversalFactory $universalFactory, - \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Framework\Module\Manager $moduleManager, - \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory, - \Magento\Catalog\Model\ResourceModel\Url $catalogUrl, - \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, - \Magento\Customer\Model\Session $customerSession, - \Magento\Framework\Stdlib\DateTime $dateTime, - GroupManagementInterface $groupManagement, - \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, - ProductLimitationFactory $productLimitationFactory = null, - MetadataPool $metadataPool = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null - ) { - parent::__construct( - $entityFactory, - $logger, - $fetchStrategy, - $eventManager, - $eavConfig, - $resource, - $eavEntityFactory, - $resourceHelper, - $universalFactory, - $storeManager, - $moduleManager, - $catalogProductFlatState, - $scopeConfig, - $productOptionFactory, - $catalogUrl, - $localeDate, - $customerSession, - $dateTime, - $groupManagement, - $connection, - $productLimitationFactory, - $metadataPool, - $indexerFrontendResource, - $categoryProductIndexerFrontend - ); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); - } - /** * Initialize collection * @@ -261,7 +168,7 @@ public function addQuantityFilter() { $this->getSelect() ->joinInner( - ['stock' => $this->indexerStockFrontendResource->getMainTable()], + ['stock' => $this->getTable('cataloginventory_stock_status')], 'selection.product_id = stock.product_id', [] ) diff --git a/app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php b/app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php index f2421060a4fec..7c4c2f3056757 100644 --- a/app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php +++ b/app/code/Magento/Bundle/Test/Unit/Model/ResourceModel/Selection/CollectionTest.php @@ -6,7 +6,6 @@ namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Store\Model\StoreManagerInterface; use Magento\Store\Api\Data\StoreInterface; use Magento\Framework\Validator\UniversalFactory; @@ -17,15 +16,9 @@ /** * Class CollectionTest. - * Unit test for \Magento\Indexer\Model\ResourceModel\FrontendResource. */ class CollectionTest extends \PHPUnit_Framework_TestCase { - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResource; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -64,9 +57,6 @@ class CollectionTest extends \PHPUnit_Framework_TestCase protected function setUp() { $objectManager = new ObjectManager($this); - $this->frontendResource = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->storeManager = $this->getMockBuilder(StoreManagerInterface::class) ->disableOriginalConstructor() ->getMock(); @@ -114,8 +104,7 @@ protected function setUp() [ 'storeManager' => $this->storeManager, 'universalFactory' => $this->universalFactory, - 'productLimitationFactory' => $factory, - 'indexerStockFrontendResource' => $this->frontendResource + 'productLimitationFactory' => $factory ] ); } @@ -123,8 +112,8 @@ protected function setUp() public function testAddQuantityFilter() { $tableName = 'cataloginventory_stock_status'; - $this->frontendResource->expects($this->once()) - ->method('getMainTable') + $this->entity->expects($this->once()) + ->method('getTable') ->willReturn($tableName); $this->select->expects($this->once()) ->method('joinInner') diff --git a/app/code/Magento/Bundle/composer.json b/app/code/Magento/Bundle/composer.json index 661cccac0b46c..a839c110402d5 100644 --- a/app/code/Magento/Bundle/composer.json +++ b/app/code/Magento/Bundle/composer.json @@ -18,8 +18,7 @@ "magento/framework": "100.2.*", "magento/module-quote": "100.2.*", "magento/module-media-storage": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-indexer": "100.2.*" + "magento/module-ui": "100.2.*" }, "suggest": { "magento/module-webapi": "100.2.*", diff --git a/app/code/Magento/Bundle/etc/di.xml b/app/code/Magento/Bundle/etc/di.xml index 4d039553ff351..f1c585f3573fc 100644 --- a/app/code/Magento/Bundle/etc/di.xml +++ b/app/code/Magento/Bundle/etc/di.xml @@ -155,19 +155,9 @@ - + 136 - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php index 5704bc4b2cbfd..2e83047be8db8 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/AbstractAction.php @@ -11,7 +11,6 @@ use Magento\Framework\DB\Query\Generator as QueryGenerator; use Magento\Framework\App\ResourceConnection; use Magento\Framework\EntityManager\MetadataPool; -use Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource as CategoryProductFrontend; /** * Class AbstractAction @@ -112,24 +111,17 @@ abstract class AbstractAction */ private $queryGenerator; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * @param ResourceConnection $resource * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Catalog\Model\Config $config * @param QueryGenerator $queryGenerator - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend */ public function __construct( \Magento\Framework\App\ResourceConnection $resource, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Catalog\Model\Config $config, - QueryGenerator $queryGenerator = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + QueryGenerator $queryGenerator = null ) { $this->resource = $resource; $this->connection = $resource->getConnection(); @@ -137,8 +129,6 @@ public function __construct( $this->config = $config; $this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance() ->get(QueryGenerator::class); - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend - ?: \Magento\Framework\App\ObjectManager::getInstance()->get(CategoryProductFrontend::class); } /** @@ -185,7 +175,7 @@ protected function getTable($table) */ protected function getMainTable() { - return $this->categoryProductIndexerFrontend->getMainTable(); + return $this->getTable(self::MAIN_INDEX_TABLE); } /** diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php index 80ca443a76555..3f935a5b4ed02 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php @@ -5,6 +5,7 @@ */ namespace Magento\Catalog\Model\Indexer\Category\Product\Action; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\Framework\DB\Query\Generator as QueryGenerator; use Magento\Framework\App\ResourceConnection; @@ -26,11 +27,6 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio */ private $batchProvider; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory - */ - private $indexerStateFactory; - /** * @var \Magento\Framework\EntityManager\MetadataPool */ @@ -43,6 +39,11 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio */ private $batchRowsCount; + /** + * @var ActiveTableSwitcher + */ + private $activeTableSwitcher; + /** * @param ResourceConnection $resource * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -53,6 +54,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool * @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory * @param int|null $batchRowsCount + * @param ActiveTableSwitcher|null $activeTableSwitcher */ public function __construct( \Magento\Framework\App\ResourceConnection $resource, @@ -62,8 +64,8 @@ public function __construct( \Magento\Framework\Indexer\BatchSizeManagementInterface $batchSizeManagement = null, \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null, \Magento\Framework\EntityManager\MetadataPool $metadataPool = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - $batchRowsCount = null + $batchRowsCount = null, + ActiveTableSwitcher $activeTableSwitcher = null ) { parent::__construct( $resource, @@ -81,10 +83,8 @@ public function __construct( $this->metadataPool = $metadataPool ?: $objectManager->get( \Magento\Framework\EntityManager\MetadataPool::class ); - $this->indexerStateFactory = $stateFactory ?: $objectManager->get( - \Magento\Indexer\Model\Indexer\StateFactory::class - ); $this->batchRowsCount = $batchRowsCount; + $this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class); } /** @@ -95,7 +95,7 @@ public function __construct( public function execute() { $this->reindex(); - + $this->activeTableSwitcher->switchTable($this->connection, $this->getMainTable()); return $this; } @@ -143,13 +143,13 @@ protected function removeUnnecessaryData() protected function publishData() { $select = $this->connection->select()->from($this->getMainTmpTable()); - $columns = array_keys($this->connection->describeTable($this->getMainTable())); + $tableName = $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; $this->connection->query( $this->connection->insertFromSelect( $select, - $this->getMainTable(), + $tableName, $columns, \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE ) @@ -236,24 +236,4 @@ private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSe $this->removeUnnecessaryData(); } } - - /** - * This overridden method returns ALTERNATIVE table name to work with. - * - * When the table used on frontend is 'catalog_category_product_index' this indexer should work - * with 'catalog_category_product_index_replica' and vice versa. - * - * @return string table name which is NOT used on frontend - */ - protected function getMainTable() - { - $table = $this->getTable(self::MAIN_INDEX_TABLE); - $indexerState = $this->indexerStateFactory->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID - ); - $destinationTableSuffix = ($indexerState->getTableSuffix() === '') - ? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX - : ''; - return $table . $destinationTableSuffix; - } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php index 6885a9dbe1574..cd40cddebea15 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/AbstractAction.php @@ -27,25 +27,17 @@ abstract class AbstractAction */ protected $_eavDecimalFactory; - /** - * @var array - */ - private $frontendResources; - /** * AbstractAction constructor. * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory - * @param array $frontendResources */ public function __construct( \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory, - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory, - $frontendResources = [] + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory ) { $this->_eavDecimalFactory = $eavDecimalFactory; $this->_eavSourceFactory = $eavSourceFactory; - $this->frontendResources = $frontendResources; } /** @@ -98,7 +90,7 @@ public function getIndexer($type) */ public function reindex($ids = null) { - foreach ($this->getIndexers() as $type => $indexer) { + foreach ($this->getIndexers() as $indexer) { if ($ids === null) { $indexer->reindexAll(); } else { @@ -107,10 +99,7 @@ public function reindex($ids = null) } $ids = $this->processRelations($indexer, $ids); $indexer->reindexEntities($ids); - $resource = isset($this->frontendResources[$type]) - ? $this->frontendResources[$type] - : $this->frontendResources['default']; - $destinationTable = $resource->getMainTable(); + $destinationTable = $indexer->getMainTable(); $this->syncData($indexer, $destinationTable, $ids); } } diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php index fdb933f714c3f..26b294394ea08 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php @@ -5,6 +5,8 @@ */ namespace Magento\Catalog\Model\Indexer\Product\Eav\Action; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; + /** * Class Full reindex action */ @@ -25,13 +27,18 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction */ private $batchSizeCalculator; + /** + * @var ActiveTableSwitcher + */ + private $activeTableSwitcher; + /** * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool * @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator - * @param array $frontendResources + * @param ActiveTableSwitcher|null $activeTableSwitcher */ public function __construct( \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory, @@ -39,9 +46,9 @@ public function __construct( \Magento\Framework\EntityManager\MetadataPool $metadataPool = null, \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator = null, - array $frontendResources = [] + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null ) { - parent::__construct($eavDecimalFactory, $eavSourceFactory, $frontendResources); + parent::__construct($eavDecimalFactory, $eavSourceFactory); $this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Framework\EntityManager\MetadataPool::class ); @@ -51,6 +58,9 @@ public function __construct( $this->batchSizeCalculator = $batchSizeCalculator ?: \Magento\Framework\App\ObjectManager::getInstance()->get( \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator::class ); + $this->activeTableSwitcher = $activeTableSwitcher ?: \Magento\Framework\App\ObjectManager::getInstance()->get( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ); } /** @@ -66,7 +76,7 @@ public function execute($ids = null) try { foreach ($this->getIndexers() as $indexerName => $indexer) { $connection = $indexer->getConnection(); - $mainTable = $indexer->getMainTable(); + $mainTable = $indexer->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; $connection->truncateTable($mainTable); $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $batches = $this->batchProvider->getBatches( @@ -87,6 +97,7 @@ public function execute($ids = null) $this->syncData($indexer, $mainTable); } } + $this->activeTableSwitcher->switchTable($indexer->getConnection(), $indexer->getMainTable()); } } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php index 9588d3f6ac4cf..28d80d39091fa 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/AbstractAction.php @@ -75,11 +75,6 @@ abstract class AbstractAction */ private $productResource; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerFrontendResource; - /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -89,7 +84,6 @@ abstract class AbstractAction * @param \Magento\Catalog\Model\Product\Type $catalogProductType * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource */ public function __construct( \Magento\Framework\App\Config\ScopeConfigInterface $config, @@ -99,8 +93,7 @@ public function __construct( \Magento\Framework\Stdlib\DateTime $dateTime, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory, - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource ) { $this->_config = $config; $this->_storeManager = $storeManager; @@ -111,10 +104,6 @@ public function __construct( $this->_indexerPriceFactory = $indexerPriceFactory; $this->_defaultIndexerResource = $defaultIndexerResource; $this->_connection = $this->_defaultIndexerResource->getConnection(); - $this->indexerFrontendResource = $indexerFrontendResource ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class - ); } /** @@ -515,13 +504,13 @@ protected function _copyRelationIndexData($parentIds, $excludeIds = null) /** * Retrieve index table that will be used for write operations. * - * This method is used during both partial and full reindex to identify the the table. + * This method is used during both partial and full reindex to identify the table. * * @return string */ protected function getIndexTargetTable() { - return $this->indexerFrontendResource->getMainTable(); + return $this->_defaultIndexerResource->getTable('catalog_product_index_price'); } /** diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php index 01d07e0cabd87..596a7876867a1 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php @@ -5,6 +5,7 @@ */ namespace Magento\Catalog\Model\Indexer\Product\Price\Action; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\Framework\App\ObjectManager; /** @@ -28,6 +29,11 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction */ private $batchProvider; + /** + * @var ActiveTableSwitcher + */ + private $activeTableSwitcher; + /** * @param \Magento\Framework\App\Config\ScopeConfigInterface $config * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -37,10 +43,11 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction * @param \Magento\Catalog\Model\Product\Type $catalogProductType * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator|null $batchSizeCalculator * @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider + * @param ActiveTableSwitcher|null $activeTableSwitcher + * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ public function __construct( @@ -52,10 +59,10 @@ public function __construct( \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\Factory $indexerPriceFactory, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice $defaultIndexerResource, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null, \Magento\Framework\EntityManager\MetadataPool $metadataPool = null, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator $batchSizeCalculator = null, - \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null + \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null, + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null ) { parent::__construct( $config, @@ -65,8 +72,7 @@ public function __construct( $dateTime, $catalogProductType, $indexerPriceFactory, - $defaultIndexerResource, - $indexerFrontendResource + $defaultIndexerResource ); $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get( \Magento\Framework\EntityManager\MetadataPool::class @@ -77,6 +83,9 @@ public function __construct( $this->batchProvider = $batchProvider ?: ObjectManager::getInstance()->get( \Magento\Framework\Indexer\BatchProviderInterface::class ); + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ); } /** @@ -94,6 +103,8 @@ public function execute($ids = null) $this->_prepareWebsiteDateTable(); $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); + $replicaTable = $this->_defaultIndexerResource->getMainTable() + . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; /** @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $indexer */ foreach ($this->getTypeIndexers() as $indexer) { @@ -130,13 +141,17 @@ public function execute($ids = null) $indexer->reindexEntity($entityIds); // Sync data from temp table to index table - $this->_insertFromTable($idxTableName, $this->_defaultIndexerResource->getMainTable()); + $this->_insertFromTable($idxTableName, $replicaTable); // Drop temporary index table $connection->dropTable($idxTableName); } } } + $this->activeTableSwitcher->switchTable( + $this->_defaultIndexerResource->getConnection(), + $this->_defaultIndexerResource->getMainTable() + ); } catch (\Exception $e) { throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e); } @@ -147,6 +162,6 @@ public function execute($ids = null) */ protected function getIndexTargetTable() { - return $this->_defaultIndexerResource->getMainTable(); + return $this->_defaultIndexerResource->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php new file mode 100644 index 0000000000000..e58ba039e31d4 --- /dev/null +++ b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php @@ -0,0 +1,48 @@ +renameTablesBatch( + [ + [ + 'oldName' => $tableName, + 'newName' => $outdatedTableName + ], + [ + 'oldName' => $replicaTableName, + 'newName' => $tableName + ], + [ + 'oldName' => $outdatedTableName, + 'newName' => $replicaTableName + ] + ] + ); + } +} diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Attribute.php b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Attribute.php index 096d7d02ccb3d..a846a32f064db 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Attribute.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Attribute.php @@ -5,8 +5,6 @@ */ namespace Magento\Catalog\Model\ResourceModel\Layer\Filter; -use Magento\Framework\App\ObjectManager; - /** * Catalog Layer Attribute Filter Resource Model * @@ -16,27 +14,6 @@ */ class Attribute extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $frontendResource; - - /** - * Attribute constructor. - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param null $connectionName - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource - */ - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - $connectionName = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null - ) { - $this->frontendResource = $frontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource::class); - parent::__construct($context, $connectionName); - } - /** * Initialize connection and define main table name * @@ -113,12 +90,4 @@ public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $fi return $connection->fetchPairs($select); } - - /** - * @inheritdoc - */ - public function getMainTable() - { - return $this->frontendResource->getMainTable(); - } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Decimal.php b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Decimal.php index 510edb97870a9..92c6622481fb9 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Decimal.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Decimal.php @@ -5,8 +5,6 @@ */ namespace Magento\Catalog\Model\ResourceModel\Layer\Filter; -use Magento\Framework\App\ObjectManager; - /** * Catalog Layer Decimal attribute Filter Resource Model * @@ -16,27 +14,6 @@ */ class Decimal extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb { - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $frontendResource; - - /** - * Attribute constructor. - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param null $connectionName - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource - */ - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - $connectionName = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null - ) { - $this->frontendResource = $frontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource::class); - parent::__construct($context, $connectionName); - } - /** * Initialize connection and define main table name * @@ -166,12 +143,4 @@ public function getCount(\Magento\Catalog\Model\Layer\Filter\FilterInterface $fi return $connection->fetchPairs($select); } - - /** - * @inheritdoc - */ - public function getMainTable() - { - return $this->frontendResource->getMainTable(); - } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Price.php b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Price.php index c65a56eb1aa04..2a503fda81e66 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Price.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Layer/Filter/Price.php @@ -40,11 +40,6 @@ class Price extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ private $storeManager; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerFrontendResource; - /** * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param \Magento\Framework\Event\ManagerInterface $eventManager @@ -52,7 +47,6 @@ class Price extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb * @param \Magento\Customer\Model\Session $session * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param null $connectionName - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $stateFactory */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, @@ -60,15 +54,12 @@ public function __construct( \Magento\Catalog\Model\Layer\Resolver $layerResolver, \Magento\Customer\Model\Session $session, \Magento\Store\Model\StoreManagerInterface $storeManager, - $connectionName = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $stateFactory = null + $connectionName = null ) { $this->layer = $layerResolver->get(); $this->session = $session; $this->storeManager = $storeManager; $this->_eventManager = $eventManager; - $this->indexerFrontendResource = $stateFactory ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class); parent::__construct($context, $connectionName); } @@ -393,12 +384,4 @@ protected function _getIndexTableAlias() { return 'price_index'; } - - /** - * @inheritdoc - */ - public function getMainTable() - { - return $this->indexerFrontendResource->getMainTable(); - } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product.php b/app/code/Magento/Catalog/Model/ResourceModel/Product.php index 17ef30b3983a5..7b29b42f600aa 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product.php @@ -79,11 +79,6 @@ class Product extends AbstractResource */ private $productCategoryLink; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * @param \Magento\Eav\Model\Entity\Context $context * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -95,7 +90,6 @@ class Product extends AbstractResource * @param \Magento\Eav\Model\Entity\TypeFactory $typeFactory * @param \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes * @param array $data - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -109,8 +103,7 @@ public function __construct( \Magento\Eav\Model\Entity\Attribute\SetFactory $setFactory, \Magento\Eav\Model\Entity\TypeFactory $typeFactory, \Magento\Catalog\Model\Product\Attribute\DefaultAttributes $defaultAttributes, - $data = [], - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + $data = [] ) { $this->_categoryCollectionFactory = $categoryCollectionFactory; $this->_catalogCategory = $catalogCategory; @@ -125,10 +118,6 @@ public function __construct( $data ); $this->connectionName = 'catalog'; - //virtual type have to be injected here. If not, we'll do it :) - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource::class - ); } /** @@ -375,7 +364,7 @@ public function getAvailableInCategories($object) if (!isset($this->availableCategoryIdsCache[$entityId])) { $this->availableCategoryIdsCache[$entityId] = $this->getConnection()->fetchCol( $this->getConnection()->select()->distinct()->from( - $this->categoryProductIndexerFrontend->getMainTable(), + $this->getTable('catalog_category_product_index'), ['category_id'] )->where( 'product_id = ? AND is_parent = 1', @@ -409,7 +398,7 @@ public function getDefaultAttributeSourceModel() public function canBeShowInCategory($product, $categoryId) { $select = $this->getConnection()->select()->from( - $this->categoryProductIndexerFrontend->getMainTable(), + $this->getTable('catalog_category_product_index'), 'product_id' )->where( 'product_id = ?', diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php index 1c9e55df7f880..7d8b16e60c3aa 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php @@ -18,7 +18,6 @@ use Magento\Framework\DB\Select; use Magento\Framework\EntityManager\MetadataPool; use Magento\Store\Model\Store; -use Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource as CategoryProductFrontend; /** * Product collection @@ -264,16 +263,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac */ private $metadataPool; - /** - * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - */ - private $indexerFrontendResource; - - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * @var bool|string */ @@ -309,11 +298,8 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Collection\Abstrac * @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection * @param ProductLimitationFactory|null $productLimitationFactory * @param MetadataPool|null $metadataPool - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend * * @SuppressWarnings(PHPMD.ExcessiveParameterList) - * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, @@ -337,9 +323,7 @@ public function __construct( GroupManagementInterface $groupManagement, \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, ProductLimitationFactory $productLimitationFactory = null, - MetadataPool $metadataPool = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + MetadataPool $metadataPool = null ) { $this->moduleManager = $moduleManager; $this->_catalogProductFlatState = $catalogProductFlatState; @@ -356,10 +340,6 @@ public function __construct( ); $this->_productLimitationFilters = $productLimitationFactory->create(); $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class); - $this->indexerFrontendResource = $indexerFrontendResource ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class); - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend - ?: \Magento\Framework\App\ObjectManager::getInstance()->get(CategoryProductFrontend::class); parent::__construct( $entityFactory, $logger, @@ -1213,7 +1193,7 @@ public function getProductCountSelect() )->distinct( false )->join( - ['count_table' => $this->categoryProductIndexerFrontend->getMainTable()], + ['count_table' => $this->getTable('catalog_category_product_index')], 'count_table.product_id = e.entity_id', [ 'count_table.category_id', @@ -1908,7 +1888,7 @@ protected function _productLimitationPrice($joinLeft = false) 'max_price', 'tier_price', ]; - $tableName = ['price_index' => $this->indexerFrontendResource->getMainTable()]; + $tableName = ['price_index' => $this->getTable('catalog_product_index_price')]; if ($joinLeft) { $select->joinLeft($tableName, $joinCond, $colls); } else { @@ -1986,7 +1966,7 @@ protected function _applyProductLimitations() $this->getSelect()->setPart(\Magento\Framework\DB\Select::FROM, $fromPart); } else { $this->getSelect()->join( - ['cat_index' => $this->categoryProductIndexerFrontend->getMainTable()], + ['cat_index' => $this->getTable('catalog_category_product_index')], $joinCond, ['cat_index_position' => 'position'] ); diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php index 8f4a47804c8ae..c4e3fb1bf1e70 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php @@ -23,16 +23,6 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\ */ protected $_eventManager = null; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory - */ - private $indexerStateFactory; - - /** - * @var mixed - */ - private $frontendResource; - /** * AbstractEav constructor. * @param \Magento\Framework\Model\ResourceModel\Db\Context $context @@ -41,22 +31,15 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\ * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param null $connectionName * @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null + $connectionName = null ) { $this->_eventManager = $eventManager; - $this->indexerStateFactory = $stateFactory ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Indexer\Model\Indexer\StateFactory::class); - $this->frontendResource = $frontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource::class); parent::__construct($context, $tableStrategy, $eavConfig, $connectionName); } @@ -316,22 +299,4 @@ protected function _synchronizeAttributeIndexData($attributeId) } return $this; } - - /** - * @inheritdoc - * Returns main table name in depends of the suffix stored in the 'indexer_state' table - * - * @return string - */ - public function getMainTable() - { - $table = parent::getMainTable(); - $indexerState = $this->indexerStateFactory->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - ); - $destinationTableSuffix = ($indexerState->getTableSuffix() === '') - ? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX - : ''; - return $table . $destinationTableSuffix; - } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php index 1acb6cc001067..5b68730209b40 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php @@ -33,8 +33,6 @@ class Source extends AbstractEav * @param \Magento\Framework\Event\ManagerInterface $eventManager * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper * @param null|string $connectionName - * @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, @@ -42,18 +40,14 @@ public function __construct( \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null + $connectionName = null ) { parent::__construct( $context, $tableStrategy, $eavConfig, $eventManager, - $connectionName, - $stateFactory, - $frontendResource + $connectionName ); $this->_resourceHelper = $resourceHelper; } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php index 3c592e4dc17c6..b4f7e43387d0e 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php @@ -38,11 +38,6 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild */ private $baseSelectProcessor; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerFrontendResource; - /** * LinkedProductSelectBuilderByIndexPrice constructor. * @param \Magento\Store\Model\StoreManagerInterface $storeManager @@ -50,15 +45,13 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild * @param \Magento\Customer\Model\Session $customerSession * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool * @param BaseSelectProcessorInterface|null $baseSelectProcessor - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource */ public function __construct( \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Framework\App\ResourceConnection $resourceConnection, \Magento\Customer\Model\Session $customerSession, \Magento\Framework\EntityManager\MetadataPool $metadataPool, - BaseSelectProcessorInterface $baseSelectProcessor = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null + BaseSelectProcessorInterface $baseSelectProcessor = null ) { $this->storeManager = $storeManager; $this->resource = $resourceConnection; @@ -66,8 +59,6 @@ public function __construct( $this->metadataPool = $metadataPool; $this->baseSelectProcessor = (null !== $baseSelectProcessor) ? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class); - $this->indexerFrontendResource = $indexerFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class); } /** @@ -89,7 +80,7 @@ public function build($productId) sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS), ['entity_id'] )->joinInner( - ['t' => $this->indexerFrontendResource->getMainTable()], + ['t' => $this->resource->getTableName('catalog_product_index_price')], sprintf('t.entity_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS), [] )->where('parent.entity_id = ?', $productId) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php index a613690209432..a007a116b6b34 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php @@ -51,11 +51,6 @@ class DefaultPrice extends AbstractIndexer implements PriceInterface */ private $hasEntity = null; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory - */ - private $indexerStateFactory; - /** * DefaultPrice constructor. * @@ -73,13 +68,10 @@ public function __construct( \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\Event\ManagerInterface $eventManager, \Magento\Framework\Module\Manager $moduleManager, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null + $connectionName = null ) { $this->_eventManager = $eventManager; $this->moduleManager = $moduleManager; - $this->indexerStateFactory = $stateFactory ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Indexer\Model\Indexer\StateFactory::class); parent::__construct($context, $tableStrategy, $eavConfig, $connectionName); } @@ -709,21 +701,4 @@ protected function hasEntity() return $this->hasEntity; } - - /** - * Returns main table name based on the suffix stored in the 'indexer_state' table - * - * {@inheritdoc} - */ - public function getMainTable() - { - $table = parent::getMainTable(); - $indexerState = $this->indexerStateFactory->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID - ); - $destinationTableSuffix = ($indexerState->getTableSuffix() === '') - ? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX - : ''; - return $table . $destinationTableSuffix; - } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Url.php b/app/code/Magento/Catalog/Model/ResourceModel/Url.php index f0058b9e57315..1cb2fed839dde 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Url.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Url.php @@ -101,11 +101,6 @@ class Url extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ protected $metadataPool; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * Url constructor. * @param \Magento\Framework\Model\ResourceModel\Db\Context $context @@ -115,7 +110,6 @@ class Url extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb * @param \Magento\Catalog\Model\Category $catalogCategory * @param \Psr\Log\LoggerInterface $logger * @param null $connectionName - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, @@ -124,17 +118,13 @@ public function __construct( Product $productResource, \Magento\Catalog\Model\Category $catalogCategory, \Psr\Log\LoggerInterface $logger, - $connectionName = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + $connectionName = null ) { $this->_storeManager = $storeManager; $this->_eavConfig = $eavConfig; $this->productResource = $productResource; $this->_catalogCategory = $catalogCategory; $this->_logger = $logger; - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource::class - ); parent::__construct($context, $connectionName); } @@ -666,7 +656,7 @@ public function getRewriteByProductStore(array $products) $connection = $this->getConnection(); $select = $connection->select()->from( - ['i' => $this->categoryProductIndexerFrontend->getMainTable()], + ['i' => $this->getTable('catalog_category_product_index')], ['product_id', 'store_id', 'visibility'] )->joinLeft( ['u' => $this->getMainTable()], diff --git a/app/code/Magento/Catalog/Setup/UpgradeSchema.php b/app/code/Magento/Catalog/Setup/UpgradeSchema.php index a6c28eed53e6d..e9b0a581b4858 100755 --- a/app/code/Magento/Catalog/Setup/UpgradeSchema.php +++ b/app/code/Magento/Catalog/Setup/UpgradeSchema.php @@ -20,24 +20,21 @@ class UpgradeSchema implements UpgradeSchemaInterface { /** * {@inheritdoc} + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) */ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); - if (version_compare($context->getVersion(), '2.0.1', '<')) { $this->addSupportVideoMediaAttributes($setup); $this->removeGroupPrice($setup); } - if (version_compare($context->getVersion(), '2.0.6', '<')) { $this->addUniqueKeyToCategoryProductTable($setup); } - if (version_compare($context->getVersion(), '2.1.4', '<')) { $this->addSourceEntityIdToProductEavIndex($setup); } - if (version_compare($context->getVersion(), '2.1.5', '<')) { $this->addPercentageValueColumn($setup); $tables = [ @@ -69,9 +66,42 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con } $this->recreateCatalogCategoryProductIndexTmpTable($setup); } - if (version_compare($context->getVersion(), '2.2.0', '<')) { - $this->addProductEavIndexReplicaTables($setup); + //remove fk from price index table + $setup->getConnection()->dropForeignKey( + $setup->getTable('catalog_product_index_price'), + $setup->getFkName( + 'catalog_product_index_price', + 'entity_id', + 'catalog_product_entity', + 'entity_id' + ) + ); + $setup->getConnection()->dropForeignKey( + $setup->getTable('catalog_product_index_price'), + $setup->getFkName( + 'catalog_product_index_price', + 'website_id', + 'store_website', + 'website_id' + ) + ); + $setup->getConnection()->dropForeignKey( + $setup->getTable('catalog_product_index_price'), + $setup->getFkName( + 'catalog_product_index_price', + 'customer_group_id', + 'customer_group', + 'customer_group_id' + ) + ); + + $this->addReplicaTable($setup, 'catalog_product_index_eav', 'catalog_product_index_eav_replica'); + $this->addReplicaTable( + $setup, + 'catalog_product_index_eav_decimal', + 'catalog_product_index_eav_decimal_replica' + ); $this->addPathKeyToCategoryEntityTableIfNotExists($setup); // By adding 'catalog_product_index_price_replica' we provide separation of tables // used for indexation write and read operations and affected models. @@ -87,7 +117,6 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con 'catalog_category_product_index_replica' ); } - if (version_compare($context->getVersion(), '2.2.2', '<')) { $tables = [ 'catalog_product_entity_tier_price', @@ -551,37 +580,11 @@ private function addPathKeyToCategoryEntityTableIfNotExists(SchemaSetupInterface */ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $replicaTable) { - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl( - $setup->getTable($existingTable), - $setup->getTable($replicaTable) - ) - ); - } - - /** - * Add Replica for Catalog Product Eav Index Tables. - * - * By adding 'catalog_product_index_eav_replica', 'catalog_product_index_eav_decimal_replica' we provide separation - * of tables used for indexation write and read operations and affected models. - * - * @param SchemaSetupInterface $setup - * @return void - */ - private function addProductEavIndexReplicaTables(SchemaSetupInterface $setup) - { - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl( - $setup->getTable('catalog_product_index_eav'), - $setup->getTable('catalog_product_index_eav_replica') - ) - ); - - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl( - $setup->getTable('catalog_product_index_eav_decimal'), - $setup->getTable('catalog_product_index_eav_decimal_replica') - ) + $sql = sprintf( + 'CREATE TABLE IF NOT EXISTS %s LIKE %s', + $setup->getTable($replicaTable), + $setup->getTable($existingTable) ); + $setup->getConnection()->query($sql); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php index 13a643d958c0b..a0dc1fe483d0a 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/AbstractActionTest.php @@ -22,11 +22,6 @@ class AbstractActionTest extends \PHPUnit_Framework_TestCase */ protected $_eavSourceFactoryMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResourceMock; - protected function setUp() { $this->_eavDecimalFactoryMock = $this->getMock( @@ -43,13 +38,9 @@ protected function setUp() '', false ); - $this->frontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->_model = $this->getMockForAbstractClass( \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction::class, - [$this->_eavDecimalFactoryMock, $this->_eavSourceFactoryMock, ['default' => $this->frontendResourceMock]] + [$this->_eavDecimalFactoryMock, $this->_eavSourceFactoryMock, []] ); } @@ -150,10 +141,6 @@ public function testReindexWithNotNullArgumentExecutesReindexEntities() $eavSource->expects($this->once())->method('getConnection')->willReturn($connectionMock); $eavDecimal->expects($this->once())->method('getConnection')->willReturn($connectionMock); - $this->frontendResourceMock - ->expects($this->any()) - ->method('getMainTable') - ->willReturn('indexer_table'); $eavDecimal->expects($this->once()) ->method('reindexEntities') ->with($ids); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php index 39df8f5e64535..4e08e8736cf9b 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php @@ -45,13 +45,17 @@ public function testExecuteWithAdapterErrorThrowsException() false ); + $tableSwitcherMock = $this->getMockBuilder( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + )->disableOriginalConstructor()->getMock(); + $model = new \Magento\Catalog\Model\Indexer\Product\Eav\Action\Full( $eavDecimalFactory, $eavSourceFactory, $metadataMock, $batchProviderMock, $batchManagementMock, - [] + $tableSwitcherMock ); $this->setExpectedException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage); @@ -59,6 +63,9 @@ public function testExecuteWithAdapterErrorThrowsException() $model->execute(); } + /** + * @SuppressWarnings(PHPMD.ExcessiveMethodLength) + */ public function testExecute() { $eavDecimalFactory = $this->getMock( @@ -146,13 +153,17 @@ public function testExecute() $selectMock->expects($this->atLeastOnce())->method('distinct')->willReturnSelf(); $selectMock->expects($this->atLeastOnce())->method('from')->willReturnSelf(); + $tableSwitcherMock = $this->getMockBuilder( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + )->disableOriginalConstructor()->getMock(); + $model = new \Magento\Catalog\Model\Indexer\Product\Eav\Action\Full( $eavDecimalFactory, $eavSourceFactory, $metadataMock, $batchProviderMock, $batchManagementMock, - [] + $tableSwitcherMock ); $model->execute(); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php b/app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php index 1bdfad325f964..b023103d33f36 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/Product/Type/PriceTest.php @@ -59,11 +59,6 @@ class PriceTest extends \PHPUnit_Framework_TestCase */ protected $websiteMock; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $idxFrontendResourceMock; - private $tierPriceExtensionFactoryMock; protected function setUp() @@ -117,10 +112,6 @@ protected function setUp() $this->getMock(\Magento\Customer\Api\GroupManagementInterface::class, [], [], '', false); $this->groupManagementMock->expects($this->any())->method('getAllCustomersGroup') ->will($this->returnValue($group)); - $this->idxFrontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->tierPriceExtensionFactoryMock = $this->getMockBuilder(ProductTierPriceExtensionFactory::class) ->setMethods(['create']) ->disableOriginalConstructor() @@ -132,7 +123,6 @@ protected function setUp() 'config' => $this->scopeConfigMock, 'storeManager' => $storeMangerMock, 'groupManagement' => $this->groupManagementMock, - 'indexerFrontendResource' => $this->idxFrontendResourceMock, 'tierPriceExtensionFactory' => $this->tierPriceExtensionFactoryMock ] ); diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php new file mode 100644 index 0000000000000..07654aa0fac9b --- /dev/null +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php @@ -0,0 +1,47 @@ +model = new \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher(); + } + + public function testSwitch() + { + $connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class) + ->disableOriginalConstructor() + ->getMock(); + $tableName = 'tableName'; + + $connectionMock->expects($this->once())->method('renameTablesBatch')->with( + [ + [ + 'oldName' => 'tableName', + 'newName' => 'tableName_outdated' + ], + [ + 'oldName' => 'tableName_replica', + 'newName' => 'tableName' + ], + [ + 'oldName' => 'tableName_outdated', + 'newName' => 'tableName_replica' + ], + ] + ); + + $this->model->switchTable($connectionMock, $tableName); + } +} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/AttributeTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/AttributeTest.php deleted file mode 100644 index a9be7bfa8faf7..0000000000000 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/AttributeTest.php +++ /dev/null @@ -1,44 +0,0 @@ -idxFrontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - $this->model = $objectManagerHelper->getObject( - \Magento\Catalog\Model\ResourceModel\Layer\Filter\Attribute::class, - [ - 'frontendResource' => $this->idxFrontendResourceMock - ] - ); - } - - public function testGetMainTable() - { - $expectedTableName = 'expectedTableName'; - $this->idxFrontendResourceMock->expects($this->once())->method('getMainTable')->willReturn($expectedTableName); - $this->assertEquals($expectedTableName, $this->model->getMainTable()); - } -} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/DecimalTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/DecimalTest.php deleted file mode 100644 index 1bc56f757668e..0000000000000 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/DecimalTest.php +++ /dev/null @@ -1,44 +0,0 @@ -idxFrontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - $this->model = $objectManagerHelper->getObject( - \Magento\Catalog\Model\ResourceModel\Layer\Filter\Decimal::class, - [ - 'frontendResource' => $this->idxFrontendResourceMock - ] - ); - } - - public function testGetMainTable() - { - $expectedTableName = 'expectedTableName'; - $this->idxFrontendResourceMock->expects($this->once())->method('getMainTable')->willReturn($expectedTableName); - $this->assertEquals($expectedTableName, $this->model->getMainTable()); - } -} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/PriceTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/PriceTest.php index 5093d61f21732..f0dcded4e877a 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/PriceTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Layer/Filter/PriceTest.php @@ -18,19 +18,23 @@ class PriceTest extends \PHPUnit_Framework_TestCase /** * @var \PHPUnit_Framework_MockObject_MockObject */ - private $idxFrontendResourceMock; + private $resourceMock; protected function setUp() { $objectManagerHelper = new ObjectManager($this); - $this->idxFrontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); + + $contextMock = $this->getMockBuilder(\Magento\Framework\Model\ResourceModel\Db\Context::class) + ->disableOriginalConstructor() + ->getMock(); + $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); $this->model = $objectManagerHelper->getObject( \Magento\Catalog\Model\ResourceModel\Layer\Filter\Price::class, [ - 'indexerFrontendResource' => $this->idxFrontendResourceMock + 'context' => $contextMock ] ); } @@ -38,7 +42,7 @@ protected function setUp() public function testGetMainTable() { $expectedTableName = 'expectedTableName'; - $this->idxFrontendResourceMock->expects($this->once())->method('getMainTable')->willReturn($expectedTableName); + $this->resourceMock->expects($this->once())->method('getTableName')->willReturn($expectedTableName); $this->assertEquals($expectedTableName, $this->model->getMainTable()); } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php deleted file mode 100644 index bd87658c2f63d..0000000000000 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php +++ /dev/null @@ -1,61 +0,0 @@ -resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) - ->disableOriginalConstructor() - ->getMock(); - $this->indexerStateFactory = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\StateFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - $this->model = $objectManagerHelper->getObject( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source::class, - [ - 'stateFactory' => $this->indexerStateFactory, - 'resources' => $this->resourceMock - ] - ); - } - - public function testGetMainTable() - { - $indexerStateModel = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\State::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resourceMock->expects($this->once())->method('getTableName')->willReturn('catalog_product_index_eav'); - $this->indexerStateFactory->expects($this->once())->method('create')->willReturn($indexerStateModel); - $indexerStateModel->expects($this->once()) - ->method('loadByIndexer') - ->with(\Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID) - ->willReturnSelf(); - $indexerStateModel->expects($this->once())->method('getTableSuffix')->willReturn(''); - $this->assertEquals('catalog_product_index_eav_replica', $this->model->getMainTable()); - } -} diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php index 3a1f43ebdd54e..a34a321c7a2af 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPriceTest.php @@ -34,11 +34,6 @@ class LinkedProductSelectBuilderByIndexPriceTest extends \PHPUnit_Framework_Test */ private $baseSelectProcessorMock; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|\PHPUnit_Framework_MockObject_MockObject - */ - private $indexerFrontendResourceMock; - /** * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice */ @@ -61,24 +56,18 @@ protected function setUp() $this->getMockBuilder(\Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); - $this->indexerFrontendResourceMock = - $this->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->model = new \Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice( $this->storeManagerMock, $this->resourceMock, $this->customerSessionMock, $this->metadataPoolMock, - $this->baseSelectProcessorMock, - $this->indexerFrontendResourceMock + $this->baseSelectProcessorMock ); } public function testBuild() { $productId = 10; - $idxTable = 'catalog_product_index_price'; $metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class) ->disableOriginalConstructor() ->getMockForAbstractClass(); @@ -101,8 +90,6 @@ public function testBuild() $this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadata); $metadata->expects($this->once())->method('getLinkField')->willReturn('row_id'); $this->resourceMock->expects($this->any())->method('getTableName'); - - $this->indexerFrontendResourceMock->expects($this->once())->method('getMainTable')->willReturn($idxTable); $this->baseSelectProcessorMock->expects($this->once())->method('process')->willReturnSelf(); $this->model->build($productId); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/DefaultPriceTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/DefaultPriceTest.php index 4346b48d070de..5d36d69c9a11e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/DefaultPriceTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/DefaultPriceTest.php @@ -14,11 +14,6 @@ class DefaultPriceTest extends \PHPUnit_Framework_TestCase */ private $model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $indexerStateFactory; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -30,14 +25,9 @@ protected function setUp() $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) ->disableOriginalConstructor() ->getMock(); - $this->indexerStateFactory = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\StateFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); $this->model = $objectManagerHelper->getObject( \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice::class, [ - 'indexerStateFactory' => $this->indexerStateFactory, 'resources' => $this->resourceMock ] ); @@ -45,16 +35,7 @@ protected function setUp() public function testGetMainTable() { - $indexerStateModel = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\State::class) - ->disableOriginalConstructor() - ->getMock(); $this->resourceMock->expects($this->once())->method('getTableName')->willReturn('catalog_product_index_price'); - $this->indexerStateFactory->expects($this->once())->method('create')->willReturn($indexerStateModel); - $indexerStateModel->expects($this->once()) - ->method('loadByIndexer') - ->with(\Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID) - ->willReturnSelf(); - $indexerStateModel->expects($this->once())->method('getTableSuffix')->willReturn(''); - $this->assertEquals('catalog_product_index_price_replica', $this->model->getMainTable()); + $this->assertEquals('catalog_product_index_price', $this->model->getMainTable()); } } diff --git a/app/code/Magento/Catalog/etc/di.xml b/app/code/Magento/Catalog/etc/di.xml index 5157544ba6b40..f405348158254 100644 --- a/app/code/Magento/Catalog/etc/di.xml +++ b/app/code/Magento/Catalog/etc/di.xml @@ -131,8 +131,6 @@ Magento\Catalog\Model\ResourceModel\Url\Proxy Magento\Customer\Model\Session\Proxy - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource @@ -232,7 +230,6 @@ Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource @@ -880,7 +877,6 @@ Magento\Catalog\Model\ResourceModel\Product\CompositeBaseSelectProcessor - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource @@ -938,18 +934,6 @@ Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableRowSizeEstimator - - - Magento\Catalog\Model\Indexer\Product\Price\Processor::INDEXER_ID - catalog_product_index_price - entity_id - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - - 100000 @@ -961,28 +945,6 @@ Magento\Catalog\Model\Indexer\Category\Product\RowSizeEstimator - - - Magento\Catalog\Model\Indexer\Category\Product::INDEXER_ID - catalog_category_product_index - entity_id - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource - - Magento\Framework\Indexer\Table\Strategy @@ -992,51 +954,17 @@ Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy indexer - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - - - Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - catalog_product_index_eav - entity_id - - - - - Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - catalog_product_index_eav_decimal - entity_id - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource - - Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy indexer - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - Magento\Catalog\Model\ResourceModel\Product\Indexer\EavDecimal\FrontendResource - diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php index c46a75a2bd712..1e7c800ea1c38 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/AbstractAction.php @@ -70,34 +70,25 @@ abstract class AbstractAction */ private $cacheCleaner; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param ResourceConnection $resource * @param \Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory * @param \Magento\Catalog\Model\Product\Type $catalogProductType * @param \Magento\Framework\Indexer\CacheContext $cacheContext * @param \Magento\Framework\Event\ManagerInterface $eventManager - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ public function __construct( ResourceConnection $resource, \Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory $indexerFactory, \Magento\Catalog\Model\Product\Type $catalogProductType, \Magento\Framework\Indexer\CacheContext $cacheContext, - \Magento\Framework\Event\ManagerInterface $eventManager, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + \Magento\Framework\Event\ManagerInterface $eventManager ) { $this->_resource = $resource; $this->_indexerFactory = $indexerFactory; $this->_catalogProductType = $catalogProductType; $this->cacheContext = $cacheContext; $this->eventManager = $eventManager; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); } /** @@ -195,7 +186,7 @@ public function reindexAll() protected function _syncData() { $idxTableName = $this->_getIdxTable(); - $tableName = $this->indexerStockFrontendResource->getMainTable(); + $tableName = $this->_getTable('cataloginventory_stock_status'); $this->_deleteOldRelations($tableName); diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php index bcb6fd9792551..db04557f871cf 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php @@ -8,6 +8,7 @@ namespace Magento\CatalogInventory\Model\Indexer\Stock\Action; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\Framework\App\ResourceConnection; use Magento\CatalogInventory\Model\ResourceModel\Indexer\StockFactory; use Magento\Catalog\Model\Product\Type as ProductType; @@ -19,7 +20,6 @@ use Magento\Framework\App\ObjectManager; use Magento\Framework\Exception\LocalizedException; use Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction; -use Magento\Indexer\Model\ResourceModel\FrontendResource; /** * Class Full reindex action @@ -54,17 +54,22 @@ class Full extends AbstractAction */ private $batchRowsCount; + /** + * @var ActiveTableSwitcher + */ + private $activeTableSwitcher; + /** * @param ResourceConnection $resource * @param StockFactory $indexerFactory * @param ProductType $catalogProductType * @param CacheContext $cacheContext * @param EventManager $eventManager - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource * @param MetadataPool|null $metadataPool * @param BatchSizeManagementInterface|null $batchSizeManagement * @param BatchProviderInterface|null $batchProvider * @param array $batchRowsCount + * @param ActiveTableSwitcher|null $activeTableSwitcher * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -74,19 +79,18 @@ public function __construct( ProductType $catalogProductType, CacheContext $cacheContext, EventManager $eventManager, - FrontendResource $indexerStockFrontendResource = null, MetadataPool $metadataPool = null, BatchSizeManagementInterface $batchSizeManagement = null, BatchProviderInterface $batchProvider = null, - array $batchRowsCount = [] + array $batchRowsCount = [], + ActiveTableSwitcher $activeTableSwitcher = null ) { parent::__construct( $resource, $indexerFactory, $catalogProductType, $cacheContext, - $eventManager, - $indexerStockFrontendResource + $eventManager ); $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class); @@ -95,6 +99,8 @@ public function __construct( \Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement::class ); $this->batchRowsCount = $batchRowsCount; + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance() + ->get(ActiveTableSwitcher::class); } /** @@ -119,7 +125,7 @@ public function execute($ids = null) foreach ($this->_getTypeIndexers() as $indexer) { $indexer->setActionType(self::ACTION_TYPE); $connection = $indexer->getConnection(); - $tableName = $indexer->getMainTable(); + $tableName = $indexer->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; $batchRowCount = isset($this->batchRowsCount[$indexer->getTypeId()]) ? $this->batchRowsCount[$indexer->getTypeId()] @@ -150,6 +156,7 @@ public function execute($ids = null) } } } + $this->activeTableSwitcher->switchTable($indexer->getConnection(), $indexer->getMainTable()); } catch (\Exception $e) { throw new LocalizedException(__($e->getMessage()), $e); } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php index cabd077c393a0..f2975f9628a73 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/CacheCleaner.php @@ -15,7 +15,6 @@ use Magento\Framework\Indexer\CacheContext; use Magento\CatalogInventory\Model\Stock; use Magento\Catalog\Model\Product; -use Magento\Framework\App\ObjectManager; /** * Clean product cache only when stock status was updated @@ -47,31 +46,22 @@ class CacheCleaner */ private $connection; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param ResourceConnection $resource * @param StockConfigurationInterface $stockConfiguration * @param CacheContext $cacheContext * @param ManagerInterface $eventManager - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ public function __construct( ResourceConnection $resource, StockConfigurationInterface $stockConfiguration, CacheContext $cacheContext, - ManagerInterface $eventManager, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + ManagerInterface $eventManager ) { $this->resource = $resource; $this->stockConfiguration = $stockConfiguration; $this->cacheContext = $cacheContext; $this->eventManager = $eventManager; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); } /** @@ -99,7 +89,7 @@ private function getProductStockStatuses(array $productIds) { $select = $this->getConnection()->select() ->from( - $this->indexerStockFrontendResource->getMainTable(), + $this->resource->getTableName('cataloginventory_stock_status'), ['product_id', 'stock_status', 'qty'] )->where('product_id IN (?)', $productIds) ->where('stock_id = ?', Stock::DEFAULT_STOCK_ID) diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php index 650dfc5bcdbb5..3e47b1c97b458 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php @@ -10,7 +10,6 @@ use Magento\CatalogInventory\Model\Stock; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\CatalogInventory\Api\StockConfigurationInterface; -use Magento\Framework\App\ObjectManager; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; /** @@ -51,16 +50,6 @@ class DefaultStock extends AbstractIndexer implements StockInterface */ protected $stockConfiguration; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory - */ - private $indexerStateFactory; - - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * Param for switching logic which depends on action type (full reindex or partial) * @@ -76,23 +65,15 @@ class DefaultStock extends AbstractIndexer implements StockInterface * @param \Magento\Eav\Model\Config $eavConfig * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig * @param string $connectionName - * @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, \Magento\Eav\Model\Config $eavConfig, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + $connectionName = null ) { $this->_scopeConfig = $scopeConfig; - $this->indexerStateFactory = $stateFactory ?: ObjectManager::getInstance() - ->get(\Magento\Indexer\Model\Indexer\StateFactory::class); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); parent::__construct($context, $tableStrategy, $eavConfig, $connectionName); } @@ -332,11 +313,7 @@ protected function _updateIndexTable($data) } $connection = $this->getConnection(); - $connection->insertOnDuplicate( - $this->indexerStockFrontendResource->getMainTable(), - $data, - ['qty', 'stock_status'] - ); + $connection->insertOnDuplicate($this->getMainTable(), $data, ['qty', 'stock_status']); return $this; } @@ -402,19 +379,4 @@ private function getQueryProcessorComposite() } return $this->queryProcessorComposite; } - - /** - * @inheritdoc - */ - public function getMainTable() - { - $table = parent::getMainTable(); - $indexerState = $this->indexerStateFactory->create()->loadByIndexer( - \Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID - ); - $destinationTableSuffix = ($indexerState->getTableSuffix() === '') - ? \Magento\Framework\Indexer\StateInterface::ADDITIONAL_TABLE_SUFFIX - : ''; - return $table . $destinationTableSuffix; - } } diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php index 18c06b4b1ee14..740d510be17f2 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php @@ -10,7 +10,6 @@ use Magento\CatalogInventory\Model\Stock; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Select; -use Magento\Framework\App\ObjectManager; /** * Class StockStatusBaseSelectProcessor @@ -22,22 +21,12 @@ class StockStatusBaseSelectProcessor implements BaseSelectProcessorInterface */ private $resource; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param ResourceConnection $resource - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - public function __construct( - ResourceConnection $resource, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null - ) { + public function __construct(ResourceConnection $resource) + { $this->resource = $resource; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); } /** @@ -48,7 +37,7 @@ public function __construct( */ public function process(Select $select) { - $stockStatusTable = $this->indexerStockFrontendResource->getMainTable(); + $stockStatusTable = $this->resource->getTableName('cataloginventory_stock_status'); /** @var Select $select */ $select->join( diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteriaMapper.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteriaMapper.php index 22d273c3bf22f..d54328cebcda5 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteriaMapper.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Item/StockItemCriteriaMapper.php @@ -14,7 +14,6 @@ use Psr\Log\LoggerInterface as Logger; use Magento\Framework\Data\Collection\Db\FetchStrategyInterface; use Magento\CatalogInventory\Api\StockConfigurationInterface; -use Magento\Framework\App\ObjectManager; /** * Interface StockItemCriteriaMapper @@ -34,11 +33,6 @@ class StockItemCriteriaMapper extends GenericMapper */ private $storeManager; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param Logger $logger * @param FetchStrategyInterface $fetchStrategy @@ -46,7 +40,6 @@ class StockItemCriteriaMapper extends GenericMapper * @param StoreManagerInterface $storeManager * @param MapperFactory $mapperFactory * @param Select $select - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ public function __construct( Logger $logger, @@ -54,12 +47,9 @@ public function __construct( ObjectFactory $objectFactory, MapperFactory $mapperFactory, StoreManagerInterface $storeManager, - Select $select = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + Select $select = null ) { $this->storeManager = $storeManager; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); parent::__construct($logger, $fetchStrategy, $objectFactory, $mapperFactory, $select); } @@ -136,7 +126,7 @@ public function mapStockStatus($storeId = null) { $websiteId = $this->getStockConfiguration()->getDefaultScopeId(); $this->getSelect()->joinLeft( - ['status_table' => $this->indexerStockFrontendResource->getMainTable()], + ['status_table' => $this->getTable('cataloginventory_stock_status')], 'main_table.product_id=status_table.product_id' . ' AND main_table.stock_id=status_table.stock_id' . $this->connection->quoteInto( diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php index c916a148f1254..a3095f51216a1 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Stock/Status.php @@ -40,34 +40,25 @@ class Status extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb */ private $stockConfiguration; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param \Magento\Framework\Model\ResourceModel\Db\Context $context * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param \Magento\Store\Model\WebsiteFactory $websiteFactory * @param \Magento\Eav\Model\Config $eavConfig * @param string $connectionName - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ public function __construct( \Magento\Framework\Model\ResourceModel\Db\Context $context, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\Store\Model\WebsiteFactory $websiteFactory, \Magento\Eav\Model\Config $eavConfig, - $connectionName = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + $connectionName = null ) { parent::__construct($context, $connectionName); $this->_storeManager = $storeManager; $this->_websiteFactory = $websiteFactory; $this->eavConfig = $eavConfig; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); } /** @@ -80,14 +71,6 @@ protected function _construct() $this->_init('cataloginventory_stock_status', 'product_id'); } - /** - * {@inheritdoc} - */ - public function getMainTable() - { - return $this->indexerStockFrontendResource->getMainTable(); - } - /** * Save Product Status per website * diff --git a/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php b/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php index cdd7a0fcd181d..1017742390eb5 100644 --- a/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php +++ b/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php @@ -157,11 +157,11 @@ private function addCatalogInventoryStockStatusIndexOnStockStatus(SchemaSetupInt */ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $replicaTable) { - $setup->getConnection()->createTable( - $setup->getConnection()->createTableByDdl( - $setup->getTable($existingTable), - $setup->getTable($replicaTable) - ) + $sql = sprintf( + 'CREATE TABLE IF NOT EXISTS %s LIKE %s', + $setup->getTable($replicaTable), + $setup->getTable($existingTable) ); + $setup->getConnection()->query($sql); } } diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/CacheCleanerTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/CacheCleanerTest.php index 5375239875ef6..0f7c108ba1940 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/CacheCleanerTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/Indexer/Stock/CacheCleanerTest.php @@ -15,7 +15,6 @@ use Magento\Framework\Indexer\CacheContext; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; use Magento\Catalog\Model\Product; -use Magento\Indexer\Model\ResourceModel\FrontendResource; class CacheCleanerTest extends \PHPUnit_Framework_TestCase { @@ -49,11 +48,6 @@ class CacheCleanerTest extends \PHPUnit_Framework_TestCase */ private $stockConfigurationMock; - /** - * @var FrontendResource|\PHPUnit_Framework_MockObject_MockObject - */ - private $indexerStockFrontendResourceMock; - /** * @var Select|\PHPUnit_Framework_MockObject_MockObject */ @@ -68,9 +62,6 @@ protected function setUp() $this->cacheContextMock = $this->getMockBuilder(CacheContext::class)->disableOriginalConstructor()->getMock(); $this->eventManagerMock = $this->getMockBuilder(ManagerInterface::class)->getMock(); $this->selectMock = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); - $this->indexerStockFrontendResourceMock = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->resourceMock->expects($this->any()) ->method('getConnection') @@ -82,8 +73,7 @@ protected function setUp() 'resource' => $this->resourceMock, 'stockConfiguration' => $this->stockConfigurationMock, 'cacheContext' => $this->cacheContextMock, - 'eventManager' => $this->eventManagerMock, - 'indexerStockFrontendResource' => $this->indexerStockFrontendResourceMock + 'eventManager' => $this->eventManagerMock ] ); } @@ -115,9 +105,6 @@ public function testClean($stockStatusBefore, $stockStatusAfter, $qtyAfter, $sto ->with(Product::CACHE_TAG, [$productId]); $this->eventManagerMock->expects($this->once())->method('dispatch') ->with('clean_cache_by_tags', ['object' => $this->cacheContextMock]); - $this->indexerStockFrontendResourceMock->expects($this->any()) - ->method('getMainTable') - ->willReturn('table_name'); $callback = function () { }; @@ -162,9 +149,6 @@ public function testNotCleanCache($stockStatusBefore, $stockStatusAfter, $qtyAft ->willReturn($stockThresholdQty); $this->cacheContextMock->expects($this->never())->method('registerEntities'); $this->eventManagerMock->expects($this->never())->method('dispatch'); - $this->indexerStockFrontendResourceMock->expects($this->any()) - ->method('getMainTable') - ->willReturn('table_name'); $callback = function () { }; diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Indexer/Stock/DefaultStockTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Indexer/Stock/DefaultStockTest.php deleted file mode 100644 index b90639a1b056a..0000000000000 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Indexer/Stock/DefaultStockTest.php +++ /dev/null @@ -1,67 +0,0 @@ -resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) - ->disableOriginalConstructor() - ->getMock(); - $this->indexerStateFactory = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\StateFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); - - $this->model = $objectManager->getObject( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock::class, - [ - 'stateFactory' => $this->indexerStateFactory, - 'resources' => $this->resourceMock - ] - ); - } - - public function testGetMainTable() - { - $indexerStateModel = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\State::class) - ->disableOriginalConstructor() - ->getMock(); - $this->resourceMock->expects($this->once()) - ->method('getTableName') - ->willReturn('cataloginventory_stock_status'); - $this->indexerStateFactory->expects($this->once())->method('create')->willReturn($indexerStateModel); - $indexerStateModel->expects($this->once()) - ->method('loadByIndexer') - ->with(\Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID) - ->willReturnSelf(); - $indexerStateModel->expects($this->once())->method('getTableSuffix')->willReturn(''); - $this->assertEquals('cataloginventory_stock_status_replica', $this->model->getMainTable()); - } -} diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Product/StockStatusBaseSelectProcessorTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Product/StockStatusBaseSelectProcessorTest.php index 57817cc8a89bc..55c68911d9399 100644 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Product/StockStatusBaseSelectProcessorTest.php +++ b/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Product/StockStatusBaseSelectProcessorTest.php @@ -11,7 +11,6 @@ use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Select; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; class StockStatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase { @@ -25,11 +24,6 @@ class StockStatusBaseSelectProcessorTest extends \PHPUnit_Framework_TestCase */ private $select; - /** - * @var FrontendResource|\PHPUnit_Framework_MockObject_MockObject - */ - private $indexerStockFrontendResource; - /** * @var StockStatusBaseSelectProcessor */ @@ -39,15 +33,11 @@ protected function setUp() { $this->resource = $this->getMockBuilder(ResourceConnection::class)->disableOriginalConstructor()->getMock(); $this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock(); - $this->indexerStockFrontendResource = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->stockStatusBaseSelectProcessor = (new ObjectManager($this))->getObject( StockStatusBaseSelectProcessor::class, [ - 'resource' => $this->resource, - 'indexerStockFrontendResource' => $this->indexerStockFrontendResource + 'resource' => $this->resource ] ); } @@ -56,9 +46,7 @@ public function testProcess() { $tableName = 'table_name'; - $this->indexerStockFrontendResource->expects($this->once()) - ->method('getMainTable') - ->willReturn($tableName); + $this->resource->expects($this->once())->method('getTableName')->willReturn($tableName); $this->select->expects($this->once()) ->method('join') diff --git a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Stock/StatusTest.php b/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Stock/StatusTest.php deleted file mode 100644 index 4a67e65b3d21d..0000000000000 --- a/app/code/Magento/CatalogInventory/Test/Unit/Model/ResourceModel/Stock/StatusTest.php +++ /dev/null @@ -1,50 +0,0 @@ -indexerStockFrontendResource = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - - $this->model = $objectManager->getObject( - \Magento\CatalogInventory\Model\ResourceModel\Stock\Status::class, - [ - 'indexerStockFrontendResource' => $this->indexerStockFrontendResource - ] - ); - } - - public function testGetMainTable() - { - $tableName = 'cataloginventory_stock_status'; - $this->indexerStockFrontendResource->expects($this->once()) - ->method('getMainTable') - ->willReturn($tableName); - $this->assertEquals($tableName, $this->model->getMainTable()); - } -} diff --git a/app/code/Magento/CatalogInventory/composer.json b/app/code/Magento/CatalogInventory/composer.json index d3804631e9850..170f28909852c 100644 --- a/app/code/Magento/CatalogInventory/composer.json +++ b/app/code/Magento/CatalogInventory/composer.json @@ -10,8 +10,7 @@ "magento/module-eav": "100.2.*", "magento/module-quote": "100.2.*", "magento/framework": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-indexer": "100.2.*" + "magento/module-ui": "100.2.*" }, "type": "magento2-module", "version": "100.2.0-dev", diff --git a/app/code/Magento/CatalogInventory/etc/di.xml b/app/code/Magento/CatalogInventory/etc/di.xml index f12826ef17436..0a1a1c58c69de 100644 --- a/app/code/Magento/CatalogInventory/etc/di.xml +++ b/app/code/Magento/CatalogInventory/etc/di.xml @@ -104,41 +104,4 @@ Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement - - - Magento\CatalogInventory\Model\Indexer\Stock\Processor::INDEXER_ID - cataloginventory_stock_status - product_id - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php index c50eb68631a24..a2242ff0f355b 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Aggregation/DataProvider.php @@ -17,7 +17,6 @@ use Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderInterface; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\App\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -49,52 +48,23 @@ class DataProvider implements DataProviderInterface */ private $connection; - /** - * @var FrontendResource - */ - private $indexerFrontendResource; - - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory|null - */ - private $stateFactory; - - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param Config $eavConfig * @param ResourceConnection $resource * @param ScopeResolverInterface $scopeResolver * @param Session $customerSession - * @param FrontendResource|null $indexerFrontendResource - * @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory - * @param FrontendResource $indexerStockFrontendResource - * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( Config $eavConfig, ResourceConnection $resource, ScopeResolverInterface $scopeResolver, - Session $customerSession, - FrontendResource $indexerFrontendResource = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - FrontendResource $indexerStockFrontendResource = null + Session $customerSession ) { $this->eavConfig = $eavConfig; $this->resource = $resource; $this->connection = $resource->getConnection(); $this->scopeResolver = $scopeResolver; $this->customerSession = $customerSession; - $this->indexerFrontendResource = $indexerFrontendResource ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class - ); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); - $this->stateFactory = $stateFactory ?: ObjectManager::getInstance() - ->get(\Magento\Indexer\Model\Indexer\StateFactory::class); } /** @@ -123,7 +93,7 @@ public function getDataSet( if (!$store instanceof \Magento\Store\Model\Store) { throw new \RuntimeException('Illegal scope resolved'); } - $table = $this->indexerFrontendResource->getMainTable(); + $table = $this->resource->getTableName('catalog_product_index_price'); $select->from(['main_table' => $table], null) ->columns([BucketInterface::FIELD_VALUE => 'main_table.min_price']) ->where('main_table.customer_group_id = ?', $this->customerSession->getCustomerGroupId()) @@ -131,18 +101,14 @@ public function getDataSet( } else { $currentScopeId = $this->scopeResolver->getScope($currentScope) ->getId(); - $tableSufix = $this->stateFactory->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - )->getTableSuffix(); $table = $this->resource->getTableName( 'catalog_product_index_eav' . ($attribute->getBackendType() === 'decimal' ? '_decimal' : '') ); - $table .= $tableSufix; $subSelect = $select; $subSelect->from(['main_table' => $table], ['main_table.entity_id', 'main_table.value']) ->distinct() ->joinLeft( - ['stock_index' => $this->indexerStockFrontendResource->getMainTable()], + ['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'main_table.source_id = stock_index.product_id', [] ) diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php index 86a4d70588b33..8b7a7ed214e36 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Dynamic/DataProvider.php @@ -16,7 +16,6 @@ use Magento\Framework\Search\Dynamic\IntervalFactory; use Magento\Framework\Search\Request\BucketInterface; use Magento\Framework\App\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Store\Model\StoreManager; /** @@ -54,11 +53,6 @@ class DataProvider implements DataProviderInterface */ private $connection; - /** - * @var FrontendResource - */ - private $indexerFrontendResource; - /** * @var StoreManager */ @@ -70,7 +64,6 @@ class DataProvider implements DataProviderInterface * @param Session $customerSession * @param MysqlDataProviderInterface $dataProvider * @param IntervalFactory $intervalFactory - * @param FrontendResource $indexerFrontendResource * @param StoreManager $storeManager */ public function __construct( @@ -79,7 +72,6 @@ public function __construct( Session $customerSession, MysqlDataProviderInterface $dataProvider, IntervalFactory $intervalFactory, - FrontendResource $indexerFrontendResource = null, StoreManager $storeManager = null ) { $this->resource = $resource; @@ -88,9 +80,6 @@ public function __construct( $this->customerSession = $customerSession; $this->dataProvider = $dataProvider; $this->intervalFactory = $intervalFactory; - $this->indexerFrontendResource = $indexerFrontendResource ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class - ); $this->storeManager = $storeManager ?: ObjectManager::getInstance()->get(StoreManager::class); } @@ -116,7 +105,7 @@ public function getAggregations(\Magento\Framework\Search\Dynamic\EntityStorage $select = $this->getSelect(); - $tableName = $this->indexerFrontendResource->getMainTable(); + $tableName = $this->resource->getTableName('catalog_product_index_price'); /** @var Table $table */ $table = $entityStorage->getSource(); $select->from(['main_table' => $tableName], []) diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php index 067d7fb3db98c..2cb9b7d81dc82 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Filter/Preprocessor.php @@ -79,11 +79,6 @@ class Preprocessor implements PreprocessorInterface */ private $customerSession; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory - */ - private $indexerStateFactory; - /** * @param ConditionManager $conditionManager * @param ScopeResolverInterface $scopeResolver @@ -93,7 +88,6 @@ class Preprocessor implements PreprocessorInterface * @param string $attributePrefix * @param ScopeConfigInterface|null $scopeConfig * @param AliasResolver|null $aliasResolver - * @param \Magento\Indexer\Model\Indexer\StateFactory|null $stateFactory * @param Session $customerSession * * @SuppressWarnings(PHPMD.ExcessiveParameterList) @@ -108,7 +102,6 @@ public function __construct( $attributePrefix, ScopeConfigInterface $scopeConfig = null, AliasResolver $aliasResolver = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, Session $customerSession = null ) { $this->conditionManager = $conditionManager; @@ -131,8 +124,6 @@ public function __construct( $this->scopeConfig = $scopeConfig; $this->aliasResolver = $aliasResolver; $this->customerSession = $customerSession; - $this->indexerStateFactory = $stateFactory ?: \Magento\Framework\App\ObjectManager::getInstance() - ->get(\Magento\Indexer\Model\Indexer\StateFactory::class); } /** @@ -226,10 +217,7 @@ private function processQueryWithField(FilterInterface $filter, $isNegation, $qu */ private function processRangeNumeric(FilterInterface $filter, $query, $attribute) { - $indexerSuffix = $this->indexerStateFactory->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - )->getTableSuffix(); - $tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' . $indexerSuffix : '' . $indexerSuffix; + $tableSuffix = $attribute->getBackendType() === 'decimal' ? '_decimal' : ''; $table = $this->resource->getTableName("catalog_product_index_eav{$tableSuffix}"); $select = $this->connection->select(); $entityField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getIdentifierField(); diff --git a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php index 3a628a4cdffed..6bf735e2141cc 100644 --- a/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php +++ b/app/code/Magento/CatalogSearch/Model/Adapter/Mysql/Plugin/Aggregation/Category/DataProvider.php @@ -8,7 +8,6 @@ use Magento\Catalog\Model\Layer\Resolver; use Magento\Framework\App\ResourceConnection; use Magento\Framework\App\ScopeResolverInterface; -use Magento\Framework\App\ObjectManager; use Magento\Framework\DB\Ddl\Table; use Magento\Framework\DB\Select; use Magento\Framework\Search\Request\BucketInterface; @@ -33,30 +32,20 @@ class DataProvider */ protected $categoryFactory; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * DataProvider constructor. * @param ResourceConnection $resource * @param ScopeResolverInterface $scopeResolver * @param Resolver $layerResolver - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend */ public function __construct( ResourceConnection $resource, ScopeResolverInterface $scopeResolver, - Resolver $layerResolver, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + Resolver $layerResolver ) { $this->resource = $resource; $this->scopeResolver = $scopeResolver; $this->layer = $layerResolver->get(); - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource::class - ); } /** @@ -82,7 +71,7 @@ public function aroundGetDataSet( $derivedTable = $this->resource->getConnection()->select(); $derivedTable->from( - ['main_table' => $this->categoryProductIndexerFrontend->getMainTable()], + ['main_table' => $this->resource->getTableName('catalog_category_product_index')], [ 'value' => 'category_id' ] diff --git a/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php b/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php index 67af121a5f764..e2c02925ebddf 100644 --- a/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php +++ b/app/code/Magento/CatalogSearch/Model/ResourceModel/Advanced/Collection.php @@ -84,11 +84,8 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection * @param SearchResultFactory|null $searchResultFactory * @param ProductLimitationFactory|null $productLimitationFactory * @param MetadataPool|null $metadataPool - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend * * @SuppressWarnings(PHPMD.ExcessiveParameterList) - * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, @@ -116,9 +113,7 @@ public function __construct( \Magento\Framework\DB\Adapter\AdapterInterface $connection = null, SearchResultFactory $searchResultFactory = null, ProductLimitationFactory $productLimitationFactory = null, - MetadataPool $metadataPool = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + MetadataPool $metadataPool = null ) { $this->requestBuilder = $requestBuilder; $this->searchEngine = $searchEngine; @@ -149,9 +144,7 @@ public function __construct( $groupManagement, $connection, $productLimitationFactory, - $metadataPool, - $indexerFrontendResource, - $categoryProductIndexerFrontend + $metadataPool ); } diff --git a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php index bace3d5a0e7dc..22b73d912e592 100644 --- a/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php +++ b/app/code/Magento/CatalogSearch/Model/ResourceModel/Fulltext/Collection.php @@ -126,11 +126,8 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection * @param SearchResultFactory|null $searchResultFactory * @param ProductLimitationFactory|null $productLimitationFactory * @param MetadataPool|null $metadataPool - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend * * @SuppressWarnings(PHPMD.ExcessiveParameterList) - * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( \Magento\Framework\Data\Collection\EntityFactory $entityFactory, @@ -160,9 +157,7 @@ public function __construct( $searchRequestName = 'catalog_view_container', SearchResultFactory $searchResultFactory = null, ProductLimitationFactory $productLimitationFactory = null, - MetadataPool $metadataPool = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null + MetadataPool $metadataPool = null ) { $this->queryFactory = $catalogSearchData; if ($searchResultFactory === null) { @@ -191,9 +186,7 @@ public function __construct( $groupManagement, $connection, $productLimitationFactory, - $metadataPool, - $indexerFrontendResource, - $categoryProductIndexerFrontend + $metadataPool ); $this->requestBuilder = $requestBuilder; $this->searchEngine = $searchEngine; diff --git a/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php b/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php index 1d246a6a194db..60c224bd26ce5 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php +++ b/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/ExclusionStrategy.php @@ -7,8 +7,6 @@ namespace Magento\CatalogSearch\Model\Search\FilterMapper; use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver; -use Magento\Framework\App\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; /** * Strategy which processes exclusions from general rules @@ -30,40 +28,19 @@ class ExclusionStrategy implements FilterStrategyInterface */ private $storeManager; - /** - * @var FrontendResource - */ - private $indexerFrontendResource; - - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null - */ - private $categoryProductIndexerFrontend; - /** * @param \Magento\Framework\App\ResourceConnection $resourceConnection * @param \Magento\Store\Model\StoreManagerInterface $storeManager * @param AliasResolver $aliasResolver - * @param FrontendResource $indexerFrontendResource - * @param FrontendResource $categoryProductIndexerFrontend - * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( \Magento\Framework\App\ResourceConnection $resourceConnection, \Magento\Store\Model\StoreManagerInterface $storeManager, - AliasResolver $aliasResolver, - FrontendResource $indexerFrontendResource = null, - FrontendResource $categoryProductIndexerFrontend = null + AliasResolver $aliasResolver ) { $this->resourceConnection = $resourceConnection; $this->storeManager = $storeManager; $this->aliasResolver = $aliasResolver; - $this->indexerFrontendResource = $indexerFrontendResource ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource::class - ); - $this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend ?: ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource::class - ); } /** @@ -78,7 +55,7 @@ public function apply( if ('price' === $field) { $alias = $this->aliasResolver->getAlias($filter); - $tableName = $this->indexerFrontendResource->getMainTable(); + $tableName = $this->resourceConnection->getTableName('catalog_product_index_price'); $select->joinInner( [ $alias => $tableName @@ -92,7 +69,7 @@ public function apply( $isApplied = true; } elseif ('category_ids' === $field) { $alias = $this->aliasResolver->getAlias($filter); - $tableName = $this->categoryProductIndexerFrontend->getMainTable(); + $tableName = $this->resourceConnection->getTableName('catalog_category_product_index'); $select->joinInner( [ $alias => $tableName diff --git a/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/TermDropdownStrategy.php b/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/TermDropdownStrategy.php index 9fff759e22d5c..9dd8482e45238 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/TermDropdownStrategy.php +++ b/app/code/Magento/CatalogSearch/Model/Search/FilterMapper/TermDropdownStrategy.php @@ -47,24 +47,12 @@ class TermDropdownStrategy implements FilterStrategyInterface */ private $scopeConfig; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $frontendResource; - - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @param StoreManagerInterface $storeManager * @param ResourceConnection $resourceConnection * @param EavConfig $eavConfig * @param ScopeConfigInterface $scopeConfig * @param AliasResolver $aliasResolver - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource * @SuppressWarnings(Magento.TypeDuplication) */ public function __construct( @@ -72,19 +60,13 @@ public function __construct( ResourceConnection $resourceConnection, EavConfig $eavConfig, ScopeConfigInterface $scopeConfig, - AliasResolver $aliasResolver, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null + AliasResolver $aliasResolver ) { $this->storeManager = $storeManager; $this->resourceConnection = $resourceConnection; $this->eavConfig = $eavConfig; $this->scopeConfig = $scopeConfig; $this->aliasResolver = $aliasResolver; - $this->frontendResource = $frontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource::class); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); } /** @@ -104,7 +86,7 @@ public function apply( $this->storeManager->getWebsite()->getId() ); $select->joinLeft( - [$alias => $this->frontendResource->getMainTable()], + [$alias => $this->resourceConnection->getTableName('catalog_product_index_eav')], $joinCondition, [] ); @@ -112,7 +94,7 @@ public function apply( $stockAlias = $alias . AliasResolver::STOCK_FILTER_SUFFIX; $select->joinLeft( [ - $stockAlias => $this->indexerStockFrontendResource->getMainTable(), + $stockAlias => $this->resourceConnection->getTableName('cataloginventory_stock_status'), ], sprintf('%2$s.product_id = %1$s.source_id', $alias, $stockAlias), [] diff --git a/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php b/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php index 68deec9c00944..e4f0ad2864ad8 100644 --- a/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php +++ b/app/code/Magento/CatalogSearch/Model/Search/IndexBuilder.php @@ -69,11 +69,6 @@ class IndexBuilder implements IndexBuilderInterface */ private $stockConfiguration; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - /** * @var FullTextSearchCheck */ @@ -87,7 +82,6 @@ class IndexBuilder implements IndexBuilderInterface * @param IndexScopeResolver $scopeResolver * @param TableMapper $tableMapper * @param ScopeResolverInterface $dimensionScopeResolver - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource * @param FullTextSearchCheck $fullTextSearchCheck */ public function __construct( @@ -98,7 +92,6 @@ public function __construct( IndexScopeResolver $scopeResolver, TableMapper $tableMapper, ScopeResolverInterface $dimensionScopeResolver, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null, FullTextSearchCheck $fullTextSearchCheck = null ) { $this->resource = $resource; @@ -108,8 +101,6 @@ public function __construct( $this->scopeResolver = $scopeResolver; $this->tableMapper = $tableMapper; $this->dimensionScopeResolver = $dimensionScopeResolver; - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); $this->fullTextSearchCheck = $fullTextSearchCheck ?: ObjectManager::getInstance() ->get(FullTextSearchCheck::class); } @@ -150,7 +141,7 @@ public function build(RequestInterface $request) ); if ($isShowOutOfStock === false) { $select->joinInner( - ['stock_index' => $this->indexerStockFrontendResource->getMainTable()], + ['stock_index' => $this->resource->getTableName('cataloginventory_stock_status')], 'search_index.entity_id = stock_index.product_id' . $this->resource->getConnection()->quoteInto( ' AND stock_index.website_id = ?', diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Aggregation/DataProviderTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Aggregation/DataProviderTest.php index 7b0680c325317..ba98f40b2e405 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Aggregation/DataProviderTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Aggregation/DataProviderTest.php @@ -11,7 +11,6 @@ use Magento\Customer\Model\Session; use Magento\Framework\App\ResourceConnection; use Magento\Framework\App\ScopeResolverInterface; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Framework\DB\Select; use Magento\Store\Model\Store; use Magento\Framework\Search\Request\BucketInterface; @@ -51,49 +50,25 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase */ private $scopeResolverMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResourceMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResourceStockMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ private $adapterMock; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $stateFactoryMock; - protected function setUp() { $this->eavConfigMock = $this->getMock(Config::class, [], [], '', false); $this->resourceConnectionMock = $this->getMock(ResourceConnection::class, [], [], '', false); $this->scopeResolverMock = $this->getMock(ScopeResolverInterface::class); $this->sessionMock = $this->getMock(Session::class, [], [], '', false); - $this->frontendResourceMock = $this->getMock(FrontendResource::class, [], [], '', false); - $this->frontendResourceStockMock = $this->getMock(FrontendResource::class, [], [], '', false); $this->adapterMock = $this->getMock(AdapterInterface::class); $this->resourceConnectionMock->expects($this->once())->method('getConnection')->willReturn($this->adapterMock); - $this->stateFactoryMock = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\StateFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); $this->model = new DataProvider( $this->eavConfigMock, $this->resourceConnectionMock, $this->scopeResolverMock, - $this->sessionMock, - $this->frontendResourceMock, - $this->stateFactoryMock, - $this->frontendResourceStockMock + $this->sessionMock ); } @@ -123,9 +98,6 @@ public function testGetDataSetUsesFrontendPriceIndexerTableIfAttributeIsPrice() $this->adapterMock->expects($this->once())->method('select')->willReturn($selectMock); $tableMock = $this->getMock(Table::class); - // verify that frontend indexer table is used - $this->frontendResourceMock->expects($this->once())->method('getMainTable'); - $this->model->getDataSet($bucketMock, ['scope' => $dimensionMock], $tableMock); } @@ -133,15 +105,6 @@ public function testGetDataSetUsesFrontendPriceIndexerTableForDecimalAttributes( { $storeId = 1; $attributeCode = 'my_decimal'; - $stateMock = $this->getMock(\Magento\Indexer\Model\Indexer\State::class, [], [], '', false); - $this->stateFactoryMock->expects($this->once())->method('create')->willReturn($stateMock); - $stateMock->expects($this->once()) - ->method('loadByIndexer') - ->with(\Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID) - ->willReturnSelf(); - // verify that frontend indexer table is used - $stateMock->expects($this->once())->method('getTableSuffix')->willReturn('_replica'); - $scopeMock = $this->getMock(Store::class, [], [], '', false); $scopeMock->expects($this->any())->method('getId')->willReturn($storeId); $dimensionMock = $this->getMock(Dimension::class, [], [], '', false); diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Dynamic/DataProviderTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Dynamic/DataProviderTest.php index 2975723c7f958..03f66d577f162 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Dynamic/DataProviderTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Dynamic/DataProviderTest.php @@ -10,7 +10,6 @@ use Magento\Customer\Model\Session; use Magento\Framework\App\ResourceConnection; use Magento\Framework\Search\Dynamic\IntervalFactory; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Framework\DB\Select; use Magento\Framework\DB\Adapter\AdapterInterface; use Magento\Framework\DB\Ddl\Table; @@ -40,11 +39,6 @@ class DataProviderTest extends \PHPUnit_Framework_TestCase */ private $resourceConnectionMock; - /** - * @var FrontendResource|\PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResourceMock; - /** * @var Range|\PHPUnit_Framework_MockObject_MockObject */ @@ -74,7 +68,6 @@ protected function setUp() { $this->resourceConnectionMock = $this->getMock(ResourceConnection::class, [], [], '', false); $this->sessionMock = $this->getMock(Session::class, [], [], '', false); - $this->frontendResourceMock = $this->getMock(FrontendResource::class, [], [], '', false); $this->adapterMock = $this->getMock(AdapterInterface::class); $this->resourceConnectionMock->expects($this->once())->method('getConnection')->willReturn($this->adapterMock); $this->rangeMock = $this->getMock(Range::class, [], [], '', false); @@ -88,7 +81,6 @@ protected function setUp() $this->sessionMock, $this->mysqlDataProviderMock, $this->intervalFactoryMock, - $this->frontendResourceMock, $this->storeManagerMock ); } @@ -105,9 +97,6 @@ public function testGetAggregationsUsesFrontendPriceIndexerTable() $entityStorageMock = $this->getMock(EntityStorage::class, [], [], '', false); $entityStorageMock->expects($this->any())->method('getSource')->willReturn($tableMock); - // verify that frontend indexer table is used - $this->frontendResourceMock->expects($this->once())->method('getMainTable'); - $storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class, [], [], '', false); $storeMock->expects($this->once())->method('getWebsiteId')->willReturn(42); $this->storeManagerMock->expects($this->once())->method('getStore')->willReturn($storeMock); diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php index 134577ae7a073..58a64185e6152 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Adapter/Mysql/Filter/PreprocessorTest.php @@ -78,11 +78,6 @@ class PreprocessorTest extends \PHPUnit_Framework_TestCase */ private $metadataPoolMock; - /** - * @var \Magento\Indexer\Model\Indexer\StateFactory|\PHPUnit_Framework_MockObject_MockObject - */ - private $stateFactoryMock; - /** * @var \Magento\Customer\Model\Session|\PHPUnit_Framework_MockObject_MockObject */ @@ -176,10 +171,6 @@ function ($select) { $this->metadataPoolMock->expects($this->any())->method('getMetadata')->willReturn($metadata); $metadata->expects($this->any())->method('getLinkField')->willReturn('entity_id'); - $this->stateFactoryMock = $this->getMockBuilder(\Magento\Indexer\Model\Indexer\StateFactory::class) - ->disableOriginalConstructor() - ->setMethods(['create']) - ->getMock(); $this->customerSessionMock = $this->getMockBuilder(\Magento\Customer\Model\Session::class) ->disableOriginalConstructor() @@ -200,7 +191,6 @@ function ($select) { 'attributePrefix' => 'attr_', 'metadataPool' => $this->metadataPoolMock, 'aliasResolver' => $this->aliasResolver, - 'stateFactory' => $this->stateFactoryMock, 'customerSession' => $this->customerSessionMock ] ); @@ -448,17 +438,9 @@ public function testProcessRangeFilter() { $query = 'static_attribute LIKE %name%'; $expected = 'search_index.entity_id IN (select entity_id from () as filter)'; - $stateMock = $this->getMock(\Magento\Indexer\Model\Indexer\State::class, [], [], '', false); $this->filter->expects($this->any()) ->method('getField') ->willReturn('termField'); - $this->stateFactoryMock->expects($this->once())->method('create')->willReturn($stateMock); - $stateMock->expects($this->once()) - ->method('loadByIndexer') - ->with(\Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID) - ->willReturnSelf(); - // verify that frontend indexer table is used - $stateMock->expects($this->once())->method('getTableSuffix')->willReturn('_replica'); $this->config->expects($this->exactly(1)) ->method('getAttribute') ->with(\Magento\Catalog\Model\Product::ENTITY, 'termField') diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php index 9d150d03540c2..af16b68a6196c 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Advanced/CollectionTest.php @@ -8,7 +8,6 @@ use Magento\Catalog\Model\Product; use Magento\CatalogSearch\Test\Unit\Model\ResourceModel\BaseCollectionTest; use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory; -use Magento\Indexer\Model\ResourceModel\FrontendResource; /** * Tests Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection @@ -52,16 +51,6 @@ class CollectionTest extends BaseCollectionTest */ private $eavConfig; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $indexerFrontendMock; - - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $categoryProductIndexerMock; - /** * setUp method for CollectionTest */ @@ -92,13 +81,6 @@ protected function setUp() $productLimitationFactoryMock->method('create') ->willReturn($productLimitationMock); - $this->indexerFrontendMock = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - $this->categoryProductIndexerMock = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - $this->advancedCollection = $this->objectManager->getObject( \Magento\CatalogSearch\Model\ResourceModel\Advanced\Collection::class, [ @@ -110,8 +92,6 @@ protected function setUp() 'temporaryStorageFactory' => $this->temporaryStorageFactory, 'search' => $this->search, 'productLimitationFactory' => $productLimitationFactoryMock, - 'indexerFrontendResource' => $this->indexerFrontendMock, - 'categoryProductIndexerFrontend' => $this->categoryProductIndexerMock, ] ); } diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Fulltext/CollectionTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Fulltext/CollectionTest.php index 05e22da6c5dfb..c3ff281cdb96d 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Fulltext/CollectionTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/ResourceModel/Fulltext/CollectionTest.php @@ -9,7 +9,6 @@ use Magento\Framework\Search\Adapter\Mysql\TemporaryStorageFactory; use PHPUnit_Framework_MockObject_MockObject as MockObject; use Magento\Catalog\Model\ResourceModel\Product\Collection\ProductLimitationFactory; -use Magento\Indexer\Model\ResourceModel\FrontendResource; /** * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -99,9 +98,6 @@ protected function setUp() ->method('create') ->willReturn($this->temporaryStorage); - $categoryProductFrontendMock = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->model = $this->objectManager->getObject( \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection::class, [ @@ -110,7 +106,6 @@ protected function setUp() 'scopeConfig' => $this->scopeConfig, 'temporaryStorageFactory' => $temporaryStorageFactory, 'productLimitationFactory' => $productLimitationFactoryMock, - 'categoryProductIndexerFrontend' => $categoryProductFrontendMock, ] ); diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/ExclusionStrategyTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/ExclusionStrategyTest.php index e9a297d622081..5a865634459a5 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/ExclusionStrategyTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/ExclusionStrategyTest.php @@ -8,7 +8,6 @@ use Magento\CatalogSearch\Model\Search\FilterMapper\ExclusionStrategy; use Magento\Framework\App\ResourceConnection; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Store\Model\StoreManagerInterface; use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver; use Magento\Framework\DB\Select; @@ -28,11 +27,6 @@ class ExclusionStrategyTest extends \PHPUnit_Framework_TestCase */ private $resourceConnectionMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResourceMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -48,28 +42,18 @@ class ExclusionStrategyTest extends \PHPUnit_Framework_TestCase */ private $aliasResolverMock; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $categoryProductFrontendMock; - protected function setUp() { $this->resourceConnectionMock = $this->getMock(ResourceConnection::class, [], [], '', false); - - $this->frontendResourceMock = $this->getMock(FrontendResource::class, [], [], '', false); $this->adapterMock = $this->getMock(AdapterInterface::class); $this->resourceConnectionMock->expects($this->any())->method('getConnection')->willReturn($this->adapterMock); $this->storeManagerMock = $this->getMock(StoreManagerInterface::class); $this->aliasResolverMock = $this->getMock(AliasResolver::class, [], [], '', false); - $this->categoryProductFrontendMock = $this->getMock(FrontendResource::class, [], [], '', false); $this->model = new ExclusionStrategy( $this->resourceConnectionMock, $this->storeManagerMock, - $this->aliasResolverMock, - $this->frontendResourceMock, - $this->categoryProductFrontendMock + $this->aliasResolverMock ); } @@ -87,9 +71,6 @@ public function testApplyUsesFrontendPriceIndexerTableIfAttributeCodeIsPrice() $websiteMock->expects($this->any())->method('getId')->willReturn($websiteId); $this->storeManagerMock->expects($this->any())->method('getWebsite')->willReturn($websiteMock); - // verify that frontend indexer table is used - $this->frontendResourceMock->expects($this->once())->method('getMainTable'); - $this->assertTrue($this->model->apply($searchFilterMock, $selectMock)); } } diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/TermDropdownStrategyTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/TermDropdownStrategyTest.php index 4228d520008a9..c88756ae16ec5 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/TermDropdownStrategyTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/FilterMapper/TermDropdownStrategyTest.php @@ -7,7 +7,6 @@ namespace Magento\CatalogSearch\Test\Unit\Model\Search\FilterMapper; use Magento\Framework\TestFramework\Unit\Helper\ObjectManager; -use Magento\Indexer\Model\ResourceModel\FrontendResource; use Magento\Framework\Search\Request\FilterInterface; use Magento\Store\Model\StoreManagerInterface; use Magento\Framework\App\Config\ScopeConfigInterface; @@ -22,11 +21,6 @@ */ class TermDropdownStrategyTest extends \PHPUnit_Framework_TestCase { - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $frontendResource; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -47,12 +41,14 @@ class TermDropdownStrategyTest extends \PHPUnit_Framework_TestCase */ private $model; + /** + * @var \PHPUnit_Framework_MockObject_MockObject + */ + private $resourceMock; + protected function setUp() { $objectManager = new ObjectManager($this); - $this->frontendResource = $this->getMockBuilder(FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); $this->eavConfig = $this->getMockBuilder(EavConfig::class) ->disableOriginalConstructor() ->getMock(); @@ -63,13 +59,17 @@ protected function setUp() ->disableOriginalConstructor() ->getMock(); + $this->resourceMock = $this->getMockBuilder(\Magento\Framework\App\ResourceConnection::class) + ->disableOriginalConstructor() + ->getMock(); + $this->model = $objectManager->getObject( \Magento\CatalogSearch\Model\Search\FilterMapper\TermDropdownStrategy::class, [ 'storeManager' => $this->storeManager, 'scopeConfig' => $this->scopeConfig, 'eavConfig' => $this->eavConfig, - 'indexerStockFrontendResource' => $this->frontendResource + 'resourceConnection' => $this->resourceMock ] ); } @@ -89,8 +89,8 @@ public function testApply() ->disableOriginalConstructor() ->getMock(); - $this->frontendResource->expects($this->once()) - ->method('getMainTable') + $this->resourceMock->expects($this->any()) + ->method('getTableName') ->willReturn('cataloginventory_stock_status'); $this->scopeConfig->expects($this->once()) ->method('isSetFlag') diff --git a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php index d7c81e0c158a2..205a6d60f7a28 100644 --- a/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php +++ b/app/code/Magento/CatalogSearch/Test/Unit/Model/Search/IndexBuilderTest.php @@ -61,11 +61,6 @@ class IndexBuilderTest extends \PHPUnit_Framework_TestCase */ private $scopeInterface; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource|\PHPUnit_Framework_MockObject_MockObject - */ - private $indexerStockFrontendResource; - /** * @var FullTextSearchCheck|\PHPUnit_Framework_MockObject_MockObject */ @@ -163,14 +158,6 @@ function ($left, $operator, $right) { ->getMockBuilder(\Magento\CatalogInventory\Api\StockConfigurationInterface::class) ->getMock(); - $this->indexerStockFrontendResource = $this - ->getMockBuilder(\Magento\Indexer\Model\ResourceModel\FrontendResource::class) - ->disableOriginalConstructor() - ->getMock(); - $this->indexerStockFrontendResource->expects($this->any()) - ->method('getMainTable') - ->willReturn('cataloginventory_stock_status'); - $this->fullTextSearchCheckMock = $this->getMockBuilder( \Magento\CatalogSearch\Model\Search\QueryChecker\FullTextSearchCheck::class )->disableOriginalConstructor() @@ -192,7 +179,6 @@ function ($left, $operator, $right) { 'scopeResolver' => $this->scopeResolver, 'tableMapper' => $this->tableMapper, 'dimensionScopeResolver' => $this->dimensionScopeResolver, - 'indexerStockFrontendResource' => $this->indexerStockFrontendResource, 'fullTextSearchCheck' => $this->fullTextSearchCheckMock ] ); diff --git a/app/code/Magento/CatalogSearch/composer.json b/app/code/Magento/CatalogSearch/composer.json index d52061e24dd88..c02c3034af524 100644 --- a/app/code/Magento/CatalogSearch/composer.json +++ b/app/code/Magento/CatalogSearch/composer.json @@ -12,7 +12,6 @@ "magento/module-backend": "100.2.*", "magento/module-theme": "100.2.*", "magento/module-catalog-inventory": "100.2.*", - "magento/module-indexer": "100.2.*", "magento/framework": "100.2.*" }, "type": "magento2-module", diff --git a/app/code/Magento/CatalogSearch/etc/di.xml b/app/code/Magento/CatalogSearch/etc/di.xml index 4fb7bacc6ac89..212f62c2a1d35 100644 --- a/app/code/Magento/CatalogSearch/etc/di.xml +++ b/app/code/Magento/CatalogSearch/etc/di.xml @@ -211,8 +211,6 @@ Magento\Catalog\Model\Layer\Filter\Price\Range\Proxy - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource @@ -287,33 +285,6 @@ - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\FrontendResource - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource - - - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - diff --git a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php index 07d0bf6b588b6..f3d983b82b11b 100644 --- a/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php +++ b/app/code/Magento/CatalogWidget/Model/Rule/Condition/Product.php @@ -9,8 +9,6 @@ */ namespace Magento\CatalogWidget\Model\Rule\Condition; -use Magento\Framework\App\ObjectManager; - /** * Class Product * @SuppressWarnings(PHPMD.CouplingBetweenObjects) @@ -34,11 +32,6 @@ class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct */ protected $storeManager; - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $frontendResource; - /** * @param \Magento\Rule\Model\Condition\Context $context * @param \Magento\Backend\Helper\Data $backendData @@ -49,7 +42,6 @@ class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct * @param \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $attrSetCollection * @param \Magento\Framework\Locale\FormatInterface $localeFormat * @param \Magento\Store\Model\StoreManagerInterface $storeManager - * @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $frontendResource * @param array $data * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -63,12 +55,9 @@ public function __construct( \Magento\Eav\Model\ResourceModel\Entity\Attribute\Set\Collection $attrSetCollection, \Magento\Framework\Locale\FormatInterface $localeFormat, \Magento\Store\Model\StoreManagerInterface $storeManager, - \Magento\Indexer\Model\ResourceModel\FrontendResource $frontendResource = null, array $data = [] ) { $this->storeManager = $storeManager; - $this->frontendResource = $frontendResource ?: ObjectManager::getInstance() - ->get(\Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource::class); parent::__construct( $context, $backendData, @@ -168,7 +157,7 @@ protected function addGlobalAttribute( default: $alias = 'at_' . md5($this->getId()) . $attribute->getAttributeCode(); $collection->getSelect()->join( - [$alias => $this->frontendResource->getMainTable()], + [$alias => $collection->getTable('catalog_product_index_eav')], "($alias.entity_id = e.entity_id) AND ($alias.store_id = $storeId)" . " AND ($alias.attribute_id = {$attribute->getId()})", [] diff --git a/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php b/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php index b878e483cc1fa..2d9089e549047 100644 --- a/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php +++ b/app/code/Magento/CatalogWidget/Test/Unit/Model/Rule/Condition/ProductTest.php @@ -15,11 +15,6 @@ class ProductTest extends \PHPUnit_Framework_TestCase */ private $model; - /** - * @var \PHPUnit_Framework_MockObject_MockObject - */ - private $resourceMock; - /** * @var \PHPUnit_Framework_MockObject_MockObject */ @@ -41,20 +36,12 @@ protected function setUp() $storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class); $storeMock = $this->getMock(\Magento\Store\Api\Data\StoreInterface::class); $storeManager->expects($this->once())->method('getStore')->willReturn($storeMock); - $this->resourceMock = $this->getMock( - \Magento\Indexer\Model\ResourceModel\FrontendResource::class, - [], - [], - '', - false - ); $productResource = $this->getMock(\Magento\Catalog\Model\ResourceModel\Product::class, [], [], '', false); $productResource->expects($this->once())->method('loadAllAttributes')->willReturnSelf(); $productResource->expects($this->once())->method('getAttributesByCode')->willReturn([]); $this->model = $objectManagerHelper->getObject( \Magento\CatalogWidget\Model\Rule\Condition\Product::class, [ - 'frontendResource' => $this->resourceMock, 'config' => $eavConfig, 'storeManager' => $storeManager, 'productResource' => $productResource, @@ -84,8 +71,6 @@ public function testAddToCollection() $this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true); $this->attributeMock->expects($this->once())->method('isScopeGlobal')->willReturn(true); $this->attributeMock->expects($this->once())->method('getBackendType')->willReturn('multiselect'); - // verify that frontend indexer table is used - $this->resourceMock->expects($this->once())->method('getMainTable')->willReturn('catalog_product_index_eav'); $this->model->addToCollection($collectionMock); } } diff --git a/app/code/Magento/CatalogWidget/composer.json b/app/code/Magento/CatalogWidget/composer.json index 8f8e9897113d7..6bd93c6eb188b 100644 --- a/app/code/Magento/CatalogWidget/composer.json +++ b/app/code/Magento/CatalogWidget/composer.json @@ -11,7 +11,6 @@ "magento/module-customer": "100.2.*", "magento/module-store": "100.2.*", "magento/module-wishlist": "100.2.*", - "magento/module-indexer": "100.2.*", "magento/framework": "100.2.*" }, "type": "magento2-module", diff --git a/app/code/Magento/CatalogWidget/etc/di.xml b/app/code/Magento/CatalogWidget/etc/di.xml index aa22865c6e501..336a956619725 100644 --- a/app/code/Magento/CatalogWidget/etc/di.xml +++ b/app/code/Magento/CatalogWidget/etc/di.xml @@ -13,9 +13,4 @@ - - - Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\FrontendResource - - diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php index 8159159b3811d..605c4473f9e6d 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php @@ -13,6 +13,7 @@ * @author Magento Core Team */ use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; /** @@ -22,36 +23,6 @@ */ class Configurable extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - - /** - * Class constructor - * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param string $connectionName - * @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource - */ - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null - ) { - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance() - ->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class); - parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName, $stateFactory); - } - /** * Get the select object for get stock status by configurable product ids * @@ -64,8 +35,8 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $connection = $this->getConnection(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() - : $this->indexerStockFrontendResource->getMainTable(); + ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable); $linkField = $metadata->getLinkField(); diff --git a/app/code/Magento/ConfigurableProduct/composer.json b/app/code/Magento/ConfigurableProduct/composer.json index aa2284b4aa022..970fe638cf89e 100644 --- a/app/code/Magento/ConfigurableProduct/composer.json +++ b/app/code/Magento/ConfigurableProduct/composer.json @@ -14,8 +14,7 @@ "magento/framework": "100.2.*", "magento/module-media-storage": "100.2.*", "magento/module-quote": "100.2.*", - "magento/module-ui": "100.2.*", - "magento/module-indexer": "100.2.*" + "magento/module-ui": "100.2.*" }, "suggest": { "magento/module-webapi": "100.2.*", diff --git a/app/code/Magento/ConfigurableProduct/etc/di.xml b/app/code/Magento/ConfigurableProduct/etc/di.xml index 496d85310e817..ca097898f1c57 100644 --- a/app/code/Magento/ConfigurableProduct/etc/di.xml +++ b/app/code/Magento/ConfigurableProduct/etc/di.xml @@ -184,9 +184,4 @@ indexer - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - diff --git a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php index 867aa99d06140..039f708de98d4 100644 --- a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php @@ -11,6 +11,7 @@ */ namespace Magento\GroupedProduct\Model\ResourceModel\Indexer\Stock; +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; /** @@ -20,37 +21,6 @@ */ class Grouped extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { - /** - * @var \Magento\Indexer\Model\ResourceModel\FrontendResource - */ - private $indexerStockFrontendResource; - - /** - * Class constructor - * - * @param \Magento\Framework\Model\ResourceModel\Db\Context $context - * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy - * @param \Magento\Eav\Model\Config $eavConfig - * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig - * @param string $connectionName - * @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory - * @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource - */ - public function __construct( - \Magento\Framework\Model\ResourceModel\Db\Context $context, - \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, - \Magento\Eav\Model\Config $eavConfig, - \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, - $connectionName = null, - \Magento\Indexer\Model\Indexer\StateFactory $stateFactory = null, - \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null - ) { - parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName, $stateFactory); - $this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()->get( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - } - /** * Get the select object for get stock status by grouped product ids * @@ -62,8 +32,8 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f { $connection = $this->getConnection(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() - : $this->indexerStockFrontendResource->getMainTable(); + ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable); diff --git a/app/code/Magento/GroupedProduct/composer.json b/app/code/Magento/GroupedProduct/composer.json index 89bd194ed756c..95173e65dc5c8 100644 --- a/app/code/Magento/GroupedProduct/composer.json +++ b/app/code/Magento/GroupedProduct/composer.json @@ -14,7 +14,6 @@ "magento/module-media-storage": "100.2.*", "magento/module-msrp": "100.2.*", "magento/module-quote": "100.2.*", - "magento/module-indexer": "100.2.*", "magento/framework": "100.2.*", "magento/module-ui": "100.2.*" }, diff --git a/app/code/Magento/GroupedProduct/etc/di.xml b/app/code/Magento/GroupedProduct/etc/di.xml index 696e2a3ed66f4..ff2cac0bd3186 100644 --- a/app/code/Magento/GroupedProduct/etc/di.xml +++ b/app/code/Magento/GroupedProduct/etc/di.xml @@ -87,11 +87,6 @@ - - - Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource - - diff --git a/app/code/Magento/Indexer/Model/Indexer.php b/app/code/Magento/Indexer/Model/Indexer.php index e00a399c4d7f7..08d6f2f147da8 100644 --- a/app/code/Magento/Indexer/Model/Indexer.php +++ b/app/code/Magento/Indexer/Model/Indexer.php @@ -411,10 +411,6 @@ public function reindexAll() } try { $this->getActionInstance()->executeFull(); - $tableSuffix = ($state->getTableSuffix() === '') - ? StateInterface::ADDITIONAL_TABLE_SUFFIX - : ''; - $state->setTableSuffix($tableSuffix); $state->setStatus(StateInterface::STATUS_VALID); $state->save(); $this->getView()->resume(); diff --git a/app/code/Magento/Indexer/Model/Indexer/State.php b/app/code/Magento/Indexer/Model/Indexer/State.php index 320fce7d2df69..ffef44281a024 100644 --- a/app/code/Magento/Indexer/Model/Indexer/State.php +++ b/app/code/Magento/Indexer/Model/Indexer/State.php @@ -121,27 +121,6 @@ public function setStatus($status) return parent::setStatus($status); } - /** - * Get suffix for indexer table. - * - * @return string - */ - public function getTableSuffix() - { - return $this->getData('table_suffix'); - } - - /** - * Get suffix for indexer table. - * - * @param string $tableSuffix - * @return $this - */ - public function setTableSuffix($tableSuffix) - { - return $this->setData('table_suffix', $tableSuffix); - } - /** * Processing object before save data * diff --git a/app/code/Magento/Indexer/Model/ResourceModel/FrontendResource.php b/app/code/Magento/Indexer/Model/ResourceModel/FrontendResource.php deleted file mode 100644 index cea59f6f0fa77..0000000000000 --- a/app/code/Magento/Indexer/Model/ResourceModel/FrontendResource.php +++ /dev/null @@ -1,81 +0,0 @@ -indexerId = $indexerId; - $this->indexerBaseTable = $indexerBaseTable; - $this->indexerStateFactory = $indexerStateFactory; - $this->_idFieldName = $idFieldName; - } - - /** - * Retrieve indexer frontend table name. - * The table that is used for read operations only. - * - * @return string - */ - public function getMainTable() - { - $indexerState = $this->indexerStateFactory->create()->loadByIndexer($this->indexerId); - - return $this->getTable($this->indexerBaseTable . $indexerState->getTableSuffix()); - } - - /** - * No resource initialization is required for this model. - * @return void - */ - protected function _construct() - { - // nothing to initialize - } -} diff --git a/app/code/Magento/Indexer/Setup/UpgradeSchema.php b/app/code/Magento/Indexer/Setup/UpgradeSchema.php deleted file mode 100644 index 235615ff54538..0000000000000 --- a/app/code/Magento/Indexer/Setup/UpgradeSchema.php +++ /dev/null @@ -1,53 +0,0 @@ -startSetup(); - - if (version_compare($context->getVersion(), '2.1.0', '<')) { - $this->addTableSuffixColumn($setup); - } - $setup->endSetup(); - } - - /** - * Add the column 'table_suffix' to the Indexer State table. - * It allows to identify which indexer table is used for data retrieve on storefront. - * - * @param SchemaSetupInterface $setup - * @return void - */ - private function addTableSuffixColumn(SchemaSetupInterface $setup) - { - $connection = $setup->getConnection(); - $connection->addColumn( - $setup->getTable('indexer_state'), - 'table_suffix', - [ - 'type' => \Magento\Framework\DB\Ddl\Table::TYPE_TEXT, - 'length' => 255, - 'nullable' => false, - 'default' => '', - 'comment' => 'Suffix for indexer table used for read operations', - ] - ); - } -} diff --git a/app/code/Magento/Indexer/Test/Unit/Model/ResourceModel/FrontendResourceTest.php b/app/code/Magento/Indexer/Test/Unit/Model/ResourceModel/FrontendResourceTest.php deleted file mode 100644 index a319002ac2bae..0000000000000 --- a/app/code/Magento/Indexer/Test/Unit/Model/ResourceModel/FrontendResourceTest.php +++ /dev/null @@ -1,98 +0,0 @@ -indexerId = 'indexer_id'; - $this->indexerBaseTable = 'indexer_base_table'; - $this->connectionName = 'connectionName'; - - $this->stateFactoryMock = $this->getMock( - \Magento\Indexer\Model\Indexer\StateFactory::class, - ['create'], - [], - '', - false - ); - - $this->resourceMock = $this->getMock(\Magento\Framework\App\ResourceConnection::class, [], [], '', false); - $contextMock = $this->getMock(\Magento\Framework\Model\ResourceModel\Db\Context::class, [], [], '', false); - $contextMock->expects($this->once())->method('getResources')->willReturn($this->resourceMock); - - $this->model = new \Magento\Indexer\Model\ResourceModel\FrontendResource( - $contextMock, - $this->indexerId, - $this->indexerBaseTable, - 'idFieldName', - $this->stateFactoryMock, - $this->connectionName - ); - } - - public function testGetMainTable() - { - $mainTable = $this->indexerBaseTable . StateInterface::ADDITIONAL_TABLE_SUFFIX; - $stateMock = $this->getMock( - \Magento\Indexer\Model\Indexer\State::class, - ['loadByIndexer', 'getTableSuffix'], - [], - '', - false - ); - $this->stateFactoryMock->expects($this->once())->method('create')->willReturn($stateMock); - - $stateMock->expects($this->once())->method('loadByIndexer')->with($this->indexerId)->willReturnSelf(); - $stateMock->expects($this->once()) - ->method('getTableSuffix') - ->willReturn(StateInterface::ADDITIONAL_TABLE_SUFFIX); - - $this->resourceMock->expects($this->once()) - ->method('getTableName') - ->with($mainTable, $this->connectionName) - ->willReturn($mainTable); - - $this->assertEquals( - $mainTable, - $this->model->getMainTable() - ); - } -} diff --git a/dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer/StockTest.php b/dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer/StockTest.php index 86d0e621f3e41..06d8b590c2611 100644 --- a/dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer/StockTest.php +++ b/dev/tests/integration/testsuite/Magento/Bundle/Model/ResourceModel/Indexer/StockTest.php @@ -37,18 +37,13 @@ public function testReindexAll() \Magento\Catalog\Block\Product\ListProduct::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $category = $categoryFactory->create()->load(2); $layer = $listProduct->getLayer(); $layer->setCurrentCategory($category); $productCollection = $layer->getProductCollection(); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php index f6782bb1ee7ce..3c2ee4bd7fe91 100644 --- a/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php +++ b/dev/tests/integration/testsuite/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/SourceTest.php @@ -67,9 +67,6 @@ public function testReindexEntitiesForConfigurableProduct() $this->_eavIndexerProcessor->reindexAll(); - $suffix = $objectManager->get(\Magento\Indexer\Model\Indexer\StateFactory::class)->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - )->getTableSuffix(); /** @var \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection $options **/ $options = $objectManager->create( \Magento\Eav\Model\ResourceModel\Entity\Attribute\Option\Collection::class @@ -79,7 +76,7 @@ public function testReindexEntitiesForConfigurableProduct() $connection = $this->productResource->getConnection(); - $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav') . $suffix) + $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav')) ->where('entity_id = ?', 1) ->where('attribute_id = ?', $attr->getId()) ->where('value IN (?)', $optionIds); @@ -136,11 +133,8 @@ public function testReindexMultiselectAttribute() $productRepository->save($product2); $this->_eavIndexerProcessor->reindexAll(); - $suffix = $objectManager->get(\Magento\Indexer\Model\Indexer\StateFactory::class)->create()->loadByIndexer( - \Magento\Catalog\Model\Indexer\Product\Eav\Processor::INDEXER_ID - )->getTableSuffix(); $connection = $this->productResource->getConnection(); - $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav') . $suffix) + $select = $connection->select()->from($this->productResource->getTable('catalog_product_index_eav')) ->where('entity_id in (?)', [$product1Id, $product2Id]) ->where('attribute_id = ?', $attr->getId()); diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/FullTest.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/FullTest.php index d98762c5dee6e..88debf19c6844 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/FullTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/FullTest.php @@ -39,18 +39,13 @@ public function testReindexAll() \Magento\Catalog\Block\Product\ListProduct::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $category = $categoryFactory->create()->load(2); $layer = $listProduct->getLayer(); $layer->setCurrentCategory($category); $productCollection = $layer->getProductCollection(); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowTest.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowTest.php index bdad0c853dbbd..9aa805fde8fa6 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowTest.php @@ -55,11 +55,6 @@ public function testProductUpdate() \Magento\Catalog\Model\ProductRepository::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $product = $productRepository->get('simple'); $this->_processor->getIndexer()->setScheduled(false); @@ -86,7 +81,7 @@ public function testProductUpdate() $productCollection = $layer->getProductCollection(); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowsTest.php b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowsTest.php index 421dd2cf9d91e..348d83886f9d2 100644 --- a/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowsTest.php +++ b/dev/tests/integration/testsuite/Magento/CatalogInventory/Model/Indexer/Stock/Action/RowsTest.php @@ -60,11 +60,6 @@ public function testProductUpdate() \Magento\Catalog\Model\ProductRepository::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $product = $productRepository->get('simple'); $stockItem = $stockRegistry->getStockItem($product->getId(), 1); @@ -90,7 +85,7 @@ public function testProductUpdate() $productCollection = $layer->getProductCollection(); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Stock/ConfigurableTest.php b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Stock/ConfigurableTest.php index 1d277a7982ee3..d33312e187b08 100644 --- a/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Stock/ConfigurableTest.php +++ b/dev/tests/integration/testsuite/Magento/ConfigurableProduct/Model/ResourceModel/Product/Indexer/Stock/ConfigurableTest.php @@ -32,16 +32,11 @@ public function testReindexAll() \Magento\Catalog\Model\ResourceModel\Product\Collection::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $productCollection->addUrlRewrite($category->getId()); $productCollection->addAttributeToSelect('name'); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Stock/GroupedTest.php b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Stock/GroupedTest.php index 1d5a7a531e351..db3e6086db714 100644 --- a/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Stock/GroupedTest.php +++ b/dev/tests/integration/testsuite/Magento/GroupedProduct/Model/ResourceModel/Product/Indexer/Stock/GroupedTest.php @@ -39,16 +39,11 @@ public function testReindexAll() \Magento\Catalog\Model\ResourceModel\Product\Collection::class ); - /** @var \Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource */ - $indexerStockFrontendResource = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create( - \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class - ); - $productCollection->addAttributeToSelect('name'); $productCollection->addUrlRewrite($category->getId()); $productCollection->joinField( 'qty', - $indexerStockFrontendResource->getMainTable(), + 'cataloginventory_stock_status', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', diff --git a/lib/internal/Magento/Framework/Indexer/StateInterface.php b/lib/internal/Magento/Framework/Indexer/StateInterface.php index ad4d9bab2ffce..124b8ab50b4b8 100644 --- a/lib/internal/Magento/Framework/Indexer/StateInterface.php +++ b/lib/internal/Magento/Framework/Indexer/StateInterface.php @@ -17,8 +17,6 @@ interface StateInterface const STATUS_VALID = 'valid'; const STATUS_INVALID = 'invalid'; - const ADDITIONAL_TABLE_SUFFIX = '_replica'; - /** * Return indexer id * From 0427fd7fda8fb730ded237788b176a05d4add221 Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 13 Jun 2017 12:09:25 +0300 Subject: [PATCH 2/5] MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching --- .../Model/ResourceModel/Indexer/Stock.php | 33 +++++++++++++++++-- .../Indexer/Category/Product/Action/Full.php | 2 +- .../Model/Indexer/Product/Eav/Action/Full.php | 6 ++-- .../Indexer/Product/Price/Action/Full.php | 12 +++---- .../Indexer/ActiveTableSwitcher.php | 11 ++++++- .../Magento/Catalog/Setup/UpgradeSchema.php | 4 +-- .../Indexer/ActiveTableSwitcherTest.php | 9 +++++ .../Model/Indexer/Stock/Action/Full.php | 2 +- .../CatalogInventory/Setup/UpgradeSchema.php | 4 +-- .../Indexer/Stock/Configurable.php | 32 ++++++++++++++++-- .../ResourceModel/Indexer/Stock/Grouped.php | 33 +++++++++++++++++-- 11 files changed, 126 insertions(+), 22 deletions(-) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php index cdba9e1d62d62..c88abf99d84a5 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php @@ -6,8 +6,8 @@ namespace Magento\Bundle\Model\ResourceModel\Indexer; use Magento\Catalog\Api\Data\ProductInterface; -use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; +use Magento\Framework\App\ObjectManager; /** * Bundle Stock Status Indexer Resource Model @@ -16,6 +16,35 @@ */ class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { + /** + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher + */ + private $activeTableSwitcher; + + /** + * Stock constructor. + * @param \Magento\Framework\Model\ResourceModel\Db\Context $context + * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy + * @param \Magento\Eav\Model\Config $eavConfig + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param null $connectionName + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher + */ + public function __construct( + \Magento\Framework\Model\ResourceModel\Db\Context $context, + \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, + \Magento\Eav\Model\Config $eavConfig, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + $connectionName = null, + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null + ) { + parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName); + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ); + } + + /** * Retrieve table name for temporary bundle option stock index * @@ -38,7 +67,7 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT $this->_cleanBundleOptionStockData(); $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable()) : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $connection = $this->getConnection(); diff --git a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php index 3f935a5b4ed02..e023d4b3ce819 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php @@ -144,7 +144,7 @@ protected function publishData() { $select = $this->connection->select()->from($this->getMainTmpTable()); $columns = array_keys($this->connection->describeTable($this->getMainTable())); - $tableName = $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; + $tableName = $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable()); $this->connection->query( $this->connection->insertFromSelect( diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php index 26b294394ea08..e966c5653fde7 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Eav/Action/Full.php @@ -46,7 +46,7 @@ public function __construct( \Magento\Framework\EntityManager\MetadataPool $metadataPool = null, \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null, \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator $batchSizeCalculator = null, - \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null + ActiveTableSwitcher $activeTableSwitcher = null ) { parent::__construct($eavDecimalFactory, $eavSourceFactory); $this->metadataPool = $metadataPool ?: \Magento\Framework\App\ObjectManager::getInstance()->get( @@ -59,7 +59,7 @@ public function __construct( \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator::class ); $this->activeTableSwitcher = $activeTableSwitcher ?: \Magento\Framework\App\ObjectManager::getInstance()->get( - \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ActiveTableSwitcher::class ); } @@ -76,7 +76,7 @@ public function execute($ids = null) try { foreach ($this->getIndexers() as $indexerName => $indexer) { $connection = $indexer->getConnection(); - $mainTable = $indexer->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; + $mainTable = $this->activeTableSwitcher->getAdditionalTableName($indexer->getMainTable()); $connection->truncateTable($mainTable); $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $batches = $this->batchProvider->getBatches( diff --git a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php index 596a7876867a1..5d2b408665bad 100644 --- a/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php +++ b/app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php @@ -5,7 +5,6 @@ */ namespace Magento\Catalog\Model\Indexer\Product\Price\Action; -use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\Framework\App\ObjectManager; /** @@ -30,7 +29,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction private $batchProvider; /** - * @var ActiveTableSwitcher + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher */ private $activeTableSwitcher; @@ -46,7 +45,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator|null $batchSizeCalculator * @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider - * @param ActiveTableSwitcher|null $activeTableSwitcher + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher * * @SuppressWarnings(PHPMD.ExcessiveParameterList) */ @@ -103,8 +102,9 @@ public function execute($ids = null) $this->_prepareWebsiteDateTable(); $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); - $replicaTable = $this->_defaultIndexerResource->getMainTable() - . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; + $replicaTable = $this->activeTableSwitcher->getAdditionalTableName( + $this->_defaultIndexerResource->getMainTable() + ); /** @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $indexer */ foreach ($this->getTypeIndexers() as $indexer) { @@ -162,6 +162,6 @@ public function execute($ids = null) */ protected function getIndexTargetTable() { - return $this->_defaultIndexerResource->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; + return $this->activeTableSwitcher->getAdditionalTableName($this->_defaultIndexerResource->getMainTable()); } } diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php index e58ba039e31d4..25ca30dbabd25 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php @@ -6,7 +6,7 @@ namespace Magento\Catalog\Model\ResourceModel\Indexer; /** - * Logic for switching active and replica index tables by mysql rename operation. + * Logic for switching active and replica index tables. */ class ActiveTableSwitcher { @@ -45,4 +45,13 @@ public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $conn ] ); } + + /** + * @param string $tableName + * @return string + */ + public function getAdditionalTableName($tableName) + { + return $tableName . self::ADDITIONAL_TABLE_SUFFIX; + } } diff --git a/app/code/Magento/Catalog/Setup/UpgradeSchema.php b/app/code/Magento/Catalog/Setup/UpgradeSchema.php index e9b0a581b4858..4e2409ed57105 100755 --- a/app/code/Magento/Catalog/Setup/UpgradeSchema.php +++ b/app/code/Magento/Catalog/Setup/UpgradeSchema.php @@ -582,8 +582,8 @@ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $r { $sql = sprintf( 'CREATE TABLE IF NOT EXISTS %s LIKE %s', - $setup->getTable($replicaTable), - $setup->getTable($existingTable) + $setup->getConnection()->quoteIdentifier($setup->getTable($replicaTable)), + $setup->getConnection()->quoteIdentifier($setup->getTable($existingTable)) ); $setup->getConnection()->query($sql); } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php index 07654aa0fac9b..70604e9e04299 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php @@ -44,4 +44,13 @@ public function testSwitch() $this->model->switchTable($connectionMock, $tableName); } + + public function testGetAdditionalTableName() + { + $tableName = 'table_name'; + $this->assertEquals( + $tableName . \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX, + $this->model->getAdditionalTableName($tableName) + ); + } } diff --git a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php index db04557f871cf..24281dd1a0c50 100644 --- a/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php +++ b/app/code/Magento/CatalogInventory/Model/Indexer/Stock/Action/Full.php @@ -125,7 +125,7 @@ public function execute($ids = null) foreach ($this->_getTypeIndexers() as $indexer) { $indexer->setActionType(self::ACTION_TYPE); $connection = $indexer->getConnection(); - $tableName = $indexer->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX; + $tableName = $this->activeTableSwitcher->getAdditionalTableName($indexer->getMainTable()); $batchRowCount = isset($this->batchRowsCount[$indexer->getTypeId()]) ? $this->batchRowsCount[$indexer->getTypeId()] diff --git a/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php b/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php index 1017742390eb5..e8f6de22cbfc8 100644 --- a/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php +++ b/app/code/Magento/CatalogInventory/Setup/UpgradeSchema.php @@ -159,8 +159,8 @@ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $r { $sql = sprintf( 'CREATE TABLE IF NOT EXISTS %s LIKE %s', - $setup->getTable($replicaTable), - $setup->getTable($existingTable) + $setup->getConnection()->quoteIdentifier($setup->getTable($replicaTable)), + $setup->getConnection()->quoteIdentifier($setup->getTable($existingTable)) ); $setup->getConnection()->query($sql); } diff --git a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php index 605c4473f9e6d..39fcdf86fdcf4 100644 --- a/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php +++ b/app/code/Magento/ConfigurableProduct/Model/ResourceModel/Indexer/Stock/Configurable.php @@ -13,8 +13,8 @@ * @author Magento Core Team */ use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus; -use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; +use Magento\Framework\App\ObjectManager; /** * Stock indexer for configurable product. @@ -23,6 +23,34 @@ */ class Configurable extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { + /** + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher + */ + private $activeTableSwitcher; + + /** + * Configurable constructor. + * @param \Magento\Framework\Model\ResourceModel\Db\Context $context + * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy + * @param \Magento\Eav\Model\Config $eavConfig + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param null $connectionName + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher + */ + public function __construct( + \Magento\Framework\Model\ResourceModel\Db\Context $context, + \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, + \Magento\Eav\Model\Config $eavConfig, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + $connectionName = null, + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null + ) { + parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName); + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ); + } + /** * Get the select object for get stock status by configurable product ids * @@ -35,7 +63,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); $connection = $this->getConnection(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable()) : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable); diff --git a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php index 039f708de98d4..4195782e993cf 100644 --- a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php @@ -11,7 +11,7 @@ */ namespace Magento\GroupedProduct\Model\ResourceModel\Indexer\Stock; -use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher; +use Magento\Framework\App\ObjectManager; use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full; /** @@ -21,6 +21,35 @@ */ class Grouped extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock { + /** + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher + */ + private $activeTableSwitcher; + + /** + * Grouped constructor. + * @param \Magento\Framework\Model\ResourceModel\Db\Context $context + * @param \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy + * @param \Magento\Eav\Model\Config $eavConfig + * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig + * @param null $connectionName + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher + */ + public function __construct( + \Magento\Framework\Model\ResourceModel\Db\Context $context, + \Magento\Framework\Indexer\Table\StrategyInterface $tableStrategy, + \Magento\Eav\Model\Config $eavConfig, + \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, + $connectionName = null, + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null + ) { + parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName); + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get( + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class + ); + } + + /** * Get the select object for get stock status by grouped product ids * @@ -32,7 +61,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f { $connection = $this->getConnection(); $table = $this->getActionType() === Full::ACTION_TYPE - ? $this->getMainTable() . ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable()) : $this->getMainTable(); $idxTable = $usePrimaryTable ? $table : $this->getIdxTable(); $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class); From afe2c8fc94ea6a3a0dbc202944e425a6a6e699fa Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 13 Jun 2017 12:39:34 +0300 Subject: [PATCH 3/5] MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching --- app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php | 1 - .../GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php | 1 - 2 files changed, 2 deletions(-) diff --git a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php index c88abf99d84a5..8177498a84332 100644 --- a/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php +++ b/app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php @@ -44,7 +44,6 @@ public function __construct( ); } - /** * Retrieve table name for temporary bundle option stock index * diff --git a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php index 4195782e993cf..9d29b02f68bf1 100644 --- a/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php +++ b/app/code/Magento/GroupedProduct/Model/ResourceModel/Indexer/Stock/Grouped.php @@ -49,7 +49,6 @@ public function __construct( ); } - /** * Get the select object for get stock status by grouped product ids * From ffc4c83ec00bffec98a4d725852cba0d818f94dd Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 13 Jun 2017 15:30:40 +0300 Subject: [PATCH 4/5] MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching --- .../ResourceModel/Indexer/ActiveTableSwitcher.php | 14 +++++++------- .../Indexer/ActiveTableSwitcherTest.php | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php index 25ca30dbabd25..234c0823f47da 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php @@ -10,11 +10,11 @@ */ class ActiveTableSwitcher { - /** Suffix for outdated index table. */ - const OUTDATED_TABLE_SUFFIX = '_outdated'; - /** Suffix for replica index table. */ - const ADDITIONAL_TABLE_SUFFIX = '_replica'; + private $additionalTableSuffix = '_replica'; + + /** Suffix for outdated index table. */ + private $outdatedTableSuffix = '_outdated'; /** * Switch index tables from replica to active. @@ -25,8 +25,8 @@ class ActiveTableSwitcher */ public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $tableName) { - $outdatedTableName = $tableName . self::OUTDATED_TABLE_SUFFIX; - $replicaTableName = $tableName . self::ADDITIONAL_TABLE_SUFFIX; + $outdatedTableName = $tableName . $this->outdatedTableSuffix; + $replicaTableName = $tableName . $this->additionalTableSuffix; $connection->renameTablesBatch( [ @@ -52,6 +52,6 @@ public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $conn */ public function getAdditionalTableName($tableName) { - return $tableName . self::ADDITIONAL_TABLE_SUFFIX; + return $tableName . $this->additionalTableSuffix; } } diff --git a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php index 70604e9e04299..3920a0d10370e 100644 --- a/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php +++ b/app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Indexer/ActiveTableSwitcherTest.php @@ -49,7 +49,7 @@ public function testGetAdditionalTableName() { $tableName = 'table_name'; $this->assertEquals( - $tableName . \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::ADDITIONAL_TABLE_SUFFIX, + $tableName . '_replica', $this->model->getAdditionalTableName($tableName) ); } From 0e95567d9e29258eaf953b7a9351312265e3cc7c Mon Sep 17 00:00:00 2001 From: Stanislav Idolov Date: Tue, 20 Jun 2017 10:34:38 +0300 Subject: [PATCH 5/5] MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching --- .../ResourceModel/Product/StockStatusBaseSelectProcessor.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php b/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php index f7d9de6a38b1c..9f89d380a8f96 100644 --- a/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php +++ b/app/code/Magento/CatalogInventory/Model/ResourceModel/Product/StockStatusBaseSelectProcessor.php @@ -8,6 +8,7 @@ use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface; use Magento\CatalogInventory\Model\Stock; +use Magento\Framework\App\ObjectManager; use Magento\Framework\App\ResourceConnection; use Magento\Framework\DB\Select;