Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- diff --git a/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Price.php b/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Price.php
- index 4cf4e15b6c0..64636c8469e 100644
- --- a/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Price.php
- +++ b/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Price.php
- @@ -19,20 +19,11 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D
- *
- * @return $this
- * @throws \Exception
- + * @deprecated
- */
- public function reindexAll()
- {
- - $this->tableStrategy->setUseIdxTable(true);
- -
- - $this->beginTransaction();
- - try {
- - $this->_prepareBundlePrice();
- - $this->commit();
- - } catch (\Exception $e) {
- - $this->rollBack();
- - throw $e;
- - }
- -
- + parent::reindexAll();
- return $this;
- }
- @@ -41,13 +32,20 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D
- *
- * @param int|array $entityIds
- * @return $this
- + * @deprecated
- */
- public function reindexEntity($entityIds)
- {
- - $this->_prepareBundlePrice($entityIds);
- -
- + parent::reindexEntity($entityIds);
- return $this;
- }
- + /**
- + * @inheritdoc
- + */
- + protected function reindex($entityIds = null)
- + {
- + $this->_prepareBundlePrice($entityIds);
- + }
- /**
- * Retrieve temporary price index table name for fixed bundle products
- diff --git a/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Stock.php b/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Stock.php
- index c05c1dc8b7f..c84e2963e13 100644
- --- a/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Stock.php
- +++ b/vendor/magento/module-bundle/Model/ResourceModel/Indexer/Stock.php
- @@ -6,6 +6,8 @@
- namespace Magento\Bundle\Model\ResourceModel\Indexer;
- use Magento\Catalog\Api\Data\ProductInterface;
- +use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
- +use Magento\Framework\App\ObjectManager;
- /**
- * Bundle Stock Status Indexer Resource Model
- @@ -14,16 +16,44 @@ use Magento\Catalog\Api\Data\ProductInterface;
- */
- 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
- + );
- + }
- +
- /**
- * Reindex temporary (price result data) for defined product(s)
- *
- * @param int|array $entityIds
- * @return $this
- + * @deprecated
- */
- public function reindexEntity($entityIds)
- {
- - $this->_updateIndex($entityIds);
- -
- + parent::reindexEntity($entityIds);
- return $this;
- }
- @@ -48,7 +78,10 @@ class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\
- {
- $this->_cleanBundleOptionStockData();
- $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
- - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
- + $table = $this->getActionType() === Full::ACTION_TYPE
- + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable())
- + : $this->getMainTable();
- + $idxTable = $usePrimaryTable ? $table : $this->getIdxTable();
- $connection = $this->getConnection();
- $select = $connection->select()->from(
- ['product' => $this->getTable('catalog_product_entity')],
- diff --git a/vendor/magento/module-bundle/etc/di.xml b/vendor/magento/module-bundle/etc/di.xml
- index 2899ce28d04..64ed00121e6 100644
- --- a/vendor/magento/module-bundle/etc/di.xml
- +++ b/vendor/magento/module-bundle/etc/di.xml
- @@ -129,4 +129,24 @@
- </argument>
- </arguments>
- </type>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
- + <arguments>
- + <argument name="estimators" xsi:type="array">
- + <item name="bundle" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
- + </argument>
- + </arguments>
- + </type>
- + <type name="Magento\Bundle\Model\ResourceModel\Indexer\Price">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- + <type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
- + <arguments>
- + <argument name="batchRowsCount" xsi:type="array">
- + <item name="bundle" xsi:type="number">136</item>
- + </argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Category/Product/AbstractAction.php b/vendor/magento/module-catalog/Model/Indexer/Category/Product/AbstractAction.php
- index 250ea1d477a..013a6e4016f 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Category/Product/AbstractAction.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Category/Product/AbstractAction.php
- @@ -165,6 +165,9 @@ abstract class AbstractAction
- /**
- * Return main index table name
- *
- + * This table should be used on frontend(clients)
- + * The name is switched between 'catalog_category_product_index' and 'catalog_category_product_index_replica'
- + *
- * @return string
- */
- protected function getMainTable()
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Category/Product/Action/Full.php b/vendor/magento/module-catalog/Model/Indexer/Category/Product/Action/Full.php
- index 5a5dced86f9..d4ee1d66757 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Category/Product/Action/Full.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Category/Product/Action/Full.php
- @@ -5,6 +5,22 @@
- */
- namespace Magento\Catalog\Model\Indexer\Category\Product\Action;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +use Magento\Framework\DB\Query\Generator as QueryGenerator;
- +use Magento\Framework\App\ResourceConnection;
- +use Magento\Store\Model\StoreManagerInterface;
- +use Magento\Catalog\Model\Config;
- +use Magento\Framework\Indexer\BatchProviderInterface;
- +use Magento\Framework\Indexer\BatchSizeManagementInterface;
- +use Magento\Framework\EntityManager\MetadataPool;
- +
- +/**
- + * Class Full reindex action
- + *
- + * @package Magento\Catalog\Model\Indexer\Category\Product\Action
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- + */
- class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
- {
- /**
- @@ -14,6 +30,68 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
- */
- protected $useTempTable = false;
- + /**
- + * @var \Magento\Framework\Indexer\BatchSizeManagementInterface
- + */
- + private $batchSizeManagement;
- +
- + /**
- + * @var \Magento\Framework\Indexer\BatchProviderInterface
- + */
- + private $batchProvider;
- +
- + /**
- + * @var \Magento\Framework\EntityManager\MetadataPool
- + */
- + protected $metadataPool;
- +
- + /**
- + * Row count to process in a batch
- + *
- + * @var int
- + */
- + private $batchRowsCount;
- +
- + /**
- + * @var ActiveTableSwitcher
- + */
- + private $activeTableSwitcher;
- +
- + /**
- + * @param ResourceConnection $resource
- + * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- + * @param \Magento\Catalog\Model\Config $config
- + * @param QueryGenerator|null $queryGenerator
- + * @param \Magento\Framework\Indexer\BatchSizeManagementInterface|null $batchSizeManagement
- + * @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider
- + * @param \Magento\Framework\EntityManager\MetadataPool|null $metadataPool
- + * @param int|null $batchRowsCount
- + * @param ActiveTableSwitcher|null $activeTableSwitcher
- + */
- + public function __construct(
- + ResourceConnection $resource,
- + StoreManagerInterface $storeManager,
- + Config $config,
- + QueryGenerator $queryGenerator = null,
- + BatchSizeManagementInterface $batchSizeManagement = null,
- + BatchProviderInterface $batchProvider = null,
- + MetadataPool $metadataPool = null,
- + $batchRowsCount = null,
- + ActiveTableSwitcher $activeTableSwitcher = null
- + ) {
- + parent::__construct(
- + $resource,
- + $storeManager,
- + $config
- + );
- + $objectManager = ObjectManager::getInstance();
- + $this->batchSizeManagement = $batchSizeManagement ?: $objectManager->get(BatchSizeManagementInterface::class);
- + $this->batchProvider = $batchProvider ?: $objectManager->get(BatchProviderInterface::class);
- + $this->metadataPool = $metadataPool ?: $objectManager->get(MetadataPool::class);
- + $this->batchRowsCount = $batchRowsCount;
- + $this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class);
- + }
- +
- /**
- * Refresh entities index
- *
- @@ -21,13 +99,8 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
- */
- public function execute()
- {
- - $this->clearTmpData();
- -
- $this->reindex();
- -
- - $this->publishData();
- - $this->removeUnnecessaryData();
- -
- + $this->activeTableSwitcher->switchTable($this->connection, [$this->getMainTable()]);
- return $this;
- }
- @@ -42,7 +115,7 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
- $this->getMainTable(),
- []
- )->joinLeft(
- - ['t' => $this->getMainTmpTable()],
- + ['t' => $this->getMainTable()],
- $this->getMainTable() .
- '.category_id = t.category_id AND ' .
- $this->getMainTable() .
- @@ -75,19 +148,17 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
- protected function publishData()
- {
- $select = $this->connection->select()->from($this->getMainTmpTable());
- + $columns = array_keys($this->connection->describeTable($this->getMainTable()));
- + $tableName = $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable());
- - $queries = $this->prepareSelectsByRange($select, 'category_id');
- -
- - foreach ($queries as $query) {
- - $this->connection->query(
- - $this->connection->insertFromSelect(
- - $query,
- - $this->getMainTable(),
- - ['category_id', 'product_id', 'position', 'is_parent', 'store_id', 'visibility'],
- - \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
- - )
- - );
- - }
- + $this->connection->query(
- + $this->connection->insertFromSelect(
- + $select,
- + $tableName,
- + $columns,
- + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
- + )
- + );
- }
- /**
- @@ -99,4 +170,75 @@ class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractActio
- {
- $this->connection->delete($this->getMainTmpTable());
- }
- +
- + /**
- + * {@inheritdoc}
- + */
- + protected function reindexRootCategory(\Magento\Store\Model\Store $store)
- + {
- + if ($this->isIndexRootCategoryNeeded()) {
- + $this->reindexCategoriesBySelect($this->getAllProducts($store), 'cp.entity_id IN (?)');
- + }
- + }
- +
- + /**
- + * Reindex products of anchor categories
- + *
- + * @param \Magento\Store\Model\Store $store
- + * @return void
- + */
- + protected function reindexAnchorCategories(\Magento\Store\Model\Store $store)
- + {
- + $this->reindexCategoriesBySelect($this->getAnchorCategoriesSelect($store), 'ccp.product_id IN (?)');
- + }
- +
- + /**
- + * Reindex products of non anchor categories
- + *
- + * @param \Magento\Store\Model\Store $store
- + * @return void
- + */
- + protected function reindexNonAnchorCategories(\Magento\Store\Model\Store $store)
- + {
- + $this->reindexCategoriesBySelect($this->getNonAnchorCategoriesSelect($store), 'ccp.product_id IN (?)');
- + }
- +
- + /**
- + * Reindex categories using given SQL select and condition.
- + *
- + * @param \Magento\Framework\DB\Select $basicSelect
- + * @param string $whereCondition
- + * @return void
- + */
- + private function reindexCategoriesBySelect(\Magento\Framework\DB\Select $basicSelect, $whereCondition)
- + {
- + $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
- + $columns = array_keys($this->connection->describeTable($this->getMainTmpTable()));
- + $this->batchSizeManagement->ensureBatchSize($this->connection, $this->batchRowsCount);
- + $batches = $this->batchProvider->getBatches(
- + $this->connection,
- + $entityMetadata->getEntityTable(),
- + $entityMetadata->getIdentifierField(),
- + $this->batchRowsCount
- + );
- + foreach ($batches as $batch) {
- + $this->clearTmpData();
- + $resultSelect = clone $basicSelect;
- + $select = $this->connection->select();
- + $select->distinct(true);
- + $select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
- + $entityIds = $this->batchProvider->getBatchIds($this->connection, $select, $batch);
- + $resultSelect->where($whereCondition, $entityIds);
- + $this->connection->query(
- + $this->connection->insertFromSelect(
- + $resultSelect,
- + $this->getMainTmpTable(),
- + $columns,
- + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
- + )
- + );
- + $this->publishData();
- + $this->removeUnnecessaryData();
- + }
- + }
- }
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Category/Product/RowSizeEstimator.php b/vendor/magento/module-catalog/Model/Indexer/Category/Product/RowSizeEstimator.php
- new file mode 100644
- index 00000000000..7057d1c0667
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/Indexer/Category/Product/RowSizeEstimator.php
- @@ -0,0 +1,77 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\Indexer\Category\Product;
- +
- +use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
- +
- +/**
- + * Class RowSizeEstimator
- + * Intended to estimate amount of memory necessary for saving the biggest category in the DB
- + * @package Magento\Catalog\Model\Indexer\Category\Product
- + */
- +class RowSizeEstimator implements IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * Amount of memory for index data row.
- + */
- + const ROW_MEMORY_SIZE = 100;
- +
- + /**
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resourceConnection;
- +
- + /**
- + * @param \Magento\Framework\App\ResourceConnection $resourceConnection
- + */
- + public function __construct(
- + \Magento\Framework\App\ResourceConnection $resourceConnection
- + ) {
- + $this->resourceConnection = $resourceConnection;
- + }
- +
- + /**
- + * Calculate memory size for largest possible category in database.
- + *
- + * Result value is a multiplication of
- + * a) maximum amount of products in one category
- + * b) amount of store groups
- + * c) memory amount per each index row in DB table
- + *
- + * {@inheritdoc}
- + */
- + public function estimateRowSize()
- + {
- + $connection = $this->resourceConnection->getConnection();
- +
- + // get store groups count except the default
- + $storeGroupSelect = $connection->select()
- + ->from(
- + $this->resourceConnection->getTableName('store_group'),
- + ['count' => new \Zend_Db_Expr('count(*)')]
- + )->where('group_id > 0');
- + $storeGroupCount = $connection->fetchOne($storeGroupSelect);
- +
- + // get max possible categories per product
- + // subselect with categories count per product
- + $categoryCounterSubSelect = $connection->select()
- + ->from(
- + $this->resourceConnection->getTableName('catalog_category_product'),
- + ['counter' => new \Zend_Db_Expr('count(category_id)')]
- + )->group('product_id');
- +
- + // select maximum value from subselect
- + $productCountSelect = $connection->select()
- + ->from(
- + ['counters' => $categoryCounterSubSelect],
- + [new \Zend_Db_Expr('max(counter)')]
- + );
- + $maxProducts = $connection->fetchOne($productCountSelect);
- +
- + return ceil($storeGroupCount * $maxProducts * self::ROW_MEMORY_SIZE);
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Product/Eav/AbstractAction.php b/vendor/magento/module-catalog/Model/Indexer/Product/Eav/AbstractAction.php
- index bd3586eff92..ce31c4f2182 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Product/Eav/AbstractAction.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Product/Eav/AbstractAction.php
- @@ -28,6 +28,7 @@ abstract class AbstractAction
- protected $_eavDecimalFactory;
- /**
- + * AbstractAction constructor.
- * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory $eavDecimalFactory
- * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory $eavSourceFactory
- */
- @@ -84,6 +85,7 @@ abstract class AbstractAction
- * Reindex entities
- *
- * @param null|array|int $ids
- + * @throws \Exception
- * @return void
- */
- public function reindex($ids = null)
- @@ -92,8 +94,55 @@ abstract class AbstractAction
- if ($ids === null) {
- $indexer->reindexAll();
- } else {
- + if (!is_array($ids)) {
- + $ids = [$ids];
- + }
- + $ids = $this->processRelations($indexer, $ids);
- $indexer->reindexEntities($ids);
- + $destinationTable = $indexer->getMainTable();
- + $this->syncData($indexer, $destinationTable, $ids);
- }
- }
- }
- +
- + /**
- + * Synchronize data between index storage and original storage
- + *
- + * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\AbstractEav $indexer
- + * @param string $destinationTable
- + * @param array $ids
- + * @throws \Exception
- + * @return void
- + */
- + protected function syncData($indexer, $destinationTable, $ids)
- + {
- + $connection = $indexer->getConnection();
- + $connection->beginTransaction();
- + try {
- + // remove old index
- + $where = $connection->quoteInto('entity_id IN(?)', $ids);
- + $connection->delete($destinationTable, $where);
- + // insert new index
- + $indexer->insertFromTable($indexer->getIdxTable(), $destinationTable);
- + $connection->commit();
- + } catch (\Exception $e) {
- + $connection->rollBack();
- + throw $e;
- + }
- + }
- +
- + /**
- + * Retrieve product relations by children and parent
- + *
- + * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\AbstractEav $indexer
- + * @param array $ids
- + *
- + * @return $ids
- + */
- + protected function processRelations($indexer, $ids)
- + {
- + $parentIds = $indexer->getRelationsByChild($ids);
- + $childIds = $indexer->getRelationsByParent($ids);
- + return array_unique(array_merge($ids, $childIds, $parentIds));
- + }
- }
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Product/Eav/Action/Full.php b/vendor/magento/module-catalog/Model/Indexer/Product/Eav/Action/Full.php
- index 7c2b2c137da..0c41c3e6eb0 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Product/Eav/Action/Full.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Product/Eav/Action/Full.php
- @@ -5,11 +5,66 @@
- */
- namespace Magento\Catalog\Model\Indexer\Product\Eav\Action;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalFactory;
- +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceFactory;
- +use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Framework\Indexer\BatchProviderInterface;
- +use Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +use Magento\Catalog\Api\Data\ProductInterface;
- +use Magento\Framework\Exception\LocalizedException;
- +use Magento\Framework\DB\Adapter\AdapterInterface;
- +
- /**
- * Class Full reindex action
- */
- class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
- {
- + /**
- + * @var \Magento\Framework\EntityManager\MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @var \Magento\Framework\Indexer\BatchProviderInterface
- + */
- + private $batchProvider;
- +
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator
- + */
- + 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 ActiveTableSwitcher|null $activeTableSwitcher
- + */
- + public function __construct(
- + DecimalFactory $eavDecimalFactory,
- + SourceFactory $eavSourceFactory,
- + MetadataPool $metadataPool = null,
- + BatchProviderInterface $batchProvider = null,
- + BatchSizeCalculator $batchSizeCalculator = null,
- + ActiveTableSwitcher $activeTableSwitcher = null
- + ) {
- + parent::__construct($eavDecimalFactory, $eavSourceFactory);
- + $objectManager = ObjectManager::getInstance();
- + $this->metadataPool = $metadataPool ?: $objectManager->get(MetadataPool::class);
- + $this->batchProvider = $batchProvider ?: $objectManager->get(BatchProviderInterface::class);
- + $this->batchSizeCalculator = $batchSizeCalculator ?: $objectManager->get(BatchSizeCalculator::class);
- + $this->activeTableSwitcher = $activeTableSwitcher ?: $objectManager->get(ActiveTableSwitcher::class);
- + }
- +
- /**
- * Execute Full reindex
- *
- @@ -21,9 +76,59 @@ class Full extends \Magento\Catalog\Model\Indexer\Product\Eav\AbstractAction
- public function execute($ids = null)
- {
- try {
- - $this->reindex();
- + foreach ($this->getIndexers() as $indexerName => $indexer) {
- + $connection = $indexer->getConnection();
- + $mainTable = $this->activeTableSwitcher->getAdditionalTableName($indexer->getMainTable());
- + $connection->truncateTable($mainTable);
- + $entityMetadata = $this->metadataPool->getMetadata(ProductInterface::class);
- + $batches = $this->batchProvider->getBatches(
- + $connection,
- + $entityMetadata->getEntityTable(),
- + $entityMetadata->getIdentifierField(),
- + $this->batchSizeCalculator->estimateBatchSize($connection, $indexerName)
- + );
- +
- + foreach ($batches as $batch) {
- + /** @var \Magento\Framework\DB\Select $select */
- + $select = $connection->select();
- + $select->distinct(true);
- + $select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
- + $entityIds = $this->batchProvider->getBatchIds($connection, $select, $batch);
- + if (!empty($entityIds)) {
- + $indexer->reindexEntities($this->processRelations($indexer, $entityIds));
- + $this->syncData($indexer, $mainTable);
- + }
- + }
- + $this->activeTableSwitcher->switchTable($indexer->getConnection(), [$indexer->getMainTable()]);
- + }
- + } catch (\Exception $e) {
- + throw new LocalizedException(__($e->getMessage()), $e);
- + }
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + protected function syncData($indexer, $destinationTable, $ids = null)
- + {
- + $connection = $indexer->getConnection();
- + $connection->beginTransaction();
- + try {
- + $sourceTable = $indexer->getIdxTable();
- + $sourceColumns = array_keys($connection->describeTable($sourceTable));
- + $targetColumns = array_keys($connection->describeTable($destinationTable));
- + $select = $connection->select()->from($sourceTable, $sourceColumns);
- + $query = $connection->insertFromSelect(
- + $select,
- + $destinationTable,
- + $targetColumns,
- + AdapterInterface::INSERT_ON_DUPLICATE
- + );
- + $connection->query($query);
- + $connection->commit();
- } catch (\Exception $e) {
- - throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
- + $connection->rollBack();
- + throw $e;
- }
- }
- }
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Product/Price/AbstractAction.php b/vendor/magento/module-catalog/Model/Indexer/Product/Price/AbstractAction.php
- index 3b3804220db..b41de15063e 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Product/Price/AbstractAction.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Product/Price/AbstractAction.php
- @@ -70,6 +70,11 @@ abstract class AbstractAction
- */
- protected $_indexers;
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Product
- + */
- + private $productResource;
- +
- /**
- * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- @@ -213,46 +218,80 @@ abstract class AbstractAction
- $table = $this->_defaultIndexerResource->getTable('catalog_product_index_tier_price');
- $this->_emptyTable($table);
- - $websiteExpression = $this->_connection->getCheckSql(
- - 'tp.website_id = 0',
- - 'ROUND(tp.value * cwd.rate, 4)',
- - 'tp.value'
- - );
- $linkField = $this->getProductIdFieldName();
- - $select = $this->_connection->select()->from(
- + $priceAttribute = $this->getProductResource()->getAttribute('price');
- + $baseColumns = [
- + 'cpe.entity_id',
- + 'tp.customer_group_id',
- + 'tp.website_id'
- + ];
- + if ($linkField !== 'entity_id') {
- + $baseColumns[] = 'cpe.' . $linkField;
- + };
- + $subSelect = $this->_connection->select()->from(
- ['cpe' => $this->_defaultIndexerResource->getTable('catalog_product_entity')],
- - ['cpe.entity_id']
- - )->join(
- + array_merge_recursive(
- + $baseColumns,
- + ['value' => 'min(tp.value)']
- + )
- + )->joinInner(
- ['tp' => $this->_defaultIndexerResource->getTable(['catalog_product_entity', 'tier_price'])],
- 'tp.' . $linkField . ' = cpe.' . $linkField,
- []
- - )->join(
- - ['cg' => $this->_defaultIndexerResource->getTable('customer_group')],
- - 'tp.all_groups = 1 OR (tp.all_groups = 0 AND tp.customer_group_id = cg.customer_group_id)',
- - ['customer_group_id']
- - )->join(
- - ['cw' => $this->_defaultIndexerResource->getTable('store_website')],
- - 'tp.website_id = 0 OR tp.website_id = cw.website_id',
- - ['website_id']
- - )->join(
- - ['cwd' => $this->_defaultIndexerResource->getTable('catalog_product_index_website')],
- - 'cw.website_id = cwd.website_id',
- - []
- - )->where(
- - 'cw.website_id != 0'
- - )->columns(
- - new \Zend_Db_Expr("MIN({$websiteExpression})")
- - )->group(
- - ['cpe.entity_id', 'cg.customer_group_id', 'cw.website_id']
- - );
- + )->where("cpe.entity_id IN(?)", $entityIds)
- + ->where("tp.website_id != 0")
- + ->group(['cpe.entity_id', 'tp.customer_group_id', 'tp.website_id']);
- +
- + $subSelect2 = $this->_connection->select()
- + ->from(
- + ['cpe' => $this->_defaultIndexerResource->getTable('catalog_product_entity')],
- + array_merge_recursive(
- + $baseColumns,
- + ['MIN(ROUND(tp.value * cwd.rate, 4)) AS value']
- + )
- + )
- + ->joinInner(
- + ['tp' => $this->_defaultIndexerResource->getTable(['catalog_product_entity', 'tier_price'])],
- + 'tp.' . $linkField . ' = cpe.' . $linkField,
- + []
- + )->join(
- + ['cw' => $this->_defaultIndexerResource->getTable('store_website')],
- + true,
- + []
- + )
- + ->joinInner(
- + ['cwd' => $this->_defaultIndexerResource->getTable('catalog_product_index_website')],
- + 'cw.website_id = cwd.website_id',
- + []
- + )
- + ->where("cpe.entity_id IN(?)", $entityIds)
- + ->where("tp.website_id = 0")
- + ->group(
- + ['cpe.entity_id', 'tp.customer_group_id', 'tp.website_id']
- + );
- - if (!empty($entityIds)) {
- - $select->where("cpe.entity_id IN(?)", $entityIds);
- - }
- + $unionSelect = $this->_connection->select()
- + ->union([$subSelect, $subSelect2], \Magento\Framework\DB\Select::SQL_UNION_ALL);
- + $select = $this->_connection->select()
- + ->from(
- + ['b' => new \Zend_Db_Expr(sprintf('(%s)', $unionSelect->assemble()))],
- + [
- + 'b.entity_id',
- + 'b.customer_group_id',
- + 'b.website_id',
- + 'b.value'
- + ]
- + )
- + ->joinInner(
- + ['product_price' => $priceAttribute->getBackend()->getTable()],
- + 'b.' . $linkField . ' = product_price.' . $linkField,
- + []
- + )
- + ->group(['b.entity_id', 'b.customer_group_id', 'b.website_id']);
- +
- + $query = $select->insertFromSelect($table, [], false);
- - $query = $select->insertFromSelect($table);
- $this->_connection->query($query);
- -
- return $this;
- }
- @@ -441,7 +480,7 @@ abstract class AbstractAction
- if ($children) {
- $select = $this->_connection->select()->from(
- - $this->_defaultIndexerResource->getTable('catalog_product_index_price')
- + $this->getIndexTargetTable()
- )->where(
- 'entity_id IN(?)',
- $children
- @@ -453,6 +492,18 @@ abstract class AbstractAction
- return $this;
- }
- + /**
- + * Retrieve index table that will be used for write operations.
- + *
- + * This method is used during both partial and full reindex to identify the table.
- + *
- + * @return string
- + */
- + protected function getIndexTargetTable()
- + {
- + return $this->_defaultIndexerResource->getTable('catalog_product_index_price');
- + }
- +
- /**
- * @return string
- */
- @@ -462,4 +513,17 @@ abstract class AbstractAction
- $indexList = $this->_connection->getIndexList($table);
- return $indexList[$this->_connection->getPrimaryKeyName($table)]['COLUMNS_LIST'][0];
- }
- +
- + /**
- + * @return \Magento\Catalog\Model\ResourceModel\Product
- + * @deprecated
- + */
- + private function getProductResource()
- + {
- + if (null === $this->productResource) {
- + $this->productResource = \Magento\Framework\App\ObjectManager::getInstance()
- + ->get(\Magento\Catalog\Model\ResourceModel\Product::class);
- + }
- + return $this->productResource;
- + }
- }
- diff --git a/vendor/magento/module-catalog/Model/Indexer/Product/Price/Action/Full.php b/vendor/magento/module-catalog/Model/Indexer/Product/Price/Action/Full.php
- index 8148703b177..ed43c243f35 100644
- --- a/vendor/magento/module-catalog/Model/Indexer/Product/Price/Action/Full.php
- +++ b/vendor/magento/module-catalog/Model/Indexer/Product/Price/Action/Full.php
- @@ -5,33 +5,163 @@
- */
- namespace Magento\Catalog\Model\Indexer\Product\Price\Action;
- +use Magento\Framework\App\ObjectManager;
- +
- /**
- * Class Full reindex action
- - *
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class Full extends \Magento\Catalog\Model\Indexer\Product\Price\AbstractAction
- {
- + /**
- + * @var \Magento\Framework\EntityManager\MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator
- + */
- + private $batchSizeCalculator;
- +
- + /**
- + * @var \Magento\Framework\Indexer\BatchProviderInterface
- + */
- + private $batchProvider;
- +
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
- + */
- + private $activeTableSwitcher;
- +
- + /**
- + * @param \Magento\Framework\App\Config\ScopeConfigInterface $config
- + * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- + * @param \Magento\Directory\Model\CurrencyFactory $currencyFactory
- + * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
- + * @param \Magento\Framework\Stdlib\DateTime $dateTime
- + * @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\Framework\EntityManager\MetadataPool|null $metadataPool
- + * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator|null $batchSizeCalculator
- + * @param \Magento\Framework\Indexer\BatchProviderInterface|null $batchProvider
- + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
- + *
- + * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- + */
- + public function __construct(
- + \Magento\Framework\App\Config\ScopeConfigInterface $config,
- + \Magento\Store\Model\StoreManagerInterface $storeManager,
- + \Magento\Directory\Model\CurrencyFactory $currencyFactory,
- + \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
- + \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\Framework\EntityManager\MetadataPool $metadataPool = null,
- + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator $batchSizeCalculator = null,
- + \Magento\Framework\Indexer\BatchProviderInterface $batchProvider = null,
- + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null
- + ) {
- + parent::__construct(
- + $config,
- + $storeManager,
- + $currencyFactory,
- + $localeDate,
- + $dateTime,
- + $catalogProductType,
- + $indexerPriceFactory,
- + $defaultIndexerResource
- + );
- + $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(
- + \Magento\Framework\EntityManager\MetadataPool::class
- + );
- + $this->batchSizeCalculator = $batchSizeCalculator ?: ObjectManager::getInstance()->get(
- + \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator::class
- + );
- + $this->batchProvider = $batchProvider ?: ObjectManager::getInstance()->get(
- + \Magento\Framework\Indexer\BatchProviderInterface::class
- + );
- + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get(
- + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class
- + );
- + }
- +
- /**
- * Execute Full reindex
- *
- * @param array|int|null $ids
- * @return void
- * @throws \Magento\Framework\Exception\LocalizedException
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function execute($ids = null)
- {
- try {
- - $this->_defaultIndexerResource->getTableStrategy()->setUseIdxTable(true);
- - $this->_emptyTable($this->_defaultIndexerResource->getIdxTable());
- + $this->_defaultIndexerResource->getTableStrategy()->setUseIdxTable(false);
- $this->_prepareWebsiteDateTable();
- - $this->_prepareTierPriceIndex();
- + $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
- + $replicaTable = $this->activeTableSwitcher->getAdditionalTableName(
- + $this->_defaultIndexerResource->getMainTable()
- + );
- +
- + /** @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer $indexer */
- foreach ($this->getTypeIndexers() as $indexer) {
- - $indexer->reindexAll();
- + $indexer->getTableStrategy()->setUseIdxTable(false);
- + $connection = $indexer->getConnection();
- +
- + $batches = $this->batchProvider->getBatches(
- + $connection,
- + $entityMetadata->getEntityTable(),
- + $entityMetadata->getIdentifierField(),
- + $this->batchSizeCalculator->estimateBatchSize($connection, $indexer->getTypeId())
- + );
- +
- + foreach ($batches as $batch) {
- + // Get entity ids from batch
- + $select = $connection->select();
- + $select->distinct(true);
- + $select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
- + $select->where('type_id = ?', $indexer->getTypeId());
- +
- + $entityIds = $this->batchProvider->getBatchIds($connection, $select, $batch);
- +
- + if (!empty($entityIds)) {
- + // Temporary table will created if not exists
- + $idxTableName = $this->_defaultIndexerResource->getIdxTable();
- + $this->_emptyTable($idxTableName);
- +
- + if ($indexer->getIsComposite()) {
- + $this->_copyRelationIndexData($entityIds);
- + }
- + $this->_prepareTierPriceIndex($entityIds);
- +
- + // Reindex entities by id
- + $indexer->reindexEntity($entityIds);
- +
- + // Sync data from temp table to index table
- + $this->_insertFromTable($idxTableName, $replicaTable);
- +
- + // Drop temporary index table
- + $connection->dropTable($idxTableName);
- + }
- + }
- }
- - $this->_syncData();
- + $this->activeTableSwitcher->switchTable(
- + $this->_defaultIndexerResource->getConnection(),
- + [$this->_defaultIndexerResource->getMainTable()]
- + );
- } catch (\Exception $e) {
- throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
- }
- }
- +
- + /**
- + * @inheritdoc
- + */
- + protected function getIndexTargetTable()
- + {
- + return $this->activeTableSwitcher->getAdditionalTableName($this->_defaultIndexerResource->getMainTable());
- + }
- }
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php b/vendor/magento/module-catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php
- new file mode 100644
- index 00000000000..6d3451f2d90
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Indexer/ActiveTableSwitcher.php
- @@ -0,0 +1,63 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\Catalog\Model\ResourceModel\Indexer;
- +
- +/**
- + * Logic for switching active and replica index tables.
- + */
- +class ActiveTableSwitcher
- +{
- + /** Suffix for replica index table. */
- + private $additionalTableSuffix = '_replica';
- +
- + /** Suffix for outdated index table. */
- + private $outdatedTableSuffix = '_outdated';
- +
- + /**
- + * Switch index tables from replica to active.
- + *
- + * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
- + * @param array $tableNames
- + * @return void
- + */
- + public function switchTable(\Magento\Framework\DB\Adapter\AdapterInterface $connection, array $tableNames)
- + {
- + $toRename = [];
- + foreach ($tableNames as $tableName) {
- + $outdatedTableName = $tableName . $this->outdatedTableSuffix;
- + $replicaTableName = $tableName . $this->additionalTableSuffix;
- +
- + $renameBatch = [
- + [
- + 'oldName' => $tableName,
- + 'newName' => $outdatedTableName
- + ],
- + [
- + 'oldName' => $replicaTableName,
- + 'newName' => $tableName
- + ],
- + [
- + 'oldName' => $outdatedTableName,
- + 'newName' => $replicaTableName
- + ]
- + ];
- + $toRename = array_merge($toRename, $renameBatch);
- + }
- +
- + if (!empty($toRename)) {
- + $connection->renameTablesBatch($toRename);
- + }
- + }
- +
- + /**
- + * @param string $tableName
- + * @return string
- + */
- + public function getAdditionalTableName($tableName)
- + {
- + return $tableName . $this->additionalTableSuffix;
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Price.php b/vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Price.php
- index a8b7bf29601..a99d88aa914 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Price.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Layer/Filter/Price.php
- @@ -7,6 +7,7 @@ namespace Magento\Catalog\Model\ResourceModel\Layer\Filter;
- /**
- * Catalog Layer Price Filter resource model
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class Price extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
- {
- @@ -43,7 +44,7 @@ class Price extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
- * @param \Magento\Catalog\Model\Layer\Resolver $layerResolver
- * @param \Magento\Customer\Model\Session $session
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- - * @param string $connectionName
- + * @param null $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php
- index 7cd1c8c09fc..ca7b8e9badf 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php
- @@ -11,6 +11,7 @@ use Magento\Catalog\Api\Data\ProductInterface;
- * Catalog Product Eav Attributes abstract indexer resource model
- *
- * @author Magento Core Team <core@magentocommerce.com>
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer
- {
- @@ -22,13 +23,12 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\
- protected $_eventManager = null;
- /**
- - * Construct
- - *
- + * AbstractEav 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\Event\ManagerInterface $eventManager
- - * @param string $connectionName
- + * @param null $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- @@ -75,40 +75,11 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\
- */
- public function reindexEntities($processIds)
- {
- - $connection = $this->getConnection();
- -
- $this->clearTemporaryIndexTable();
- - if (!is_array($processIds)) {
- - $processIds = [$processIds];
- - }
- -
- - $parentIds = $this->getRelationsByChild($processIds);
- - if ($parentIds) {
- - $processIds = array_unique(array_merge($processIds, $parentIds));
- - }
- - $childIds = $this->getRelationsByParent($processIds);
- - if ($childIds) {
- - $processIds = array_unique(array_merge($processIds, $childIds));
- - }
- -
- $this->_prepareIndex($processIds);
- $this->_prepareRelationIndex($processIds);
- $this->_removeNotVisibleEntityFromIndex();
- -
- - $connection->beginTransaction();
- - try {
- - // remove old index
- - $where = $connection->quoteInto('entity_id IN(?)', $processIds);
- - $connection->delete($this->getMainTable(), $where);
- -
- - // insert new index
- - $this->insertFromTable($this->getIdxTable(), $this->getMainTable());
- - $connection->commit();
- - } catch (\Exception $e) {
- - $connection->rollBack();
- - throw $e;
- - }
- return $this;
- }
- @@ -218,7 +189,8 @@ abstract class AbstractEav extends \Magento\Catalog\Model\ResourceModel\Product\
- ]
- );
- if ($parentIds !== null) {
- - $select->where('e.entity_id IN(?)', $parentIds);
- + $ids = implode(',', array_map('intval', $parentIds));
- + $select->where("e.entity_id IN({$ids})");
- }
- /**
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/BatchSizeCalculator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/BatchSizeCalculator.php
- new file mode 100644
- index 00000000000..479dcf70f4a
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/BatchSizeCalculator.php
- @@ -0,0 +1,60 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav;
- +
- +use Magento\Framework\DB\Adapter\AdapterInterface;
- +use Magento\Framework\Exception\NoSuchEntityException;
- +
- +/**
- + * Composite batch size calculator for EAV related indexers.
- + *
- + * Can be configured to provide batch sizes for different indexer types.
- + */
- +class BatchSizeCalculator
- +{
- + /**
- + * @var array
- + */
- + private $batchSizes;
- +
- + /**
- + * @var \Magento\Framework\Indexer\BatchSizeManagement[]
- + */
- + private $batchSizeManagers;
- +
- + /**
- + * @param array $batchSizes preferable sizes (number of rows in batch) of batches per index type
- + * @param array $batchSizeManagers batch managers per index type
- + */
- + public function __construct(
- + array $batchSizes,
- + array $batchSizeManagers
- + ) {
- + $this->batchSizes = $batchSizes;
- + $this->batchSizeManagers = $batchSizeManagers;
- + }
- +
- + /**
- + * Estimate batch size and ensure that database will be able to handle it properly.
- + *
- + * @param AdapterInterface $connection
- + * @param string $indexerTypeId unique identifier of the indexer
- + * @return int estimated batch size
- + * @throws NoSuchEntityException thrown if indexer identifier is not recognized
- + */
- + public function estimateBatchSize(
- + AdapterInterface $connection,
- + $indexerTypeId
- + ) {
- + if (!isset($this->batchSizes[$indexerTypeId])) {
- + throw NoSuchEntityException::singleField('indexTypeId', $indexerTypeId);
- + }
- + $this->batchSizeManagers[$indexerTypeId]->ensureBatchSize($connection, $this->batchSizes[$indexerTypeId]);
- +
- + return $this->batchSizes[$indexerTypeId];
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/DecimalRowSizeEstimator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/DecimalRowSizeEstimator.php
- new file mode 100644
- index 00000000000..0c8c3a9c0b1
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/DecimalRowSizeEstimator.php
- @@ -0,0 +1,79 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav;
- +
- +use Magento\Store\Api\StoreManagementInterface;
- +use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
- +use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Catalog\Api\Data\ProductInterface;
- +
- +/**
- + * Estimator of the EAV decimal index table row size.
- + *
- + * Estimates the amount of memory required to store the index data of the product
- + * with the highest number of attributes/values.
- + *
- + * Can be used with batch size manager to ensure that the batch will be handled correctly by the database.
- + * @see \Magento\Framework\Indexer\BatchSizeManagement
- + */
- +class DecimalRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * @var Decimal
- + */
- + private $indexerResource;
- +
- + /**
- + * @var StoreManagementInterface
- + */
- + private $storeManagement;
- +
- + /**
- + * @var MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @param StoreManagementInterface $storeManagement
- + * @param Decimal $indexerResource
- + * @param MetadataPool $metadataPool
- + */
- + public function __construct(
- + StoreManagementInterface $storeManagement,
- + Decimal $indexerResource,
- + MetadataPool $metadataPool
- + ) {
- + $this->storeManagement = $storeManagement;
- + $this->indexerResource = $indexerResource;
- + $this->metadataPool = $metadataPool;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function estimateRowSize()
- + {
- + $connection = $this->indexerResource->getConnection();
- + $entityIdField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
- +
- + $valueSelect = $connection->select();
- + $valueSelect->from(
- + ['value_table' => $this->indexerResource->getTable('catalog_product_entity_decimal')],
- + ['count' => new \Zend_Db_Expr('count(value_table.value_id)')]
- + );
- + $valueSelect->group([$entityIdField, 'store_id']);
- +
- + $maxSelect = $connection->select();
- + $maxSelect->from(
- + ['max_value' => $valueSelect],
- + ['count' => new \Zend_Db_Expr('MAX(count)')]
- + );
- + $maxRowsPerStore = $connection->fetchOne($maxSelect);
- +
- + return ceil($maxRowsPerStore * $this->storeManagement->getCount() * 500);
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- index e7cf48c378c..364f7dad61d 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- @@ -11,10 +11,12 @@ use Magento\Catalog\Api\Data\ProductInterface;
- /**
- * Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
- *
- - * @author Magento Core Team <core@magentocommerce.com>
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class Source extends AbstractEav
- {
- + const TRANSIT_PREFIX = 'transit_';
- +
- /**
- * Catalog resource helper
- *
- @@ -30,7 +32,7 @@ class Source extends AbstractEav
- * @param \Magento\Eav\Model\Config $eavConfig
- * @param \Magento\Framework\Event\ManagerInterface $eventManager
- * @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
- - * @param string $connectionName
- + * @param null|string $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- @@ -40,8 +42,14 @@ class Source extends AbstractEav
- \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
- $connectionName = null
- ) {
- + parent::__construct(
- + $context,
- + $tableStrategy,
- + $eavConfig,
- + $eventManager,
- + $connectionName
- + );
- $this->_resourceHelper = $resourceHelper;
- - parent::__construct($context, $tableStrategy, $eavConfig, $eventManager, $connectionName);
- }
- /**
- @@ -110,30 +118,27 @@ class Source extends AbstractEav
- $connection = $this->getConnection();
- $idxTable = $this->getIdxTable();
- // prepare select attributes
- - if ($attributeId === null) {
- - $attrIds = $this->_getIndexableAttributes(false);
- - } else {
- - $attrIds = [$attributeId];
- - }
- -
- + $attrIds = $attributeId === null ? $this->_getIndexableAttributes(false) : [$attributeId];
- if (!$attrIds) {
- return $this;
- }
- $productIdField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
- + $attrIdsFlat = implode(',', array_map('intval', $attrIds));
- + $ifNullSql = $connection->getIfNullSql('pis.value', 'COALESCE(ds.value, dd.value)');
- - /**@var $subSelect \Magento\Framework\DB\Select*/
- - $subSelect = $connection->select()->from(
- + /**@var $select \Magento\Framework\DB\Select*/
- + $select = $connection->select()->distinct(true)->from(
- ['s' => $this->getTable('store')],
- - ['store_id', 'website_id']
- + []
- )->joinLeft(
- ['dd' => $this->getTable('catalog_product_entity_int')],
- 'dd.store_id = 0',
- - ['attribute_id']
- + []
- )->joinLeft(
- ['ds' => $this->getTable('catalog_product_entity_int')],
- "ds.store_id = s.store_id AND ds.attribute_id = dd.attribute_id AND " .
- "ds.{$productIdField} = dd.{$productIdField}",
- - ['value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)')]
- + []
- )->joinLeft(
- ['d2d' => $this->getTable('catalog_product_entity_int')],
- sprintf(
- @@ -149,48 +154,38 @@ class Source extends AbstractEav
- )->joinLeft(
- ['cpe' => $this->getTable('catalog_product_entity')],
- "cpe.{$productIdField} = dd.{$productIdField}",
- - array_unique([$productIdField, 'entity_id'])
- + []
- + )->joinLeft(
- + ['pis' => $this->getTable('catalog_product_entity_int')],
- + "pis.{$productIdField} = cpe.{$productIdField} " .
- + "AND pis.attribute_id = dd.attribute_id AND pis.store_id = s.store_id",
- + []
- )->where(
- 's.store_id != 0'
- )->where(
- '(ds.value IS NOT NULL OR dd.value IS NOT NULL)'
- )->where(
- (new \Zend_Db_Expr('COALESCE(d2s.value, d2d.value)')) . ' = ' . ProductStatus::STATUS_ENABLED
- - )->distinct(true);
- -
- - if ($entityIds !== null) {
- - $subSelect->where('cpe.entity_id IN(?)', $entityIds);
- - }
- -
- - $ifNullSql = $connection->getIfNullSql('pis.value', 'pid.value');
- - /**@var $select \Magento\Framework\DB\Select*/
- - $select = $connection->select()->distinct(true)->from(
- - ['pid' => new \Zend_Db_Expr(sprintf('(%s)', $subSelect->assemble()))],
- - []
- - )->joinLeft(
- - ['pis' => $this->getTable('catalog_product_entity_int')],
- - "pis.{$productIdField} = pid.{$productIdField}"
- - .' AND pis.attribute_id = pid.attribute_id AND pis.store_id = pid.store_id',
- - []
- + )->where(
- + "dd.attribute_id IN({$attrIdsFlat})"
- + )->where(
- + 'NOT(pis.value IS NULL AND pis.value_id IS NOT NULL)'
- + )->where(
- + $ifNullSql . ' IS NOT NULL'
- )->columns(
- [
- - 'pid.entity_id',
- - 'pid.attribute_id',
- - 'pid.store_id',
- - 'value' => $ifNullSql,
- - 'pid.entity_id',
- + 'cpe.entity_id',
- + 'dd.attribute_id',
- + 's.store_id',
- + 'value' => new \Zend_Db_Expr('COALESCE(ds.value, dd.value)'),
- + 'cpe.entity_id',
- ]
- - )->where(
- - 'pid.attribute_id IN(?)',
- - $attrIds
- );
- - $select->where($ifNullSql . ' IS NOT NULL');
- -
- - /**
- - * Exclude attribute values that contains NULL
- - */
- - $select->where('NOT(pis.value IS NULL AND pis.value_id IS NOT NULL)');
- + if ($entityIds !== null) {
- + $ids = implode(',', array_map('intval', $entityIds));
- + $select->where("cpe.entity_id IN({$ids})");
- + }
- /**
- * Add additional external limitation
- @@ -199,14 +194,13 @@ class Source extends AbstractEav
- 'prepare_catalog_product_index_select',
- [
- 'select' => $select,
- - 'entity_field' => new \Zend_Db_Expr('pid.entity_id'),
- - 'website_field' => new \Zend_Db_Expr('pid.website_id'),
- - 'store_field' => new \Zend_Db_Expr('pid.store_id'),
- + 'entity_field' => new \Zend_Db_Expr('cpe.entity_id'),
- + 'website_field' => new \Zend_Db_Expr('s.website_id'),
- + 'store_field' => new \Zend_Db_Expr('s.store_id'),
- ]
- );
- $query = $select->insertFromSelect($idxTable);
- $connection->query($query);
- -
- return $this;
- }
- @@ -325,11 +319,8 @@ class Source extends AbstractEav
- }
- /**
- - * Prepares data from select to save.
- - *
- * @param \Magento\Framework\DB\Select $select
- * @param array $options
- - *
- * @return void
- */
- private function saveDataFromSelect(\Magento\Framework\DB\Select $select, array $options)
- @@ -365,4 +356,48 @@ class Source extends AbstractEav
- {
- return $this->tableStrategy->getTableName('catalog_product_index_eav');
- }
- +
- + /**
- + * Prepare data index for product relations
- + *
- + * @param array $parentIds the parent entity ids limitation
- + * @return $this
- + */
- + protected function _prepareRelationIndex($parentIds = null)
- + {
- + $connection = $this->getConnection();
- + $idxTable = $this->getIdxTable();
- +
- + if (!$this->tableStrategy->getUseIdxTable()) {
- + $additionalIdxTable = $connection->getTableName(self::TRANSIT_PREFIX . $this->getIdxTable());
- + $connection->createTemporaryTableLike($additionalIdxTable, $idxTable);
- +
- + $query = $connection->insertFromSelect(
- + $this->_prepareRelationIndexSelect($parentIds),
- + $additionalIdxTable,
- + []
- + );
- + $connection->query($query);
- +
- + $select = $connection->select()->from($additionalIdxTable);
- + $query = $connection->insertFromSelect(
- + $select,
- + $idxTable,
- + [],
- + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
- + );
- + $connection->query($query);
- +
- + $connection->dropTemporaryTable($additionalIdxTable);
- + } else {
- + $query = $connection->insertFromSelect(
- + $this->_prepareRelationIndexSelect($parentIds),
- + $idxTable,
- + [],
- + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
- + );
- + $connection->query($query);
- + }
- + return $this;
- + }
- }
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/SourceRowSizeEstimator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/SourceRowSizeEstimator.php
- new file mode 100644
- index 00000000000..d212337ae7c
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Eav/SourceRowSizeEstimator.php
- @@ -0,0 +1,107 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav;
- +
- +use Magento\Store\Api\StoreManagementInterface;
- +use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
- +use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Catalog\Api\Data\ProductInterface;
- +use Magento\Framework\DB\Adapter\AdapterInterface;
- +
- +/**
- + * Estimator of the EAV index table row size.
- + *
- + * Estimates the amount of memory required to store the index data of the product
- + * with the highest number of attributes/values.
- + *
- + * Can be used with batch size manager to ensure that the batch will be handled correctly by the database.
- + * @see \Magento\Framework\Indexer\BatchSizeManagement
- + */
- +class SourceRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * @var StoreManagementInterface
- + */
- + private $storeManagement;
- +
- + /**
- + * @var Source
- + */
- + private $indexerResource;
- +
- + /**
- + * @var MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @param StoreManagementInterface $storeManagement
- + * @param Source $indexerResource
- + * @param MetadataPool $metadataPool
- + */
- + public function __construct(
- + StoreManagementInterface $storeManagement,
- + Source $indexerResource,
- + MetadataPool $metadataPool
- + ) {
- + $this->storeManagement = $storeManagement;
- + $this->indexerResource = $indexerResource;
- + $this->metadataPool = $metadataPool;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function estimateRowSize()
- + {
- + $connection = $this->indexerResource->getConnection();
- + $entityIdField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
- +
- + $maxRowsPerStore = max(
- + $this->getMaxRowsPerStore(
- + $connection,
- + $this->indexerResource->getTable('catalog_product_entity_int'),
- + $entityIdField
- + ),
- + $this->getMaxRowsPerStore(
- + $connection,
- + $this->indexerResource->getTable('catalog_product_entity_varchar'),
- + $entityIdField
- + )
- + );
- +
- + return ceil($maxRowsPerStore * $this->storeManagement->getCount() * 500);
- + }
- +
- + /**
- + * Calculate maximum rows per store and product stored in the target table.
- + *
- + * @param AdapterInterface $connection
- + * @param string $valueTable name of the target table
- + * @param string $entityIdField entity ID field name
- + * @return string maximum rows per store and product stored in the table
- + */
- + private function getMaxRowsPerStore(
- + AdapterInterface $connection,
- + $valueTable,
- + $entityIdField
- + ) {
- + $valueSelect = $connection->select();
- + $valueSelect->from(
- + ['value_table' => $valueTable],
- + ['count' => new \Zend_Db_Expr('count(value_table.value_id)')]
- + );
- + $valueSelect->group([$entityIdField, 'store_id']);
- +
- + $maxSelect = $connection->select();
- + $maxSelect->from(
- + ['max_value' => $valueSelect],
- + ['count' => new \Zend_Db_Expr('MAX(count)')]
- + );
- + return $connection->fetchOne($maxSelect);
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php
- index ffaf8a5d100..d81b38e9ac7 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/LinkedProductSelectBuilderByIndexPrice.php
- @@ -39,11 +39,12 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
- private $baseSelectProcessor;
- /**
- + * LinkedProductSelectBuilderByIndexPrice constructor.
- * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- * @param \Magento\Framework\App\ResourceConnection $resourceConnection
- * @param \Magento\Customer\Model\Session $customerSession
- * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
- - * @param BaseSelectProcessorInterface $baseSelectProcessor
- + * @param BaseSelectProcessorInterface|null $baseSelectProcessor
- */
- public function __construct(
- \Magento\Store\Model\StoreManagerInterface $storeManager,
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
- new file mode 100644
- index 00000000000..b31147af234
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/BatchSizeCalculator.php
- @@ -0,0 +1,59 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
- +
- +/**
- + * Ensure that size of index MEMORY table is enough for configured rows count in batch.
- + */
- +class BatchSizeCalculator
- +{
- + /**
- + * @var array
- + */
- + private $batchRowsCount;
- +
- + /**
- + * @var \Magento\Framework\Indexer\BatchSizeManagementInterface[]
- + */
- + private $estimators;
- +
- + /**
- + * BatchSizeCalculator constructor.
- + * @param array $batchRowsCount
- + * @param array $estimators
- + */
- + public function __construct(array $batchRowsCount, array $estimators)
- + {
- + $this->batchRowsCount = $batchRowsCount;
- + $this->estimators = $estimators;
- + }
- +
- + /**
- + * Retrieve batch size for the given indexer.
- + *
- + * Ensure that the database will be able to handle provided batch size correctly.
- + *
- + * @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
- + * @param string $indexerTypeId
- + * @return int
- + */
- + public function estimateBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $indexerTypeId)
- + {
- + $batchRowsCount = isset($this->batchRowsCount[$indexerTypeId])
- + ? $this->batchRowsCount[$indexerTypeId]
- + : $this->batchRowsCount['default'];
- +
- + /** @var \Magento\Framework\Indexer\BatchSizeManagementInterface $calculator */
- + $calculator = isset($this->estimators[$indexerTypeId])
- + ? $this->estimators[$indexerTypeId]
- + : $this->estimators['default'];
- +
- + $calculator->ensureBatchSize($connection, $batchRowsCount);
- +
- + return $batchRowsCount;
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php
- new file mode 100644
- index 00000000000..a3425bfc9d7
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimator.php
- @@ -0,0 +1,88 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
- +
- +use Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface;
- +use Magento\Store\Api\WebsiteManagementInterface;
- +use Magento\Customer\Model\ResourceModel\Group\CollectionFactory;
- +
- +/**
- + * Estimate index memory size for largest composite product in catalog.
- + */
- +class CompositeProductRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * Calculated memory size for one record in catalog_product_index_price table
- + */
- + const MEMORY_SIZE_FOR_ONE_ROW = 200;
- +
- + /**
- + * @var DefaultPrice
- + */
- + private $indexerResource;
- +
- + /**
- + * @var WebsiteManagementInterface
- + */
- + private $websiteManagement;
- +
- + /**
- + * @var CollectionFactory
- + */
- + private $collectionFactory;
- +
- + /**
- + * @param DefaultPrice $indexerResource
- + * @param WebsiteManagementInterface $websiteManagement
- + * @param CollectionFactory $collectionFactory
- + */
- + public function __construct(
- + DefaultPrice $indexerResource,
- + WebsiteManagementInterface $websiteManagement,
- + CollectionFactory $collectionFactory
- + ) {
- + $this->indexerResource = $indexerResource;
- + $this->websiteManagement = $websiteManagement;
- + $this->collectionFactory = $collectionFactory;
- + }
- +
- + /**
- + * Calculate memory size for largest composite product in database.
- + *
- + * {@inheritdoc}
- + */
- + public function estimateRowSize()
- + {
- + $websitesCount = $this->websiteManagement->getCount();
- + $customerGroupCount = $this->collectionFactory->create()->getSize();
- +
- + $connection = $this->indexerResource->getConnection();
- + $relationSelect = $connection->select();
- + $relationSelect->from(
- + ['relation' => $this->indexerResource->getTable('catalog_product_relation')],
- + ['count' => new \Zend_Db_Expr('count(relation.child_id)')]
- + );
- + $relationSelect->group('parent_id');
- +
- + $maxSelect = $connection->select();
- + $maxSelect->from(
- + ['max_value' => $relationSelect],
- + ['count' => new \Zend_Db_Expr('MAX(count)')]
- + );
- + $maxRelatedProductCount = $connection->fetchOne($maxSelect);
- +
- + /**
- + * Calculate memory size for largest composite product in database.
- + *
- + * $maxRelatedProductCount - maximum number of related products
- + * $websitesCount - active websites
- + * $customerGroupCount - active customer groups
- + * MEMORY_SIZE_FOR_ONE_ROW - calculated memory size for one record in catalog_product_index_price table
- + */
- + return ceil($maxRelatedProductCount * $websitesCount * $customerGroupCount * self::MEMORY_SIZE_FOR_ONE_ROW);
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php
- index 8a97d43a18d..5d1353ccd57 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/DefaultPrice.php
- @@ -12,6 +12,7 @@ use Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer;
- * For correctly work need define product type id
- *
- * @author Magento Core Team <core@magentocommerce.com>
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class DefaultPrice extends AbstractIndexer implements PriceInterface
- {
- @@ -44,14 +45,19 @@ class DefaultPrice extends AbstractIndexer implements PriceInterface
- protected $_eventManager = null;
- /**
- - * Class constructor
- + * @var bool|null
- + */
- + private $hasEntity = null;
- +
- + /**
- + * DefaultPrice 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\Event\ManagerInterface $eventManager
- * @param \Magento\Framework\Module\Manager $moduleManager
- - * @param string $connectionName
- + * @param string|null $connectionName
- */
- public function __construct(
- \Magento\Framework\Model\ResourceModel\Db\Context $context,
- @@ -677,16 +683,19 @@ class DefaultPrice extends AbstractIndexer implements PriceInterface
- */
- protected function hasEntity()
- {
- - $reader = $this->getConnection();
- -
- - $select = $reader->select()->from(
- - [$this->getTable('catalog_product_entity')],
- - ['count(entity_id)']
- - )->where(
- - 'type_id=?',
- - $this->getTypeId()
- - );
- + if ($this->hasEntity === null) {
- + $reader = $this->getConnection();
- +
- + $select = $reader->select()->from(
- + [$this->getTable('catalog_product_entity')],
- + ['count(entity_id)']
- + )->where(
- + 'type_id=?',
- + $this->getTypeId()
- + );
- + $this->hasEntity = (int)$reader->fetchOne($select) > 0;
- + }
- - return (int)$reader->fetchOne($select) > 0;
- + return $this->hasEntity;
- }
- }
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/IndexTableRowSizeEstimator.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/IndexTableRowSizeEstimator.php
- new file mode 100644
- index 00000000000..89df6677f24
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/Price/IndexTableRowSizeEstimator.php
- @@ -0,0 +1,63 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer\Price;
- +
- +/**
- + * Estimate index memory size for simple product.
- + * Size depends on websites and customer groups count.
- + */
- +class IndexTableRowSizeEstimator implements \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * Calculated memory size for one record in catalog_product_index_price table
- + */
- + const MEMORY_SIZE_FOR_ONE_ROW = 120;
- +
- + /**
- + * @var \Magento\Store\Api\WebsiteManagementInterface
- + */
- + private $websiteManagement;
- +
- + /**
- + * @var \Magento\Customer\Model\ResourceModel\Group\CollectionFactory
- + */
- + private $collectionFactory;
- +
- + /**
- + * CompositeProductBatchSizeCalculator constructor.
- + * @param \Magento\Store\Api\WebsiteManagementInterface $websiteManagement
- + * @param \Magento\Customer\Model\ResourceModel\Group\CollectionFactory $collectionFactory
- + */
- + public function __construct(
- + \Magento\Store\Api\WebsiteManagementInterface $websiteManagement,
- + \Magento\Customer\Model\ResourceModel\Group\CollectionFactory $collectionFactory
- + ) {
- + $this->websiteManagement = $websiteManagement;
- + $this->collectionFactory = $collectionFactory;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function estimateRowSize()
- + {
- + $websitesCount = $this->websiteManagement->getCount();
- +
- + /** @var \Magento\Customer\Model\ResourceModel\Group\Collection $collection */
- + $collection = $this->collectionFactory->create();
- + $customerGroupCount = $collection->getSize();
- +
- + /**
- + * Calculate memory size for product in database.
- + *
- + * $websitesCount - active websites
- + * $customerGroupCount - active customer groups
- + * MEMORY_SIZE_FOR_ONE_ROW - calculated memory size for one record in catalog_product_index_price table
- + */
- + return ceil($websitesCount * $customerGroupCount * self::MEMORY_SIZE_FOR_ONE_ROW);
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/TemporaryTableStrategy.php b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/TemporaryTableStrategy.php
- new file mode 100644
- index 00000000000..54673cb01bb
- --- /dev/null
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Product/Indexer/TemporaryTableStrategy.php
- @@ -0,0 +1,87 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
- +
- +/**
- + * Provided logic will create temporary table based on memory table and will return new index table name.
- + */
- +class TemporaryTableStrategy implements \Magento\Framework\Indexer\Table\StrategyInterface
- +{
- + /**
- + * Suffix for new temporary table
- + */
- + const TEMP_SUFFIX = '_temp';
- +
- + /**
- + * @var \Magento\Framework\Indexer\Table\Strategy
- + */
- + private $strategy;
- +
- + /**
- + * Application resource
- + *
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resource;
- +
- + /**
- + * TemporaryTableStrategy constructor.
- + * @param \Magento\Framework\Indexer\Table\Strategy $strategy
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + */
- + public function __construct(
- + \Magento\Framework\Indexer\Table\StrategyInterface $strategy,
- + \Magento\Framework\App\ResourceConnection $resource
- + ) {
- + $this->strategy = $strategy;
- + $this->resource = $resource;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function getUseIdxTable()
- + {
- + return $this->strategy->getUseIdxTable();
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function setUseIdxTable($value = false)
- + {
- + return $this->strategy->setUseIdxTable($value);
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function getTableName($tablePrefix)
- + {
- + return $this->resource->getTableName($this->prepareTableName($tablePrefix));
- + }
- +
- + /**
- + * Create temporary index table based on memory table
- + *
- + * {@inheritdoc}
- + */
- + public function prepareTableName($tablePrefix)
- + {
- + if ($this->getUseIdxTable()) {
- + return $tablePrefix . self::IDX_SUFFIX;
- + }
- +
- + // Create temporary table
- + $this->resource->getConnection('indexer')->createTemporaryTableLike(
- + $this->resource->getTableName($tablePrefix . self::TEMP_SUFFIX),
- + $this->resource->getTableName($tablePrefix . self::TMP_SUFFIX),
- + true
- + );
- + return $tablePrefix . self::TEMP_SUFFIX;
- + }
- +}
- diff --git a/vendor/magento/module-catalog/Model/ResourceModel/Url.php b/vendor/magento/module-catalog/Model/ResourceModel/Url.php
- index cb4c3143fc3..c4bab809c2f 100644
- --- a/vendor/magento/module-catalog/Model/ResourceModel/Url.php
- +++ b/vendor/magento/module-catalog/Model/ResourceModel/Url.php
- @@ -13,6 +13,7 @@ namespace Magento\Catalog\Model\ResourceModel;
- use Magento\CatalogUrlRewrite\Model\ProductUrlRewriteGenerator;
- use Magento\Catalog\Api\Data\CategoryInterface;
- use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Framework\App\ObjectManager;
- /**
- * Class Url
- diff --git a/vendor/magento/module-catalog/Setup/UpgradeSchema.php b/vendor/magento/module-catalog/Setup/UpgradeSchema.php
- index 213cbe8b0cf..b46c8cfd91e 100644
- --- a/vendor/magento/module-catalog/Setup/UpgradeSchema.php
- +++ b/vendor/magento/module-catalog/Setup/UpgradeSchema.php
- @@ -37,6 +37,56 @@ class UpgradeSchema implements UpgradeSchemaInterface
- $this->addSourceEntityIdToProductEavIndex($setup);
- }
- + if (version_compare($context->getVersion(), '2.1.4.1.2', '<')) {
- + //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'
- + );
- + // By adding 'catalog_product_index_price_replica' we provide separation of tables
- + // used for indexation write and read operations and affected models.
- + $this->addReplicaTable(
- + $setup,
- + 'catalog_product_index_price',
- + 'catalog_product_index_price_replica'
- + );
- + // the same for 'catalog_category_product_index'
- + $this->addReplicaTable(
- + $setup,
- + 'catalog_category_product_index',
- + 'catalog_category_product_index_replica'
- + );
- + }
- $setup->endSetup();
- }
- @@ -46,7 +96,6 @@ class UpgradeSchema implements UpgradeSchemaInterface
- * It is useful to identify original entity in a composite products.
- *
- * @param SchemaSetupInterface $setup
- - *
- * @return void
- */
- private function addSourceEntityIdToProductEavIndex(SchemaSetupInterface $setup)
- @@ -60,7 +109,6 @@ class UpgradeSchema implements UpgradeSchemaInterface
- 'catalog_product_index_eav_decimal_tmp',
- ];
- $connection = $setup->getConnection();
- -
- foreach ($tables as $tableName) {
- $tableName = $setup->getTable($tableName);
- $connection->addColumn(
- @@ -328,4 +376,22 @@ class UpgradeSchema implements UpgradeSchemaInterface
- $connection->dropColumn($setup->getTable($filedInfo['table']), $filedInfo['column']);
- }
- }
- +
- + /**
- + * Add the replica table for existing one.
- + *
- + * @param SchemaSetupInterface $setup
- + * @param string $existingTable
- + * @param string $replicaTable
- + * @return void
- + */
- + private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $replicaTable)
- + {
- + $sql = sprintf(
- + 'CREATE TABLE IF NOT EXISTS %s LIKE %s',
- + $setup->getConnection()->quoteIdentifier($setup->getTable($replicaTable)),
- + $setup->getConnection()->quoteIdentifier($setup->getTable($existingTable))
- + );
- + $setup->getConnection()->query($sql);
- + }
- }
- diff --git a/vendor/magento/module-catalog/etc/di.xml b/vendor/magento/module-catalog/etc/di.xml
- index 793c6351ffe..469e4d7cc17 100644
- --- a/vendor/magento/module-catalog/etc/di.xml
- +++ b/vendor/magento/module-catalog/etc/di.xml
- @@ -46,6 +46,7 @@
- <preference for="Magento\Catalog\Api\ProductManagementInterface" type="Magento\Catalog\Model\ProductManagement" />
- <preference for="Magento\Catalog\Api\AttributeSetFinderInterface" type="Magento\Catalog\Model\Product\Attribute\AttributeSetFinder" />
- <preference for="Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolverInterface" type="Magento\Catalog\Model\Product\Pricing\Renderer\SalableResolver"/>
- + <preference for="Magento\Framework\Indexer\BatchProviderInterface" type="Magento\Framework\Indexer\BatchProvider" />
- <type name="Magento\Customer\Model\ResourceModel\Visitor">
- <plugin name="catalogLog" type="Magento\Catalog\Model\Plugin\Log" />
- </type>
- @@ -806,4 +807,78 @@
- <plugin name="copy_quote_files_to_order" type="Magento\Catalog\Model\Plugin\QuoteItemProductOption"/>
- </type>
- <preference for="Magento\Catalog\Pricing\Price\MinimalPriceCalculatorInterface" type="Magento\Catalog\Pricing\Price\MinimalTierPriceCalculator" />
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
- + <arguments>
- + <argument name="batchRowsCount" xsi:type="array">
- + <item name="default" xsi:type="number">5000</item></argument>
- + <argument name="estimators" xsi:type="array">
- + <item name="default" xsi:type="object">Magento\Catalog\Model\Indexer\Price\BatchSizeManagement</item>
- + </argument>
- + </arguments>
- + </type>
- + <virtualType name="Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\CompositeProductRowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <virtualType name="Magento\Catalog\Model\Indexer\Price\BatchSizeManagement" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableRowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <type name="Magento\Catalog\Model\Indexer\Category\Product\Action\Full">
- + <arguments>
- + <argument name="batchRowsCount" xsi:type="number">100000</argument>
- + <argument name="batchSizeManagement" xsi:type="object">Magento\Catalog\Model\Indexer\CategoryProductBatchSize</argument>
- + </arguments>
- + </type>
- + <virtualType name="Magento\Catalog\Model\Indexer\CategoryProductBatchSize" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\Catalog\Model\Indexer\Category\Product\RowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy" shared="false">
- + <arguments>
- + <argument name="strategy" xsi:type="object">Magento\Framework\Indexer\Table\Strategy</argument>
- + </arguments>
- + </type>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- + <type name="Magento\Catalog\Model\Indexer\Product\Eav\Action\Full">
- + <arguments>
- + <argument name="batchSizeCalculator" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator</argument>
- + </arguments>
- + </type>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- + <virtualType name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalBatchSizeManagement" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalRowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <virtualType name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceBatchSizeManagement" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceRowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\BatchSizeCalculator">
- + <arguments>
- + <argument name="batchSizes" xsi:type="array">
- + <item name="decimal" xsi:type="number">1000</item>
- + <item name="source" xsi:type="number">1000</item>
- + </argument>
- + <argument name="batchSizeManagers" xsi:type="array">
- + <item name="decimal" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\DecimalBatchSizeManagement</item>
- + <item name="source" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\SourceBatchSizeManagement</item>
- + </argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-catalog/etc/module.xml b/vendor/magento/module-catalog/etc/module.xml
- index 57117669454..d3dd9716abe 100644
- --- a/vendor/magento/module-catalog/etc/module.xml
- +++ b/vendor/magento/module-catalog/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_Catalog" setup_version="2.1.4">
- + <module name="Magento_Catalog" setup_version="2.1.4.1.2">
- <sequence>
- <module name="Magento_Eav"/>
- <module name="Magento_Cms"/>
- diff --git a/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/AbstractAction.php b/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/AbstractAction.php
- index cd4a3b440ab..6bbcc9dde1a 100644
- --- a/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/AbstractAction.php
- +++ b/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/AbstractAction.php
- @@ -186,10 +186,10 @@ abstract class AbstractAction
- $this->_deleteOldRelations($tableName);
- - $columns = array_keys($this->_connection->describeTable($idxTableName));
- - $select = $this->_connection->select()->from($idxTableName, $columns);
- + $columns = array_keys($this->_getConnection()->describeTable($idxTableName));
- + $select = $this->_getConnection()->select()->from($idxTableName, $columns);
- $query = $select->insertFromSelect($tableName, $columns);
- - $this->_connection->query($query);
- + $this->_getConnection()->query($query);
- return $this;
- }
- @@ -202,7 +202,7 @@ abstract class AbstractAction
- */
- protected function _deleteOldRelations($tableName)
- {
- - $select = $this->_connection->select()
- + $select = $this->_getConnection()->select()
- ->from(['s' => $tableName])
- ->joinLeft(
- ['w' => $this->_getTable('catalog_product_website')],
- @@ -212,7 +212,7 @@ abstract class AbstractAction
- ->where('w.product_id IS NULL');
- $sql = $select->deleteFromSelect('s');
- - $this->_connection->query($sql);
- + $this->_getConnection()->query($sql);
- }
- /**
- diff --git a/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/Action/Full.php b/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/Action/Full.php
- index 2f545417a07..baa770c25bc 100644
- --- a/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/Action/Full.php
- +++ b/vendor/magento/module-catalog-inventory/Model/Indexer/Stock/Action/Full.php
- @@ -8,18 +8,106 @@
- 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;
- +use Magento\Framework\Indexer\CacheContext;
- +use Magento\Framework\Event\ManagerInterface as EventManager;
- +use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Framework\Indexer\BatchSizeManagementInterface;
- +use Magento\Framework\Indexer\BatchProviderInterface;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\Framework\Exception\LocalizedException;
- +use Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction;
- +
- /**
- * Class Full reindex action
- *
- * @package Magento\CatalogInventory\Model\Indexer\Stock\Action
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- -class Full extends \Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction
- +class Full extends AbstractAction
- {
- + /**
- + * Action type representation
- + */
- + const ACTION_TYPE = 'full';
- +
- + /**
- + * @var MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @var BatchSizeManagementInterface
- + */
- + private $batchSizeManagement;
- +
- + /**
- + * @var BatchProviderInterface
- + */
- + private $batchProvider;
- +
- + /**
- + * @var array
- + */
- + private $batchRowsCount;
- +
- + /**
- + * @var ActiveTableSwitcher
- + */
- + private $activeTableSwitcher;
- +
- + /**
- + * @param ResourceConnection $resource
- + * @param StockFactory $indexerFactory
- + * @param ProductType $catalogProductType
- + * @param CacheContext $cacheContext
- + * @param EventManager $eventManager
- + * @param MetadataPool|null $metadataPool
- + * @param BatchSizeManagementInterface|null $batchSizeManagement
- + * @param BatchProviderInterface|null $batchProvider
- + * @param array $batchRowsCount
- + * @param ActiveTableSwitcher|null $activeTableSwitcher
- + *
- + * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- + */
- + public function __construct(
- + ResourceConnection $resource,
- + StockFactory $indexerFactory,
- + ProductType $catalogProductType,
- + CacheContext $cacheContext,
- + EventManager $eventManager,
- + MetadataPool $metadataPool = null,
- + BatchSizeManagementInterface $batchSizeManagement = null,
- + BatchProviderInterface $batchProvider = null,
- + array $batchRowsCount = [],
- + ActiveTableSwitcher $activeTableSwitcher = null
- + ) {
- + parent::__construct(
- + $resource,
- + $indexerFactory,
- + $catalogProductType,
- + $cacheContext,
- + $eventManager
- + );
- +
- + $this->metadataPool = $metadataPool ?: ObjectManager::getInstance()->get(MetadataPool::class);
- + $this->batchProvider = $batchProvider ?: ObjectManager::getInstance()->get(BatchProviderInterface::class);
- + $this->batchSizeManagement = $batchSizeManagement ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement::class
- + );
- + $this->batchRowsCount = $batchRowsCount;
- + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()
- + ->get(ActiveTableSwitcher::class);
- + }
- +
- /**
- * Execute Full reindex
- *
- * @param null|array $ids
- - * @throws \Magento\Framework\Exception\LocalizedException
- + * @throws LocalizedException
- *
- * @return void
- *
- @@ -28,9 +116,49 @@ class Full extends \Magento\CatalogInventory\Model\Indexer\Stock\AbstractAction
- public function execute($ids = null)
- {
- try {
- - $this->reindexAll();
- + $this->useIdxTable(false);
- + $entityMetadata = $this->metadataPool->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
- +
- + $columns = array_keys($this->_getConnection()->describeTable($this->_getIdxTable()));
- +
- + /** @var \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock $indexer */
- + foreach ($this->_getTypeIndexers() as $indexer) {
- + $indexer->setActionType(self::ACTION_TYPE);
- + $connection = $indexer->getConnection();
- + $tableName = $this->activeTableSwitcher->getAdditionalTableName($indexer->getMainTable());
- +
- + $batchRowCount = isset($this->batchRowsCount[$indexer->getTypeId()])
- + ? $this->batchRowsCount[$indexer->getTypeId()]
- + : $this->batchRowsCount['default'];
- +
- + $this->batchSizeManagement->ensureBatchSize($connection, $batchRowCount);
- + $batches = $this->batchProvider->getBatches(
- + $connection,
- + $entityMetadata->getEntityTable(),
- + $entityMetadata->getIdentifierField(),
- + $batchRowCount
- + );
- +
- + foreach ($batches as $batch) {
- + $this->clearTemporaryIndexTable();
- + // Get entity ids from batch
- + $select = $connection->select();
- + $select->distinct(true);
- + $select->from(['e' => $entityMetadata->getEntityTable()], $entityMetadata->getIdentifierField());
- + $select->where('type_id = ?', $indexer->getTypeId());
- +
- + $entityIds = $this->batchProvider->getBatchIds($connection, $select, $batch);
- + if (!empty($entityIds)) {
- + $indexer->reindexEntity($entityIds);
- + $select = $connection->select()->from($this->_getIdxTable(), $columns);
- + $query = $select->insertFromSelect($tableName, $columns);
- + $connection->query($query);
- + }
- + }
- + }
- + $this->activeTableSwitcher->switchTable($indexer->getConnection(), [$indexer->getMainTable()]);
- } catch (\Exception $e) {
- - throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
- + throw new LocalizedException(__($e->getMessage()), $e);
- }
- }
- }
- diff --git a/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php b/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php
- index fcac88be425..ba9960a6b9c 100644
- --- a/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php
- +++ b/vendor/magento/module-catalog-inventory/Model/ResourceModel/Indexer/Stock/DefaultStock.php
- @@ -10,6 +10,7 @@ use Magento\Catalog\Model\ResourceModel\Product\Indexer\AbstractIndexer;
- use Magento\CatalogInventory\Model\Stock;
- use Magento\Framework\DB\Adapter\AdapterInterface;
- use Magento\CatalogInventory\Api\StockConfigurationInterface;
- +use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
- /**
- * CatalogInventory Default Stock Status Indexer Resource Model
- @@ -48,6 +49,13 @@ class DefaultStock extends AbstractIndexer implements StockInterface
- */
- protected $stockConfiguration;
- + /**
- + * Param for switching logic which depends on action type (full reindex or partial)
- + *
- + * @var string
- + */
- + private $actionType;
- +
- /**
- * Class constructor
- *
- @@ -106,10 +114,38 @@ class DefaultStock extends AbstractIndexer implements StockInterface
- */
- public function reindexEntity($entityIds)
- {
- + if ($this->getActionType() === Full::ACTION_TYPE) {
- + $this->tableStrategy->setUseIdxTable(false);
- + $this->_prepareIndexTable($entityIds);
- + return $this;
- + }
- +
- $this->_updateIndex($entityIds);
- return $this;
- }
- + /**
- + * Returns action run type
- + *
- + * @return string
- + */
- + public function getActionType()
- + {
- + return $this->actionType;
- + }
- +
- + /**
- + * Set action run type
- + *
- + * @param string $type
- + * @return $this
- + */
- + public function setActionType($type)
- + {
- + $this->actionType = $type;
- + return $this;
- + }
- +
- /**
- * Set active Product Type Id
- *
- @@ -221,7 +257,7 @@ class DefaultStock extends AbstractIndexer implements StockInterface
- protected function _prepareIndexTable($entityIds = null)
- {
- $connection = $this->getConnection();
- - $select = $this->_getStockStatusSelect($entityIds);
- + $select = $this->_getStockStatusSelect($entityIds, true);
- $select = $this->getQueryProcessorComposite()->processQuery($select, $entityIds);
- $query = $select->insertFromSelect($this->getIdxTable());
- $connection->query($query);
- diff --git a/vendor/magento/module-catalog-inventory/Setup/UpgradeSchema.php b/vendor/magento/module-catalog-inventory/Setup/UpgradeSchema.php
- new file mode 100644
- index 00000000000..f1975841f1d
- --- /dev/null
- +++ b/vendor/magento/module-catalog-inventory/Setup/UpgradeSchema.php
- @@ -0,0 +1,46 @@
- +<?php
- +/**
- + * Copyright © 2013-2017 Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogInventory\Setup;
- +
- +use Magento\Framework\Setup\UpgradeSchemaInterface;
- +use Magento\Framework\Setup\ModuleContextInterface;
- +use Magento\Framework\Setup\SchemaSetupInterface;
- +
- +class UpgradeSchema implements UpgradeSchemaInterface
- +{
- + /**
- + * {@inheritdoc}
- + */
- + public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
- + {
- + $setup->startSetup();
- +
- + if (version_compare($context->getVersion(), '2.0.1.1.2', '<')) {
- + $this->addReplicaTable($setup, 'cataloginventory_stock_status', 'cataloginventory_stock_status_replica');
- + }
- +
- + $setup->endSetup();
- + }
- +
- + /**
- + * Add replica table for existing one.
- + *
- + * @param SchemaSetupInterface $setup
- + * @param string $existingTable
- + * @param string $replicaTable
- + * @return void
- + */
- + private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $replicaTable)
- + {
- + $sql = sprintf(
- + 'CREATE TABLE IF NOT EXISTS %s LIKE %s',
- + $setup->getConnection()->quoteIdentifier($setup->getTable($replicaTable)),
- + $setup->getConnection()->quoteIdentifier($setup->getTable($existingTable))
- + );
- + $setup->getConnection()->query($sql);
- + }
- +}
- diff --git a/vendor/magento/module-catalog-inventory/etc/di.xml b/vendor/magento/module-catalog-inventory/etc/di.xml
- index 9e970cef7d0..10a72edb0db 100644
- --- a/vendor/magento/module-catalog-inventory/etc/di.xml
- +++ b/vendor/magento/module-catalog-inventory/etc/di.xml
- @@ -86,4 +86,22 @@
- <argument name="indexerProcessor" xsi:type="object">Magento\CatalogInventory\Model\Indexer\Stock\Processor</argument>
- </arguments>
- </type>
- + <virtualType name="Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement" type="Magento\Framework\Indexer\BatchSizeManagement">
- + <arguments>
- + <argument name="rowSizeEstimator" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\IndexTableRowSizeEstimator</argument>
- + </arguments>
- + </virtualType>
- + <virtualType name="Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\IndexTableRowSizeEstimator" type="Magento\Framework\Indexer\IndexTableRowSizeEstimator">
- + <arguments>
- + <argument name="rowMemorySize" xsi:type="number">100</argument>
- + </arguments>
- + </virtualType>
- + <type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
- + <arguments>
- + <argument name="batchRowsCount" xsi:type="array">
- + <item name="default" xsi:type="number">200</item>
- + </argument>
- + <argument name="batchSizeManagement" xsi:type="object">Magento\CatalogInventory\Model\Indexer\Stock\BatchSizeManagement</argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-catalog-inventory/etc/module.xml b/vendor/magento/module-catalog-inventory/etc/module.xml
- index 6d86fa55984..676d3e8ef82 100644
- --- a/vendor/magento/module-catalog-inventory/etc/module.xml
- +++ b/vendor/magento/module-catalog-inventory/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_CatalogInventory" setup_version="2.0.1">
- + <module name="Magento_CatalogInventory" setup_version="2.0.1.1.2">
- <sequence>
- <module name="Magento_Catalog"/>
- </sequence>
- diff --git a/vendor/magento/module-catalog-rule/Api/IndexerTableSwapperInterface.php b/vendor/magento/module-catalog-rule/Api/IndexerTableSwapperInterface.php
- new file mode 100644
- index 00000000000..664505c48ba
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Api/IndexerTableSwapperInterface.php
- @@ -0,0 +1,32 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Api;
- +
- +/**
- + * Manage additional tables used while building new index to preserve
- + * index tables until the process finishes.
- + */
- +interface IndexerTableSwapperInterface
- +{
- + /**
- + * Get working table name used to build index.
- + *
- + * @param string $originalTable
- + *
- + * @return string
- + */
- + public function getWorkingTableName(string $originalTable): string;
- +
- + /**
- + * Swap working tables with actual tables to save new indexes.
- + *
- + * @param string[] $originalTablesNames
- + *
- + * @return void
- + */
- + public function swapIndexTables(array $originalTablesNames);
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/IndexBuilder.php b/vendor/magento/module-catalog-rule/Model/Indexer/IndexBuilder.php
- index 423aaa6986e..af17aa7efbc 100644
- --- a/vendor/magento/module-catalog-rule/Model/Indexer/IndexBuilder.php
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/IndexBuilder.php
- @@ -6,16 +6,17 @@
- namespace Magento\CatalogRule\Model\Indexer;
- -use Magento\Catalog\Api\Data\ProductInterface;
- use Magento\Catalog\Model\Product;
- use Magento\CatalogRule\Model\ResourceModel\Rule\CollectionFactory as RuleCollectionFactory;
- use Magento\CatalogRule\Model\Rule;
- -use Magento\Framework\App\ResourceConnection;
- -use Magento\Framework\EntityManager\MetadataPool;
- +use Magento\Framework\App\ObjectManager;
- use Magento\Framework\Pricing\PriceCurrencyInterface;
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface as TableSwapper;
- /**
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- + * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
- + * @SuppressWarnings(PHPMD.TooManyFields)
- */
- class IndexBuilder
- {
- @@ -23,6 +24,7 @@ class IndexBuilder
- /**
- * @var \Magento\Framework\EntityManager\MetadataPool
- + * @deprecated
- */
- protected $metadataPool;
- @@ -32,6 +34,7 @@ class IndexBuilder
- * This array contain list of CatalogRuleGroupWebsite table columns
- *
- * @var array
- + * @deprecated
- */
- protected $_catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
- @@ -95,6 +98,46 @@ class IndexBuilder
- */
- protected $connection;
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator
- + */
- + private $productPriceCalculator;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct
- + */
- + private $reindexRuleProduct;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite
- + */
- + private $reindexRuleGroupWebsite;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder
- + */
- + private $ruleProductsSelectBuilder;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice
- + */
- + private $reindexRuleProductPrice;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor
- + */
- + private $pricesPersistor;
- +
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
- + */
- + private $activeTableSwitcher;
- +
- + /**
- + * @var TableSwapper
- + */
- + private $tableSwapper;
- +
- /**
- * @param RuleCollectionFactory $ruleCollectionFactory
- * @param PriceCurrencyInterface $priceCurrency
- @@ -106,7 +149,16 @@ class IndexBuilder
- * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
- * @param \Magento\Catalog\Model\ProductFactory $productFactory
- * @param int $batchCount
- + * @param \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator|null $productPriceCalculator
- + * @param \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct|null $reindexRuleProduct
- + * @param \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite|null $reindexRuleGroupWebsite
- + * @param \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder|null $ruleProductsSelectBuilder
- + * @param \Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice|null $reindexRuleProductPrice
- + * @param \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor|null $pricesPersistor
- + * @param \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher|null $activeTableSwitcher
- + * @param TableSwapper|null $tableSwapper
- * @SuppressWarnings(PHPMD.ExcessiveParameterList)
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function __construct(
- RuleCollectionFactory $ruleCollectionFactory,
- @@ -118,7 +170,15 @@ class IndexBuilder
- \Magento\Framework\Stdlib\DateTime $dateFormat,
- \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
- \Magento\Catalog\Model\ProductFactory $productFactory,
- - $batchCount = 1000
- + $batchCount = 1000,
- + \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator $productPriceCalculator = null,
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct $reindexRuleProduct = null,
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite $reindexRuleGroupWebsite = null,
- + \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder $ruleProductsSelectBuilder = null,
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice $reindexRuleProductPrice = null,
- + \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor $pricesPersistor = null,
- + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null,
- + TableSwapper $tableSwapper = null
- ) {
- $this->resource = $resource;
- $this->connection = $resource->getConnection();
- @@ -131,6 +191,30 @@ class IndexBuilder
- $this->dateTime = $dateTime;
- $this->productFactory = $productFactory;
- $this->batchCount = $batchCount;
- +
- + $this->productPriceCalculator = $productPriceCalculator ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator::class
- + );
- + $this->reindexRuleProduct = $reindexRuleProduct ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct::class
- + );
- + $this->reindexRuleGroupWebsite = $reindexRuleGroupWebsite ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite::class
- + );
- + $this->ruleProductsSelectBuilder = $ruleProductsSelectBuilder ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder::class
- + );
- + $this->reindexRuleProductPrice = $reindexRuleProductPrice ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice::class
- + );
- + $this->pricesPersistor = $pricesPersistor ?: ObjectManager::getInstance()->get(
- + \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor::class
- + );
- + $this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get(
- + \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class
- + );
- +
- + $this->tableSwapper = $tableSwapper ?: ObjectManager::getInstance()->get(TableSwapper::class);
- }
- /**
- @@ -207,9 +291,19 @@ class IndexBuilder
- protected function doReindexFull()
- {
- foreach ($this->getAllRules() as $rule) {
- - $this->updateRuleProductData($rule);
- + $this->reindexRuleProduct->execute($rule, $this->batchCount, true);
- }
- - $this->deleteOldData()->applyAllRules();
- +
- + $this->reindexRuleProductPrice->execute($this->batchCount, null, true);
- + $this->reindexRuleGroupWebsite->execute(true);
- +
- + $this->tableSwapper->swapIndexTables(
- + [
- + $this->getTable('catalogrule_product'),
- + $this->getTable('catalogrule_product_price'),
- + $this->getTable('catalogrule_group_website')
- + ]
- + );
- }
- /**
- @@ -305,7 +399,8 @@ class IndexBuilder
- throw $e;
- }
- - $this->applyAllRules($product);
- + $this->reindexRuleProductPrice->execute($this->batchCount, $product);
- + $this->reindexRuleGroupWebsite->execute();
- return $this;
- }
- @@ -322,8 +417,8 @@ class IndexBuilder
- /**
- * @param Rule $rule
- * @return $this
- - * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- - * @SuppressWarnings(PHPMD.NPathComplexity)
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\ReindexRuleProduct::execute
- */
- protected function updateRuleProductData(Rule $rule)
- {
- @@ -340,63 +435,7 @@ class IndexBuilder
- );
- }
- - if (!$rule->getIsActive()) {
- - return $this;
- - }
- -
- - $websiteIds = $rule->getWebsiteIds();
- - if (!is_array($websiteIds)) {
- - $websiteIds = explode(',', $websiteIds);
- - }
- - if (empty($websiteIds)) {
- - return $this;
- - }
- -
- - \Magento\Framework\Profiler::start('__MATCH_PRODUCTS__');
- - $productIds = $rule->getMatchingProductIds();
- - \Magento\Framework\Profiler::stop('__MATCH_PRODUCTS__');
- -
- - $customerGroupIds = $rule->getCustomerGroupIds();
- - $fromTime = strtotime($rule->getFromDate());
- - $toTime = strtotime($rule->getToDate());
- - $toTime = $toTime ? $toTime + self::SECONDS_IN_DAY - 1 : 0;
- - $sortOrder = (int)$rule->getSortOrder();
- - $actionOperator = $rule->getSimpleAction();
- - $actionAmount = $rule->getDiscountAmount();
- - $actionStop = $rule->getStopRulesProcessing();
- -
- - $rows = [];
- -
- - foreach ($productIds as $productId => $validationByWebsite) {
- - foreach ($websiteIds as $websiteId) {
- - if (empty($validationByWebsite[$websiteId])) {
- - continue;
- - }
- - foreach ($customerGroupIds as $customerGroupId) {
- - $rows[] = [
- - 'rule_id' => $ruleId,
- - 'from_time' => $fromTime,
- - 'to_time' => $toTime,
- - 'website_id' => $websiteId,
- - 'customer_group_id' => $customerGroupId,
- - 'product_id' => $productId,
- - 'action_operator' => $actionOperator,
- - 'action_amount' => $actionAmount,
- - 'action_stop' => $actionStop,
- - 'sort_order' => $sortOrder,
- - ];
- -
- - if (count($rows) == $this->batchCount) {
- - $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
- - $rows = [];
- - }
- - }
- - }
- - }
- - if (!empty($rows)) {
- - $this->connection->insertMultiple($this->getTable('catalogrule_product'), $rows);
- - }
- -
- + $this->reindexRuleProduct->execute($rule, $this->batchCount);
- return $this;
- }
- @@ -404,123 +443,27 @@ class IndexBuilder
- * @param Product|null $product
- * @throws \Exception
- * @return $this
- - * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- - * @SuppressWarnings(PHPMD.NPathComplexity)
- - * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\ReindexRuleProductPrice::execute
- + * @see \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite::execute
- */
- protected function applyAllRules(Product $product = null)
- {
- - $fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
- - $toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
- -
- - /**
- - * Update products rules prices per each website separately
- - * because of max join limit in mysql
- - */
- - foreach ($this->storeManager->getWebsites() as $website) {
- - $productsStmt = $this->getRuleProductsStmt($website->getId(), $product);
- -
- - $dayPrices = [];
- - $stopFlags = [];
- - $prevKey = null;
- -
- - while ($ruleData = $productsStmt->fetch()) {
- - $ruleProductId = $ruleData['product_id'];
- - $productKey = $ruleProductId .
- - '_' .
- - $ruleData['website_id'] .
- - '_' .
- - $ruleData['customer_group_id'];
- -
- - if ($prevKey && $prevKey != $productKey) {
- - $stopFlags = [];
- - if (count($dayPrices) > $this->batchCount) {
- - $this->saveRuleProductPrices($dayPrices);
- - $dayPrices = [];
- - }
- - }
- -
- - $ruleData['from_time'] = $this->roundTime($ruleData['from_time']);
- - $ruleData['to_time'] = $this->roundTime($ruleData['to_time']);
- - /**
- - * Build prices for each day
- - */
- - for ($time = $fromDate; $time <= $toDate; $time += self::SECONDS_IN_DAY) {
- - if (($ruleData['from_time'] == 0 ||
- - $time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 ||
- - $time <= $ruleData['to_time'])
- - ) {
- - $priceKey = $time . '_' . $productKey;
- -
- - if (isset($stopFlags[$priceKey])) {
- - continue;
- - }
- -
- - if (!isset($dayPrices[$priceKey])) {
- - $dayPrices[$priceKey] = [
- - 'rule_date' => $time,
- - 'website_id' => $ruleData['website_id'],
- - 'customer_group_id' => $ruleData['customer_group_id'],
- - 'product_id' => $ruleProductId,
- - 'rule_price' => $this->calcRuleProductPrice($ruleData),
- - 'latest_start_date' => $ruleData['from_time'],
- - 'earliest_end_date' => $ruleData['to_time'],
- - ];
- - } else {
- - $dayPrices[$priceKey]['rule_price'] = $this->calcRuleProductPrice(
- - $ruleData,
- - $dayPrices[$priceKey]
- - );
- - $dayPrices[$priceKey]['latest_start_date'] = max(
- - $dayPrices[$priceKey]['latest_start_date'],
- - $ruleData['from_time']
- - );
- - $dayPrices[$priceKey]['earliest_end_date'] = min(
- - $dayPrices[$priceKey]['earliest_end_date'],
- - $ruleData['to_time']
- - );
- - }
- -
- - if ($ruleData['action_stop']) {
- - $stopFlags[$priceKey] = true;
- - }
- - }
- - }
- -
- - $prevKey = $productKey;
- - }
- - $this->saveRuleProductPrices($dayPrices);
- - }
- -
- - return $this->updateCatalogRuleGroupWebsiteData();
- + $this->reindexRuleProductPrice->execute($this->batchCount, $product);
- + $this->reindexRuleGroupWebsite->execute();
- + return $this;
- }
- /**
- * Update CatalogRuleGroupWebsite data
- *
- * @return $this
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\ReindexRuleGroupWebsite::execute
- */
- protected function updateCatalogRuleGroupWebsiteData()
- {
- - $this->connection->delete($this->getTable('catalogrule_group_website'), []);
- -
- - $timestamp = $this->dateTime->gmtTimestamp();
- -
- - $select = $this->connection->select()->distinct(
- - true
- - )->from(
- - $this->getTable('catalogrule_product'),
- - $this->_catalogRuleGroupWebsiteColumnsList
- - )->where(
- - "{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)"
- - );
- - $query = $select->insertFromSelect(
- - $this->getTable('catalogrule_group_website'),
- - $this->_catalogRuleGroupWebsiteColumnsList
- - );
- -
- - $this->connection->query($query);
- -
- + $this->reindexRuleGroupWebsite->execute();
- return $this;
- }
- @@ -539,33 +482,12 @@ class IndexBuilder
- * @param array $ruleData
- * @param null $productData
- * @return float
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator::calculate
- */
- protected function calcRuleProductPrice($ruleData, $productData = null)
- {
- - if ($productData !== null && isset($productData['rule_price'])) {
- - $productPrice = $productData['rule_price'];
- - } else {
- - $productPrice = $ruleData['default_price'];
- - }
- -
- - switch ($ruleData['action_operator']) {
- - case 'to_fixed':
- - $productPrice = min($ruleData['action_amount'], $productPrice);
- - break;
- - case 'to_percent':
- - $productPrice = $productPrice * $ruleData['action_amount'] / 100;
- - break;
- - case 'by_fixed':
- - $productPrice = max(0, $productPrice - $ruleData['action_amount']);
- - break;
- - case 'by_percent':
- - $productPrice = $productPrice * (1 - $ruleData['action_amount'] / 100);
- - break;
- - default:
- - $productPrice = 0;
- - }
- -
- - return $this->priceCurrency->round($productPrice);
- + return $this->productPriceCalculator->calculate($ruleData, $productData);
- }
- /**
- @@ -573,107 +495,24 @@ class IndexBuilder
- * @param Product|null $product
- * @return \Zend_Db_Statement_Interface
- * @throws \Magento\Framework\Exception\LocalizedException
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder::build
- */
- protected function getRuleProductsStmt($websiteId, Product $product = null)
- {
- - /**
- - * Sort order is important
- - * It used for check stop price rule condition.
- - * website_id customer_group_id product_id sort_order
- - * 1 1 1 0
- - * 1 1 1 1
- - * 1 1 1 2
- - * if row with sort order 1 will have stop flag we should exclude
- - * all next rows for same product id from price calculation
- - */
- - $select = $this->connection->select()->from(
- - ['rp' => $this->getTable('catalogrule_product')]
- - )->order(
- - ['rp.website_id', 'rp.customer_group_id', 'rp.product_id', 'rp.sort_order', 'rp.rule_id']
- - );
- -
- - if ($product && $product->getEntityId()) {
- - $select->where('rp.product_id=?', $product->getEntityId());
- - }
- -
- - /**
- - * Join default price and websites prices to result
- - */
- - $priceAttr = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
- - $priceTable = $priceAttr->getBackend()->getTable();
- - $attributeId = $priceAttr->getId();
- -
- - $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
- - $select->join(
- - ['e' => $this->getTable('catalog_product_entity')],
- - sprintf('e.entity_id = rp.product_id'),
- - []
- - );
- - $joinCondition = '%1$s.' . $linkField . '=e.' . $linkField . ' AND (%1$s.attribute_id='
- - . $attributeId
- - . ') and %1$s.store_id=%2$s';
- -
- - $select->join(
- - ['pp_default' => $priceTable],
- - sprintf($joinCondition, 'pp_default', \Magento\Store\Model\Store::DEFAULT_STORE_ID),
- - []
- - );
- -
- - $website = $this->storeManager->getWebsite($websiteId);
- - $defaultGroup = $website->getDefaultGroup();
- - if ($defaultGroup instanceof \Magento\Store\Model\Group) {
- - $storeId = $defaultGroup->getDefaultStoreId();
- - } else {
- - $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
- - }
- -
- - $select->joinInner(
- - ['product_website' => $this->getTable('catalog_product_website')],
- - 'product_website.product_id=rp.product_id '
- - . 'AND product_website.website_id = rp.website_id '
- - . 'AND product_website.website_id='
- - . $websiteId,
- - []
- - );
- -
- - $tableAlias = 'pp' . $websiteId;
- - $select->joinLeft(
- - [$tableAlias => $priceTable],
- - sprintf($joinCondition, $tableAlias, $storeId),
- - []
- - );
- - $select->columns([
- - 'default_price' =>$this->connection->getIfNullSql($tableAlias . '.value', 'pp_default.value'),
- - ]);
- -
- - return $this->connection->query($select);
- + return $this->ruleProductsSelectBuilder->build($websiteId, $product);
- }
- /**
- * @param array $arrData
- * @return $this
- * @throws \Exception
- + * @deprecated
- + * @see \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor::execute
- */
- protected function saveRuleProductPrices($arrData)
- {
- - if (empty($arrData)) {
- - return $this;
- - }
- -
- - $productIds = [];
- -
- - try {
- - foreach ($arrData as $key => $data) {
- - $productIds['product_id'] = $data['product_id'];
- - $arrData[$key]['rule_date'] = $this->dateFormat->formatDate($data['rule_date'], false);
- - $arrData[$key]['latest_start_date'] = $this->dateFormat->formatDate($data['latest_start_date'], false);
- - $arrData[$key]['earliest_end_date'] = $this->dateFormat->formatDate($data['earliest_end_date'], false);
- - }
- - $this->connection->insertOnDuplicate($this->getTable('catalogrule_product_price'), $arrData);
- - } catch (\Exception $e) {
- - throw $e;
- - }
- -
- + $this->pricesPersistor->execute($arrData);
- return $this;
- }
- @@ -684,8 +523,7 @@ class IndexBuilder
- */
- protected function getActiveRules()
- {
- - return $this->ruleCollectionFactory->create()
- - ->addFieldToFilter('is_active', 1);
- + return $this->ruleCollectionFactory->create()->addFieldToFilter('is_active', 1);
- }
- /**
- @@ -722,6 +560,7 @@ class IndexBuilder
- /**
- * @param int $timeStamp
- * @return int
- + * @deprecated
- */
- private function roundTime($timeStamp)
- {
- @@ -734,6 +573,7 @@ class IndexBuilder
- /**
- * @return MetadataPool
- + * @deprecated
- */
- private function getMetadataPool()
- {
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/IndexerTableSwapper.php b/vendor/magento/module-catalog-rule/Model/Indexer/IndexerTableSwapper.php
- new file mode 100644
- index 00000000000..e2e53f724a7
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/IndexerTableSwapper.php
- @@ -0,0 +1,127 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface;
- +use Magento\Framework\App\ResourceConnection;
- +
- +/**
- + * @inheritDoc
- + */
- +class IndexerTableSwapper implements IndexerTableSwapperInterface
- +{
- + /**
- + * Keys are original tables' names, values - created temporary tables.
- + *
- + * @var string[]
- + */
- + private $temporaryTables = [];
- +
- + /**
- + * @var ResourceConnection
- + */
- + private $resourceConnection;
- +
- + /**
- + * @param ResourceConnection $resource
- + */
- + public function __construct(ResourceConnection $resource)
- + {
- + $this->resourceConnection = $resource;
- + }
- +
- + /**
- + * Create temporary table based on given table to use instead of original.
- + *
- + * @param string $originalTableName
- + *
- + * @return string Created table name.
- + * @throws \Throwable
- + */
- + private function createTemporaryTable(string $originalTableName): string
- + {
- + $temporaryTableName = $this->resourceConnection->getTableName(
- + $originalTableName . '__temp' . $this->generateRandomSuffix()
- + );
- +
- + $this->resourceConnection->getConnection()->query(
- + sprintf(
- + 'create table %s like %s',
- + $temporaryTableName,
- + $this->resourceConnection->getTableName($originalTableName)
- + )
- + );
- +
- + return $temporaryTableName;
- + }
- +
- + /**
- + * Random suffix for temporary tables not to conflict with each other.
- + *
- + * @return string
- + */
- + private function generateRandomSuffix(): string
- + {
- + return bin2hex(random_bytes(4));
- + }
- +
- + /**
- + * @inheritDoc
- + */
- + public function getWorkingTableName(string $originalTable): string
- + {
- + $originalTable = $this->resourceConnection->getTableName($originalTable);
- + if (!array_key_exists($originalTable, $this->temporaryTables)) {
- + $this->temporaryTables[$originalTable]
- + = $this->createTemporaryTable($originalTable);
- + }
- +
- + return $this->temporaryTables[$originalTable];
- + }
- +
- + /**
- + * @inheritDoc
- + */
- + public function swapIndexTables(array $originalTablesNames)
- + {
- + $toRename = [];
- + /** @var string[] $toDrop */
- + $toDrop = [];
- + /** @var string[] $temporaryTablesRenamed */
- + $temporaryTablesRenamed = [];
- + //Renaming temporary tables to original tables' names, dropping old
- + //tables.
- + foreach ($originalTablesNames as $tableName) {
- + $tableName = $this->resourceConnection->getTableName($tableName);
- + $temporaryOriginalName = $this->resourceConnection->getTableName(
- + $tableName . $this->generateRandomSuffix()
- + );
- + $temporaryTableName = $this->getWorkingTableName($tableName);
- + $toRename[] = [
- + 'oldName' => $tableName,
- + 'newName' => $temporaryOriginalName
- + ];
- + $toRename[] = [
- + 'oldName' => $temporaryTableName,
- + 'newName' => $tableName
- + ];
- + $toDrop[] = $temporaryOriginalName;
- + $temporaryTablesRenamed[] = $tableName;
- + }
- +
- + //Swapping tables.
- + $this->resourceConnection->getConnection()->renameTablesBatch($toRename);
- + //Cleaning up.
- + foreach ($temporaryTablesRenamed as $tableName) {
- + unset($this->temporaryTables[$tableName]);
- + }
- + //Removing old ones.
- + foreach ($toDrop as $tableName) {
- + $this->resourceConnection->getConnection()->dropTable($tableName);
- + }
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/ProductPriceCalculator.php b/vendor/magento/module-catalog-rule/Model/Indexer/ProductPriceCalculator.php
- new file mode 100644
- index 00000000000..02b499c75b7
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/ProductPriceCalculator.php
- @@ -0,0 +1,61 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +/**
- + * Product price calculation according rules settings.
- + */
- +class ProductPriceCalculator
- +{
- + /**
- + * @var \Magento\Framework\Pricing\PriceCurrencyInterface
- + */
- + private $priceCurrency;
- +
- + /**
- + * @param \Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency
- + */
- + public function __construct(\Magento\Framework\Pricing\PriceCurrencyInterface $priceCurrency)
- + {
- + $this->priceCurrency = $priceCurrency;
- + }
- +
- + /**
- + * Calculates product price.
- + *
- + * @param array $ruleData
- + * @param null $productData
- + * @return float
- + */
- + public function calculate($ruleData, $productData = null)
- + {
- + if ($productData !== null && isset($productData['rule_price'])) {
- + $productPrice = $productData['rule_price'];
- + } else {
- + $productPrice = $ruleData['default_price'];
- + }
- +
- + switch ($ruleData['action_operator']) {
- + case 'to_fixed':
- + $productPrice = min($ruleData['action_amount'], $productPrice);
- + break;
- + case 'to_percent':
- + $productPrice = $productPrice * $ruleData['action_amount'] / 100;
- + break;
- + case 'by_fixed':
- + $productPrice = max(0, $productPrice - $ruleData['action_amount']);
- + break;
- + case 'by_percent':
- + $productPrice = $productPrice * (1 - $ruleData['action_amount'] / 100);
- + break;
- + default:
- + $productPrice = 0;
- + }
- +
- + return $this->priceCurrency->round($productPrice);
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleGroupWebsite.php b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleGroupWebsite.php
- new file mode 100644
- index 00000000000..482aaf4834d
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleGroupWebsite.php
- @@ -0,0 +1,92 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface as TableSwapper;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +
- +/**
- + * Reindex information about rule relations with customer groups and websites.
- + */
- +class ReindexRuleGroupWebsite
- +{
- + /**
- + * @var \Magento\Framework\Stdlib\DateTime\DateTime
- + */
- + private $dateTime;
- +
- + /**
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resource;
- +
- + /**
- + * @var array
- + */
- + private $catalogRuleGroupWebsiteColumnsList = ['rule_id', 'customer_group_id', 'website_id'];
- +
- + /**
- + * @var TableSwapper
- + */
- + private $tableSwapper;
- +
- + /**
- + * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + * @param ActiveTableSwitcher $activeTableSwitcher
- + * @param TableSwapper|null $tableSwapper
- + *
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- + */
- + public function __construct(
- + \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
- + \Magento\Framework\App\ResourceConnection $resource,
- + ActiveTableSwitcher $activeTableSwitcher,
- + TableSwapper $tableSwapper = null
- + ) {
- + $this->dateTime = $dateTime;
- + $this->resource = $resource;
- + $this->tableSwapper = $tableSwapper ?: ObjectManager::getInstance()->get(TableSwapper::class);
- + }
- +
- + /**
- + * Prepare and persist information about rule relations with customer groups and websites to index table.
- + *
- + * @param bool $useAdditionalTable
- + * @return bool
- + */
- + public function execute($useAdditionalTable = false)
- + {
- + $connection = $this->resource->getConnection();
- + $timestamp = $this->dateTime->gmtTimestamp();
- +
- + $indexTable = $this->resource->getTableName('catalogrule_group_website');
- + $ruleProductTable = $this->resource->getTableName('catalogrule_product');
- + if ($useAdditionalTable) {
- + $indexTable = $this->resource->getTableName(
- + $this->tableSwapper->getWorkingTableName('catalogrule_group_website')
- + );
- + $ruleProductTable = $this->resource->getTableName(
- + $this->tableSwapper->getWorkingTableName('catalogrule_product')
- + );
- + }
- +
- + $connection->delete($indexTable);
- + $select = $connection->select()->distinct(
- + true
- + )->from(
- + $ruleProductTable,
- + $this->catalogRuleGroupWebsiteColumnsList
- + )->where(
- + "{$timestamp} >= from_time AND (({$timestamp} <= to_time AND to_time > 0) OR to_time = 0)"
- + );
- + $query = $select->insertFromSelect($indexTable, $this->catalogRuleGroupWebsiteColumnsList);
- + $connection->query($query);
- + return true;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProduct.php b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProduct.php
- new file mode 100644
- index 00000000000..f79f5aad6d6
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProduct.php
- @@ -0,0 +1,123 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface as TableSwapper;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +use Magento\Framework\App\ObjectManager;
- +
- +/**
- + * Reindex rule relations with products.
- + */
- +class ReindexRuleProduct
- +{
- + /**
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resource;
- +
- + /**
- + * @var TableSwapper
- + */
- + private $tableSwapper;
- +
- + /**
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + * @param ActiveTableSwitcher $activeTableSwitcher
- + * @param TableSwapper|null $tableSwapper
- + *
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- + */
- + public function __construct(
- + \Magento\Framework\App\ResourceConnection $resource,
- + ActiveTableSwitcher $activeTableSwitcher,
- + TableSwapper $tableSwapper = null
- + ) {
- + $this->resource = $resource;
- + $this->tableSwapper = $tableSwapper ?: ObjectManager::getInstance()->get(TableSwapper::class);
- + }
- +
- + /**
- + * Reindex information about rule relations with products.
- + *
- + * @param \Magento\CatalogRule\Model\Rule $rule
- + * @param int $batchCount
- + * @param bool $useAdditionalTable
- + * @return bool
- + * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- + * @SuppressWarnings(PHPMD.NPathComplexity)
- + */
- + public function execute(
- + \Magento\CatalogRule\Model\Rule $rule,
- + $batchCount,
- + $useAdditionalTable = false
- + ) {
- + if (!$rule->getIsActive() || empty($rule->getWebsiteIds())) {
- + return false;
- + }
- +
- + $connection = $this->resource->getConnection();
- + $websiteIds = $rule->getWebsiteIds();
- + if (!is_array($websiteIds)) {
- + $websiteIds = explode(',', $websiteIds);
- + }
- +
- + \Magento\Framework\Profiler::start('__MATCH_PRODUCTS__');
- + $productIds = $rule->getMatchingProductIds();
- + \Magento\Framework\Profiler::stop('__MATCH_PRODUCTS__');
- +
- + $indexTable = $this->resource->getTableName('catalogrule_product');
- + if ($useAdditionalTable) {
- + $indexTable = $this->resource->getTableName(
- + $this->tableSwapper->getWorkingTableName('catalogrule_product')
- + );
- + }
- +
- + $ruleId = $rule->getId();
- + $customerGroupIds = $rule->getCustomerGroupIds();
- + $fromTime = strtotime($rule->getFromDate());
- + $toTime = strtotime($rule->getToDate());
- + $toTime = $toTime ? $toTime + \Magento\CatalogRule\Model\Indexer\IndexBuilder::SECONDS_IN_DAY - 1 : 0;
- + $sortOrder = (int)$rule->getSortOrder();
- + $actionOperator = $rule->getSimpleAction();
- + $actionAmount = $rule->getDiscountAmount();
- + $actionStop = $rule->getStopRulesProcessing();
- +
- + $rows = [];
- +
- + foreach ($productIds as $productId => $validationByWebsite) {
- + foreach ($websiteIds as $websiteId) {
- + if (empty($validationByWebsite[$websiteId])) {
- + continue;
- + }
- + foreach ($customerGroupIds as $customerGroupId) {
- + $rows[] = [
- + 'rule_id' => $ruleId,
- + 'from_time' => $fromTime,
- + 'to_time' => $toTime,
- + 'website_id' => $websiteId,
- + 'customer_group_id' => $customerGroupId,
- + 'product_id' => $productId,
- + 'action_operator' => $actionOperator,
- + 'action_amount' => $actionAmount,
- + 'action_stop' => $actionStop,
- + 'sort_order' => $sortOrder,
- + ];
- +
- + if (count($rows) == $batchCount) {
- + $connection->insertMultiple($indexTable, $rows);
- + $rows = [];
- + }
- + }
- + }
- + }
- + if (!empty($rows)) {
- + $connection->insertMultiple($indexTable, $rows);
- + }
- + return true;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProductPrice.php b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProductPrice.php
- new file mode 100644
- index 00000000000..6a87be3c50a
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/ReindexRuleProductPrice.php
- @@ -0,0 +1,168 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +/**
- + * Reindex product prices according rule settings.
- + */
- +class ReindexRuleProductPrice
- +{
- + /**
- + * @var \Magento\Store\Model\StoreManagerInterface
- + */
- + private $storeManager;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder
- + */
- + private $ruleProductsSelectBuilder;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator
- + */
- + private $productPriceCalculator;
- +
- + /**
- + * @var \Magento\Framework\Stdlib\DateTime\DateTime
- + */
- + private $dateTime;
- +
- + /**
- + * @var \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor
- + */
- + private $pricesPersistor;
- +
- + /**
- + * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- + * @param RuleProductsSelectBuilder $ruleProductsSelectBuilder
- + * @param ProductPriceCalculator $productPriceCalculator
- + * @param \Magento\Framework\Stdlib\DateTime\DateTime $dateTime
- + * @param \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor $pricesPersistor
- + */
- + public function __construct(
- + \Magento\Store\Model\StoreManagerInterface $storeManager,
- + \Magento\CatalogRule\Model\Indexer\RuleProductsSelectBuilder $ruleProductsSelectBuilder,
- + \Magento\CatalogRule\Model\Indexer\ProductPriceCalculator $productPriceCalculator,
- + \Magento\Framework\Stdlib\DateTime\DateTime $dateTime,
- + \Magento\CatalogRule\Model\Indexer\RuleProductPricesPersistor $pricesPersistor
- + ) {
- + $this->storeManager = $storeManager;
- + $this->ruleProductsSelectBuilder = $ruleProductsSelectBuilder;
- + $this->productPriceCalculator = $productPriceCalculator;
- + $this->dateTime = $dateTime;
- + $this->pricesPersistor = $pricesPersistor;
- + }
- +
- + /**
- + * Reindex product prices.
- + *
- + * @param int $batchCount
- + * @param \Magento\Catalog\Model\Product|null $product
- + * @param bool $useAdditionalTable
- + * @return bool
- + * @SuppressWarnings(PHPMD.CyclomaticComplexity)
- + */
- + public function execute(
- + $batchCount,
- + \Magento\Catalog\Model\Product $product = null,
- + $useAdditionalTable = false
- + ) {
- + $fromDate = mktime(0, 0, 0, date('m'), date('d') - 1);
- + $toDate = mktime(0, 0, 0, date('m'), date('d') + 1);
- +
- + /**
- + * Update products rules prices per each website separately
- + * because of max join limit in mysql
- + */
- + foreach ($this->storeManager->getWebsites() as $website) {
- + $productsStmt = $this->ruleProductsSelectBuilder->build($website->getId(), $product, $useAdditionalTable);
- + $dayPrices = [];
- + $stopFlags = [];
- + $prevKey = null;
- +
- + while ($ruleData = $productsStmt->fetch()) {
- + $ruleProductId = $ruleData['product_id'];
- + $productKey = $ruleProductId .
- + '_' .
- + $ruleData['website_id'] .
- + '_' .
- + $ruleData['customer_group_id'];
- +
- + if ($prevKey && $prevKey != $productKey) {
- + $stopFlags = [];
- + if (count($dayPrices) > $batchCount) {
- + $this->pricesPersistor->execute($dayPrices, $useAdditionalTable);
- + $dayPrices = [];
- + }
- + }
- +
- + $ruleData['from_time'] = $this->roundTime($ruleData['from_time']);
- + $ruleData['to_time'] = $this->roundTime($ruleData['to_time']);
- + /**
- + * Build prices for each day
- + */
- + for ($time = $fromDate; $time <= $toDate; $time += IndexBuilder::SECONDS_IN_DAY) {
- + if (($ruleData['from_time'] == 0 ||
- + $time >= $ruleData['from_time']) && ($ruleData['to_time'] == 0 ||
- + $time <= $ruleData['to_time'])
- + ) {
- + $priceKey = $time . '_' . $productKey;
- +
- + if (isset($stopFlags[$priceKey])) {
- + continue;
- + }
- +
- + if (!isset($dayPrices[$priceKey])) {
- + $dayPrices[$priceKey] = [
- + 'rule_date' => $time,
- + 'website_id' => $ruleData['website_id'],
- + 'customer_group_id' => $ruleData['customer_group_id'],
- + 'product_id' => $ruleProductId,
- + 'rule_price' => $this->productPriceCalculator->calculate($ruleData),
- + 'latest_start_date' => $ruleData['from_time'],
- + 'earliest_end_date' => $ruleData['to_time'],
- + ];
- + } else {
- + $dayPrices[$priceKey]['rule_price'] = $this->productPriceCalculator->calculate(
- + $ruleData,
- + $dayPrices[$priceKey]
- + );
- + $dayPrices[$priceKey]['latest_start_date'] = max(
- + $dayPrices[$priceKey]['latest_start_date'],
- + $ruleData['from_time']
- + );
- + $dayPrices[$priceKey]['earliest_end_date'] = min(
- + $dayPrices[$priceKey]['earliest_end_date'],
- + $ruleData['to_time']
- + );
- + }
- +
- + if ($ruleData['action_stop']) {
- + $stopFlags[$priceKey] = true;
- + }
- + }
- + }
- +
- + $prevKey = $productKey;
- + }
- + $this->pricesPersistor->execute($dayPrices, $useAdditionalTable);
- + }
- + return true;
- + }
- +
- + /**
- + * @param int $timeStamp
- + * @return int
- + */
- + private function roundTime($timeStamp)
- + {
- + if (is_numeric($timeStamp) && $timeStamp != 0) {
- + $timeStamp = $this->dateTime->timestamp($this->dateTime->date('Y-m-d 00:00:00', $timeStamp));
- + }
- + return $timeStamp;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductPricesPersistor.php b/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductPricesPersistor.php
- new file mode 100644
- index 00000000000..ad5a2d25948
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductPricesPersistor.php
- @@ -0,0 +1,95 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface as TableSwapper;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +use Magento\Framework\App\ObjectManager;
- +
- +/**
- + * Persist product prices to index table.
- + */
- +class RuleProductPricesPersistor
- +{
- + /**
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resource;
- +
- + /**
- + * @var \Magento\Framework\Stdlib\DateTime
- + */
- + private $dateFormat;
- +
- + /**
- + * @var TableSwapper
- + */
- + private $tableSwapper;
- +
- + /**
- + * @param \Magento\Framework\Stdlib\DateTime $dateFormat
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + * @param ActiveTableSwitcher $activeTableSwitcher
- + * @param TableSwapper|null $tableSwapper
- + *
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- + */
- + public function __construct(
- + \Magento\Framework\Stdlib\DateTime $dateFormat,
- + \Magento\Framework\App\ResourceConnection $resource,
- + ActiveTableSwitcher $activeTableSwitcher,
- + TableSwapper $tableSwapper = null
- + ) {
- + $this->dateFormat = $dateFormat;
- + $this->resource = $resource;
- + $this->tableSwapper = $tableSwapper ?: ObjectManager::getInstance()->get(TableSwapper::class);
- + }
- +
- + /**
- + * Persist prices data to index table.
- + *
- + * @param array $priceData
- + * @param bool $useAdditionalTable
- + * @return bool
- + * @throws \Exception
- + */
- + public function execute(array $priceData, $useAdditionalTable = false)
- + {
- + if (empty($priceData)) {
- + return false;
- + }
- +
- + $connection = $this->resource->getConnection();
- + $indexTable = $this->resource->getTableName('catalogrule_product_price');
- + if ($useAdditionalTable) {
- + $indexTable = $this->resource->getTableName(
- + $this->tableSwapper->getWorkingTableName('catalogrule_product_price')
- + );
- + }
- +
- + $productIds = [];
- +
- + try {
- + foreach ($priceData as $key => $data) {
- + $productIds['product_id'] = $data['product_id'];
- + $priceData[$key]['rule_date'] = $this->dateFormat->formatDate($data['rule_date'], false);
- + $priceData[$key]['latest_start_date'] = $this->dateFormat->formatDate(
- + $data['latest_start_date'],
- + false
- + );
- + $priceData[$key]['earliest_end_date'] = $this->dateFormat->formatDate(
- + $data['earliest_end_date'],
- + false
- + );
- + }
- + $connection->insertOnDuplicate($indexTable, $priceData);
- + } catch (\Exception $e) {
- + throw $e;
- + }
- + return true;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductsSelectBuilder.php b/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductsSelectBuilder.php
- new file mode 100644
- index 00000000000..65ca07a524a
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule/Model/Indexer/RuleProductsSelectBuilder.php
- @@ -0,0 +1,163 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRule\Model\Indexer;
- +
- +use Magento\CatalogRule\Api\IndexerTableSwapperInterface as TableSwapper;
- +use Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher;
- +use Magento\Framework\App\ObjectManager;
- +
- +/**
- + * Build select for rule relation with product.
- + */
- +class RuleProductsSelectBuilder
- +{
- + /**
- + * @var \Magento\Framework\App\ResourceConnection
- + */
- + private $resource;
- +
- + /**
- + * @var \Magento\Eav\Model\Config
- + */
- + private $eavConfig;
- +
- + /**
- + * @var \Magento\Store\Model\StoreManagerInterface
- + */
- + private $storeManager;
- +
- + /**
- + * @var \Magento\Framework\EntityManager\MetadataPool
- + */
- + private $metadataPool;
- +
- + /**
- + * @var TableSwapper
- + */
- + private $tableSwapper;
- +
- + /**
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + * @param \Magento\Eav\Model\Config $eavConfig
- + * @param \Magento\Store\Model\StoreManagerInterface $storeManager
- + * @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
- + * @param ActiveTableSwitcher $activeTableSwitcher
- + * @param TableSwapper|null $tableSwapper
- + *
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- + */
- + public function __construct(
- + \Magento\Framework\App\ResourceConnection $resource,
- + \Magento\Eav\Model\Config $eavConfig,
- + \Magento\Store\Model\StoreManagerInterface $storeManager,
- + \Magento\Framework\EntityManager\MetadataPool $metadataPool,
- + ActiveTableSwitcher $activeTableSwitcher,
- + TableSwapper $tableSwapper = null
- + ) {
- + $this->eavConfig = $eavConfig;
- + $this->storeManager = $storeManager;
- + $this->metadataPool = $metadataPool;
- + $this->resource = $resource;
- + $this->tableSwapper = $tableSwapper ?: ObjectManager::getInstance()->get(TableSwapper::class);
- + }
- +
- + /**
- + * Build select for indexer according passed parameters.
- + *
- + * @param int $websiteId
- + * @param \Magento\Catalog\Model\Product|null $product
- + * @param bool $useAdditionalTable
- + * @return \Zend_Db_Statement_Interface
- + */
- + public function build(
- + $websiteId,
- + \Magento\Catalog\Model\Product $product = null,
- + $useAdditionalTable = false
- + ) {
- + $connection = $this->resource->getConnection();
- + $indexTable = $this->resource->getTableName('catalogrule_product');
- + if ($useAdditionalTable) {
- + $indexTable = $this->resource->getTableName(
- + $this->tableSwapper->getWorkingTableName('catalogrule_product')
- + );
- + }
- +
- + /**
- + * Sort order is important
- + * It used for check stop price rule condition.
- + * website_id customer_group_id product_id sort_order
- + * 1 1 1 0
- + * 1 1 1 1
- + * 1 1 1 2
- + * if row with sort order 1 will have stop flag we should exclude
- + * all next rows for same product id from price calculation
- + */
- + $select = $connection->select()->from(
- + ['rp' => $indexTable]
- + )->order(
- + ['rp.website_id', 'rp.customer_group_id', 'rp.product_id', 'rp.sort_order', 'rp.rule_id']
- + );
- +
- + if ($product && $product->getEntityId()) {
- + $select->where('rp.product_id=?', $product->getEntityId());
- + }
- +
- + /**
- + * Join default price and websites prices to result
- + */
- + $priceAttr = $this->eavConfig->getAttribute(\Magento\Catalog\Model\Product::ENTITY, 'price');
- + $priceTable = $priceAttr->getBackend()->getTable();
- + $attributeId = $priceAttr->getId();
- +
- + $linkField = $this->metadataPool
- + ->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class)
- + ->getLinkField();
- + $select->join(
- + ['e' => $this->resource->getTableName('catalog_product_entity')],
- + sprintf('e.entity_id = rp.product_id'),
- + []
- + );
- + $joinCondition = '%1$s.' . $linkField . '=e.' . $linkField . ' AND (%1$s.attribute_id='
- + . $attributeId
- + . ') and %1$s.store_id=%2$s';
- +
- + $select->join(
- + ['pp_default' => $priceTable],
- + sprintf($joinCondition, 'pp_default', \Magento\Store\Model\Store::DEFAULT_STORE_ID),
- + []
- + );
- +
- + $website = $this->storeManager->getWebsite($websiteId);
- + $defaultGroup = $website->getDefaultGroup();
- + if ($defaultGroup instanceof \Magento\Store\Model\Group) {
- + $storeId = $defaultGroup->getDefaultStoreId();
- + } else {
- + $storeId = \Magento\Store\Model\Store::DEFAULT_STORE_ID;
- + }
- +
- + $select->joinInner(
- + ['product_website' => $this->resource->getTableName('catalog_product_website')],
- + 'product_website.product_id=rp.product_id '
- + . 'AND product_website.website_id = rp.website_id '
- + . 'AND product_website.website_id='
- + . $websiteId,
- + []
- + );
- +
- + $tableAlias = 'pp' . $websiteId;
- + $select->joinLeft(
- + [$tableAlias => $priceTable],
- + sprintf($joinCondition, $tableAlias, $storeId),
- + []
- + );
- + $select->columns([
- + 'default_price' => $connection->getIfNullSql($tableAlias . '.value', 'pp_default.value'),
- + ]);
- +
- + return $connection->query($select);
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule/Model/Rule.php b/vendor/magento/module-catalog-rule/Model/Rule.php
- index f94bdb5fa80..ef1c286eb9b 100644
- --- a/vendor/magento/module-catalog-rule/Model/Rule.php
- +++ b/vendor/magento/module-catalog-rule/Model/Rule.php
- @@ -505,9 +505,11 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements \Magento\Catalog
- public function afterSave()
- {
- if ($this->isObjectNew()) {
- - $this->getMatchingProductIds();
- - if (!empty($this->_productIds) && is_array($this->_productIds)) {
- - $this->_ruleProductProcessor->reindexList($this->_productIds);
- + if (!$this->_ruleProductProcessor->isIndexerScheduled()) {
- + $this->getMatchingProductIds();
- + if (!empty($this->_productIds) && is_array($this->_productIds)) {
- + $this->_getResource()->addCommitCallback([$this, 'reindex']);
- + }
- }
- } else {
- $this->_ruleProductProcessor->getIndexer()->invalidate();
- @@ -515,6 +517,16 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements \Magento\Catalog
- return parent::afterSave();
- }
- + /**
- + * Init indexing process after rule save
- + *
- + * @return void
- + */
- + public function reindex()
- + {
- + $this->_ruleProductProcessor->reindexList($this->_productIds);
- + }
- +
- /**
- * {@inheritdoc}
- *
- diff --git a/vendor/magento/module-catalog-rule/Setup/UpgradeSchema.php b/vendor/magento/module-catalog-rule/Setup/UpgradeSchema.php
- index ac667186a9a..c86f02c40a5 100644
- --- a/vendor/magento/module-catalog-rule/Setup/UpgradeSchema.php
- +++ b/vendor/magento/module-catalog-rule/Setup/UpgradeSchema.php
- @@ -26,6 +26,31 @@ class UpgradeSchema implements UpgradeSchemaInterface
- $this->removeSubProductDiscounts($setup);
- }
- + if (version_compare($context->getVersion(), '2.0.1.1.2', '<')) {
- + $connection = $setup->getConnection();
- + $connection->dropForeignKey(
- + $setup->getTable('catalogrule_group_website'),
- + $setup->getFkName(
- + 'catalogrule_group_website',
- + 'customer_group_id',
- + 'customer_group',
- + 'customer_group_id'
- + )
- + );
- + $connection->dropForeignKey(
- + $setup->getTable('catalogrule_group_website'),
- + $setup->getFkName('catalogrule_group_website', 'rule_id', 'catalogrule', 'rule_id')
- + );
- + $connection->dropForeignKey(
- + $setup->getTable('catalogrule_group_website'),
- + $setup->getFkName('catalogrule_group_website', 'website_id', 'store_website', 'website_id')
- + );
- +
- + $this->addReplicaTable($setup, 'catalogrule_product', 'catalogrule_product_replica');
- + $this->addReplicaTable($setup, 'catalogrule_product_price', 'catalogrule_product_price_replica');
- + $this->addReplicaTable($setup, 'catalogrule_group_website', 'catalogrule_group_website_replica');
- + }
- +
- $setup->endSetup();
- }
- @@ -55,4 +80,22 @@ class UpgradeSchema implements UpgradeSchemaInterface
- }
- }
- }
- +
- + /**
- + * Add the replica table for existing one.
- + *
- + * @param SchemaSetupInterface $setup
- + * @param string $existingTable
- + * @param string $replicaTable
- + * @return void
- + */
- + private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $replicaTable)
- + {
- + $sql = sprintf(
- + 'CREATE TABLE IF NOT EXISTS %s LIKE %s',
- + $setup->getTable($replicaTable),
- + $setup->getTable($existingTable)
- + );
- + $setup->getConnection()->query($sql);
- + }
- }
- diff --git a/vendor/magento/module-catalog-rule/etc/di.xml b/vendor/magento/module-catalog-rule/etc/di.xml
- index 6783fd6d69b..1aaed9c3cbd 100644
- --- a/vendor/magento/module-catalog-rule/etc/di.xml
- +++ b/vendor/magento/module-catalog-rule/etc/di.xml
- @@ -126,4 +126,5 @@
- </argument>
- </arguments>
- </type>
- + <preference for="Magento\CatalogRule\Api\IndexerTableSwapperInterface" type="Magento\CatalogRule\Model\Indexer\IndexerTableSwapper" />
- </config>
- diff --git a/vendor/magento/module-catalog-rule/etc/module.xml b/vendor/magento/module-catalog-rule/etc/module.xml
- index 6a864895ffe..d0af39d3f01 100644
- --- a/vendor/magento/module-catalog-rule/etc/module.xml
- +++ b/vendor/magento/module-catalog-rule/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_CatalogRule" setup_version="2.0.1">
- + <module name="Magento_CatalogRule" setup_version="2.0.1.1.2">
- <sequence>
- <module name="Magento_Rule"/>
- <module name="Magento_Catalog"/>
- diff --git a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider.php b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider.php
- index 495b22048b4..0c8c26904d1 100644
- --- a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider.php
- +++ b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Aggregation/DataProvider.php
- @@ -6,6 +6,7 @@
- namespace Magento\CatalogSearch\Model\Adapter\Mysql\Aggregation;
- use Magento\Catalog\Model\Product;
- +use Magento\CatalogInventory\Model\Stock;
- use Magento\Customer\Model\Session;
- use Magento\Eav\Model\Config;
- use Magento\Framework\App\ResourceConnection;
- @@ -15,7 +16,6 @@ use Magento\Framework\DB\Ddl\Table;
- use Magento\Framework\DB\Select;
- use Magento\Framework\Search\Adapter\Mysql\Aggregation\DataProviderInterface;
- use Magento\Framework\Search\Request\BucketInterface;
- -use Magento\CatalogInventory\Model\Stock;
- /**
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- diff --git a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/AliasResolver.php b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/AliasResolver.php
- index 52a2c6ff40c..8f5a231b1dd 100644
- --- a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/AliasResolver.php
- +++ b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/AliasResolver.php
- @@ -6,24 +6,22 @@
- namespace Magento\CatalogSearch\Model\Adapter\Mysql\Filter;
- +
- use Magento\CatalogSearch\Model\Search\RequestGenerator;
- /**
- - * Purpose of class is to resolve table alias for Search Request filter.
- + * Purpose of class is to resolve table alias for Search Request filter
- */
- class AliasResolver
- {
- /**
- - * The suffix for stock status filter that may be added to the query beside the filter query.
- + * The suffix for stock status filter that may be added to the query beside the filter query
- * Used when showing of Out of Stock products is disabled.
- */
- const STOCK_FILTER_SUFFIX = '_stock';
- /**
- - * Returns alias of the filter in database.
- - *
- * @param \Magento\Framework\Search\Request\FilterInterface $filter
- - *
- * @return string alias of the filter in database
- */
- public function getAlias(\Magento\Framework\Search\Request\FilterInterface $filter)
- @@ -41,7 +39,6 @@ class AliasResolver
- $alias = $field . RequestGenerator::FILTER_SUFFIX;
- break;
- }
- -
- return $alias;
- }
- }
- diff --git a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/Preprocessor.php b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/Preprocessor.php
- index 05652445264..27a80aba56a 100644
- --- a/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/Preprocessor.php
- +++ b/vendor/magento/module-catalog-search/Model/Adapter/Mysql/Filter/Preprocessor.php
- @@ -8,8 +8,11 @@ namespace Magento\CatalogSearch\Model\Adapter\Mysql\Filter;
- use Magento\Catalog\Api\Data\ProductInterface;
- use Magento\Catalog\Model\Product;
- use Magento\Catalog\Model\ResourceModel\Eav\Attribute;
- +use Magento\CatalogInventory\Model\Stock;
- use Magento\CatalogSearch\Model\Search\TableMapper;
- use Magento\Eav\Model\Config;
- +use Magento\Framework\App\Config\ScopeConfigInterface;
- +use Magento\Framework\App\ObjectManager;
- use Magento\Framework\App\ResourceConnection;
- use Magento\Framework\App\ScopeResolverInterface;
- use Magento\Framework\DB\Adapter\AdapterInterface;
- @@ -17,11 +20,8 @@ use Magento\Framework\EntityManager\MetadataPool;
- use Magento\Framework\Search\Adapter\Mysql\ConditionManager;
- use Magento\Framework\Search\Adapter\Mysql\Filter\PreprocessorInterface;
- use Magento\Framework\Search\Request\FilterInterface;
- -use Magento\Store\Model\Store;
- -use Magento\CatalogInventory\Model\Stock;
- -use Magento\Framework\App\Config\ScopeConfigInterface;
- -use Magento\Framework\App\ObjectManager;
- use Magento\Store\Model\ScopeInterface;
- +use Magento\Store\Model\Store;
- /**
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- @@ -64,22 +64,11 @@ class Preprocessor implements PreprocessorInterface
- private $metadataPool;
- /**
- - * @deprecated
- - *
- - * @var TableMapper
- - */
- - private $tableMapper;
- -
- - /**
- - * Scope config.
- - *
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- /**
- - * Resolving table alias for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- @@ -91,8 +80,9 @@ class Preprocessor implements PreprocessorInterface
- * @param ResourceConnection $resource
- * @param TableMapper $tableMapper
- * @param string $attributePrefix
- - * @param ScopeConfigInterface $scopeConfig
- - * @param AliasResolver $aliasResolver
- + * @param ScopeConfigInterface|null $scopeConfig
- + * @param AliasResolver|null $aliasResolver
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function __construct(
- ConditionManager $conditionManager,
- @@ -110,7 +100,6 @@ class Preprocessor implements PreprocessorInterface
- $this->resource = $resource;
- $this->connection = $resource->getConnection();
- $this->attributePrefix = $attributePrefix;
- - $this->tableMapper = $tableMapper;
- $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
- $this->aliasResolver = $aliasResolver ?: ObjectManager::getInstance()->get(AliasResolver::class);
- }
- @@ -264,8 +253,6 @@ class Preprocessor implements PreprocessorInterface
- }
- /**
- - * Checks if it is necessary to show out of stock products.
- - *
- * @return bool
- */
- private function isAddStockFilter()
- @@ -274,7 +261,6 @@ class Preprocessor implements PreprocessorInterface
- 'cataloginventory/options/show_out_of_stock',
- ScopeInterface::SCOPE_STORE
- );
- -
- return false === $isShowOutOfStock;
- }
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php b/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php
- index 0783bdb424e..fff770bc446 100644
- --- a/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Fulltext.php
- @@ -6,11 +6,16 @@
- namespace Magento\CatalogSearch\Model\Indexer;
- use Magento\CatalogSearch\Model\Indexer\Fulltext\Action\FullFactory;
- +use Magento\CatalogSearch\Model\Indexer\Scope\State;
- use Magento\CatalogSearch\Model\ResourceModel\Fulltext as FulltextResource;
- -use \Magento\Framework\Search\Request\Config as SearchRequestConfig;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\Framework\Search\Request\Config as SearchRequestConfig;
- use Magento\Framework\Search\Request\DimensionFactory;
- use Magento\Store\Model\StoreManagerInterface;
- +/**
- + * Provide functionality for Fulltext Search indexing
- + */
- class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\Framework\Mview\ActionInterface
- {
- /**
- @@ -18,34 +23,51 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
- */
- const INDEXER_ID = 'catalogsearch_fulltext';
- - /** @var array index structure */
- + /**
- + * @var array index structure
- + */
- protected $data;
- /**
- * @var IndexerHandlerFactory
- */
- private $indexerHandlerFactory;
- +
- /**
- * @var StoreManagerInterface
- */
- private $storeManager;
- +
- /**
- - * @var DimensionFactory
- + * @var \Magento\Framework\Search\Request\DimensionFactory
- */
- private $dimensionFactory;
- +
- /**
- - * @var Full
- + * @var \Magento\CatalogSearch\Model\Indexer\Fulltext\Action\Full
- */
- private $fullAction;
- +
- /**
- * @var FulltextResource
- */
- private $fulltextResource;
- +
- /**
- - * @var SearchRequestConfig
- + * @var \Magento\Framework\Search\Request\Config
- */
- private $searchRequestConfig;
- + /**
- + * @var IndexSwitcherInterface
- + */
- + private $indexSwitcher;
- +
- + /**
- + * @var \Magento\CatalogSearch\Model\Indexer\Scope\State
- + */
- + private $indexScopeState;
- +
- /**
- * @param FullFactory $fullActionFactory
- * @param IndexerHandlerFactory $indexerHandlerFactory
- @@ -54,6 +76,8 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
- * @param FulltextResource $fulltextResource
- * @param SearchRequestConfig $searchRequestConfig
- * @param array $data
- + * @param IndexSwitcherInterface $indexSwitcher
- + * @param Scope\State $indexScopeState
- */
- public function __construct(
- FullFactory $fullActionFactory,
- @@ -62,7 +86,9 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
- DimensionFactory $dimensionFactory,
- FulltextResource $fulltextResource,
- SearchRequestConfig $searchRequestConfig,
- - array $data
- + array $data,
- + IndexSwitcherInterface $indexSwitcher = null,
- + State $indexScopeState = null
- ) {
- $this->fullAction = $fullActionFactory->create(['data' => $data]);
- $this->indexerHandlerFactory = $indexerHandlerFactory;
- @@ -71,6 +97,14 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
- $this->fulltextResource = $fulltextResource;
- $this->searchRequestConfig = $searchRequestConfig;
- $this->data = $data;
- + if (null === $indexSwitcher) {
- + $indexSwitcher = ObjectManager::getInstance()->get(IndexSwitcherInterface::class);
- + }
- + if (null === $indexScopeState) {
- + $indexScopeState = ObjectManager::getInstance()->get(State::class);
- + }
- + $this->indexSwitcher = $indexSwitcher;
- + $this->indexScopeState = $indexScopeState;
- }
- /**
- @@ -106,10 +140,14 @@ class Fulltext implements \Magento\Framework\Indexer\ActionInterface, \Magento\F
- 'data' => $this->data
- ]);
- foreach ($storeIds as $storeId) {
- - $dimension = $this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId]);
- - $saveHandler->cleanIndex([$dimension]);
- - $saveHandler->saveIndex([$dimension], $this->fullAction->rebuildStoreIndex($storeId));
- + $dimensions = [$this->dimensionFactory->create(['name' => 'scope', 'value' => $storeId])];
- + $this->indexScopeState->useTemporaryIndex();
- +
- + $saveHandler->cleanIndex($dimensions);
- + $saveHandler->saveIndex($dimensions, $this->fullAction->rebuildStoreIndex($storeId));
- + $this->indexSwitcher->switchIndex($dimensions);
- + $this->indexScopeState->useRegularIndex();
- }
- $this->fulltextResource->resetSearchResults();
- $this->searchRequestConfig->reset();
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/IndexStructure.php b/vendor/magento/module-catalog-search/Model/Indexer/IndexStructure.php
- index 43c3eb670f4..92eff50cfc1 100644
- --- a/vendor/magento/module-catalog-search/Model/Indexer/IndexStructure.php
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/IndexStructure.php
- @@ -12,6 +12,7 @@ use Magento\Framework\DB\Ddl\Table;
- use Magento\Framework\Search\Request\Dimension;
- use Magento\Framework\Indexer\IndexStructureInterface;
- use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
- +use Magento\Framework\Search\Request\IndexScopeResolverInterface;
- class IndexStructure implements IndexStructureInterface
- {
- @@ -19,6 +20,7 @@ class IndexStructure implements IndexStructureInterface
- * @var Resource
- */
- private $resource;
- +
- /**
- * @var IndexScopeResolver
- */
- @@ -26,11 +28,11 @@ class IndexStructure implements IndexStructureInterface
- /**
- * @param ResourceConnection $resource
- - * @param IndexScopeResolver $indexScopeResolver
- + * @param IndexScopeResolverInterface $indexScopeResolver
- */
- public function __construct(
- ResourceConnection $resource,
- - IndexScopeResolver $indexScopeResolver
- + IndexScopeResolverInterface $indexScopeResolver
- ) {
- $this->resource = $resource;
- $this->indexScopeResolver = $indexScopeResolver;
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherInterface.php b/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherInterface.php
- new file mode 100644
- index 00000000000..ba5fb461dde
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherInterface.php
- @@ -0,0 +1,22 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\CatalogSearch\Model\Indexer;
- +
- +/**
- + * Provides a functionality to replace main index with its temporary representation
- + */
- +interface IndexSwitcherInterface
- +{
- + /**
- + * Switch current index with temporary index
- + *
- + * It will drop current index table and rename temporary index table to the current index table.
- + *
- + * @param array $dimensions
- + * @return void
- + */
- + public function switchIndex(array $dimensions);
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherProxy.php b/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherProxy.php
- new file mode 100644
- index 00000000000..2ce093ed99e
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/IndexSwitcherProxy.php
- @@ -0,0 +1,100 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer;
- +
- +use Magento\Framework\App\Config\ScopeConfigInterface;
- +use Magento\Framework\ObjectManagerInterface;
- +use Magento\Store\Model\ScopeInterface;
- +
- +/**
- + * Proxy for adapter-specific index switcher
- + */
- +class IndexSwitcherProxy implements IndexSwitcherInterface
- +{
- + /**
- + * Object Manager instance
- + *
- + * @var ObjectManagerInterface
- + */
- + private $objectManager = null;
- +
- + /**
- + * Instance name to create
- + *
- + * @var string
- + */
- + private $handlers;
- +
- + /**
- + * @var ScopeConfigInterface
- + */
- + private $scopeConfig;
- +
- + /**
- + * Configuration path by which current indexer handler stored
- + *
- + * @var string
- + */
- + private $configPath;
- +
- + /**
- + * Factory constructor
- + *
- + * @param ObjectManagerInterface $objectManager
- + * @param ScopeConfigInterface $scopeConfig
- + * @param string $configPath
- + * @param string[] $handlers
- + */
- + public function __construct(
- + ObjectManagerInterface $objectManager,
- + ScopeConfigInterface $scopeConfig,
- + $configPath,
- + array $handlers = []
- + ) {
- + $this->objectManager = $objectManager;
- + $this->scopeConfig = $scopeConfig;
- + $this->configPath = $configPath;
- + $this->handlers = $handlers;
- + }
- +
- + /**
- + * {@inheritDoc}
- + *
- + * As index switcher is an optional part of the search SPI, it may be not defined by a search engine.
- + * It is especially reasonable for search engines with pre-defined indexes declaration (like old SOLR and Sphinx)
- + * which cannot create temporary indexes on the fly.
- + * That's the reason why this method do nothing for the case
- + * when switcher is not defined for a specific search engine.
- + */
- + public function switchIndex(array $dimensions)
- + {
- + $currentHandler = $this->scopeConfig->getValue($this->configPath, ScopeInterface::SCOPE_STORE);
- + if (!isset($this->handlers[$currentHandler])) {
- + return;
- + }
- + $this->create($currentHandler)->switchIndex($dimensions);
- + }
- +
- + /**
- + * Create indexer handler
- + *
- + * @param string $handler
- + * @return IndexSwitcherInterface
- + */
- + private function create($handler)
- + {
- + $indexSwitcher = $this->objectManager->create($this->handlers[$handler]);
- +
- + if (!$indexSwitcher instanceof IndexSwitcherInterface) {
- + throw new \InvalidArgumentException(
- + $handler . ' index switcher doesn\'t implement ' . IndexSwitcherInterface::class
- + );
- + }
- +
- + return $indexSwitcher;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/IndexerHandler.php b/vendor/magento/module-catalog-search/Model/Indexer/IndexerHandler.php
- index 2d98f3c06b6..5051b76a41d 100644
- --- a/vendor/magento/module-catalog-search/Model/Indexer/IndexerHandler.php
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/IndexerHandler.php
- @@ -7,13 +7,11 @@ namespace Magento\CatalogSearch\Model\Indexer;
- use Magento\Eav\Model\Config;
- use Magento\Framework\App\ResourceConnection;
- -use Magento\Framework\DB\Adapter\AdapterInterface;
- use Magento\Framework\Indexer\SaveHandler\IndexerInterface;
- use Magento\Framework\Indexer\IndexStructureInterface;
- use Magento\Framework\Search\Request\Dimension;
- use Magento\Framework\Search\Request\IndexScopeResolverInterface;
- use Magento\Framework\Indexer\SaveHandler\Batch;
- -use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
- class IndexerHandler implements IndexerInterface
- {
- @@ -62,7 +60,7 @@ class IndexerHandler implements IndexerInterface
- * @param ResourceConnection $resource
- * @param Config $eavConfig
- * @param Batch $batch
- - * @param \Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver $indexScopeResolver
- + * @param IndexScopeResolverInterface $indexScopeResolver
- * @param array $data
- * @param int $batchSize
- */
- @@ -71,7 +69,7 @@ class IndexerHandler implements IndexerInterface
- ResourceConnection $resource,
- Config $eavConfig,
- Batch $batch,
- - IndexScopeResolver $indexScopeResolver,
- + IndexScopeResolverInterface $indexScopeResolver,
- array $data,
- $batchSize = 100
- ) {
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexSwitcher.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexSwitcher.php
- new file mode 100644
- index 00000000000..87a7b7110d3
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexSwitcher.php
- @@ -0,0 +1,76 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +use Magento\CatalogSearch\Model\Indexer\IndexSwitcherInterface;
- +use Magento\Framework\App\ResourceConnection;
- +use Magento\Framework\Search\Request\IndexScopeResolverInterface;
- +
- +/**
- + * Provides a functionality to replace main index with its temporary representation
- + */
- +class IndexSwitcher implements IndexSwitcherInterface
- +{
- + /**
- + * @var Resource
- + */
- + private $resource;
- +
- + /**
- + * @var ScopeProxy
- + */
- + private $resolver;
- +
- + /**
- + * @var State
- + */
- + private $state;
- +
- + /**
- + * @param ResourceConnection $resource
- + * @param IndexScopeResolverInterface $indexScopeResolver
- + * @param State $state
- + */
- + public function __construct(
- + ResourceConnection $resource,
- + IndexScopeResolverInterface $indexScopeResolver,
- + State $state
- + ) {
- + $this->resource = $resource;
- + $this->resolver = $indexScopeResolver;
- + $this->state = $state;
- + }
- +
- + /**
- + * {@inheritdoc}
- + * @throws IndexTableNotExistException
- + */
- + public function switchIndex(array $dimensions)
- + {
- + if (State::USE_TEMPORARY_INDEX === $this->state->getState()) {
- + $index = \Magento\CatalogSearch\Model\Indexer\Fulltext::INDEXER_ID;
- +
- + $temporalIndexTable = $this->resolver->resolve($index, $dimensions);
- + if (!$this->resource->getConnection()->isTableExists($temporalIndexTable)) {
- + throw new IndexTableNotExistException(
- + __(
- + "Temporary table for index $index doesn't exist,"
- + . " which is inconsistent with state of scope resolver"
- + )
- + );
- + }
- +
- + $this->state->useRegularIndex();
- + $tableName = $this->resolver->resolve($index, $dimensions);
- + if ($this->resource->getConnection()->isTableExists($tableName)) {
- + $this->resource->getConnection()->dropTable($tableName);
- + }
- +
- + $this->resource->getConnection()->renameTable($temporalIndexTable, $tableName);
- + $this->state->useTemporaryIndex();
- + }
- + }
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexTableNotExistException.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexTableNotExistException.php
- new file mode 100644
- index 00000000000..6974f8c278a
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/IndexTableNotExistException.php
- @@ -0,0 +1,18 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +
- +use Magento\Framework\Exception\LocalizedException;
- +
- +/**
- + * Exception which represents situation where temporary index table should be used somewhere,
- + * but it does not exist in a database
- + */
- +class IndexTableNotExistException extends LocalizedException
- +{
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/ScopeProxy.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/ScopeProxy.php
- new file mode 100644
- index 00000000000..14832af303b
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/ScopeProxy.php
- @@ -0,0 +1,76 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +
- +use Magento\Framework\Search\Request\Dimension;
- +
- +/**
- + * Implementation of IndexScopeResolverInterface which resolves index scope dynamically
- + * depending on current scope state
- + */
- +class ScopeProxy implements \Magento\Framework\Search\Request\IndexScopeResolverInterface
- +{
- + /**
- + * Object Manager instance
- + *
- + * @var \Magento\Framework\ObjectManagerInterface
- + */
- + private $objectManager;
- +
- + /**
- + * @var array
- + */
- + private $states = [];
- +
- + /**
- + * @var State
- + */
- + private $scopeState;
- +
- + /**
- + * Factory constructor
- + *
- + * @param \Magento\Framework\ObjectManagerInterface $objectManager
- + * @param State $scopeState
- + * @param array $states
- + */
- + public function __construct(
- + \Magento\Framework\ObjectManagerInterface $objectManager,
- + State $scopeState,
- + array $states
- + ) {
- + $this->objectManager = $objectManager;
- + $this->scopeState = $scopeState;
- + $this->states = $states;
- + }
- +
- + /**
- + * Creates class instance with specified parameters
- + *
- + * @param string $state
- + * @return \Magento\Framework\Search\Request\IndexScopeResolverInterface
- + * @throws UnknownStateException
- + */
- + private function create($state)
- + {
- + if (!array_key_exists($state, $this->states)) {
- + throw new UnknownStateException(__("Requested resolver for unknown indexer state: $state"));
- + }
- + return $this->objectManager->create($this->states[$state]);
- + }
- +
- + /**
- + * @param string $index
- + * @param Dimension[] $dimensions
- + * @return string
- + */
- + public function resolve($index, array $dimensions)
- + {
- + return $this->create($this->scopeState->getState())->resolve($index, $dimensions);
- + }
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/State.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/State.php
- new file mode 100644
- index 00000000000..2bba29ae8d8
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/State.php
- @@ -0,0 +1,65 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +
- +use Magento\Framework\App\ResourceConnection;
- +use Magento\Framework\App\ScopeResolverInterface;
- +use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
- +use Magento\Framework\Search\Request\Dimension;
- +use Magento\Framework\Search\Request\IndexScopeResolverInterface;
- +
- +/**
- + * This class represents state that defines which table should be used during indexation process
- + *
- + * There are two possible states:
- + * - use_temporary_table
- + * - use_main_table
- + *
- + * The 'use_main_table' state means that default indexer table should be used.
- + *
- + * The 'use_temporary_table' state is an opposite for 'use_main_table'
- + * which means that default indexer table should be left unchanged during indexation
- + * and temporary table should be used instead.
- + *
- + */
- +class State
- +{
- + const USE_TEMPORARY_INDEX = 'use_temporary_table';
- + const USE_REGULAR_INDEX = 'use_main_table';
- +
- + /**
- + * @var string
- + */
- + private $state = self::USE_REGULAR_INDEX;
- +
- + /**
- + * Set the state to use temporary Index
- + * @return void
- + */
- + public function useTemporaryIndex()
- + {
- + $this->state = self::USE_TEMPORARY_INDEX;
- + }
- +
- + /**
- + * Set the state to use regular Index
- + * @return void
- + */
- + public function useRegularIndex()
- + {
- + $this->state = self::USE_REGULAR_INDEX;
- + }
- +
- + /**
- + * @return string
- + */
- + public function getState()
- + {
- + return $this->state;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/TemporaryResolver.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/TemporaryResolver.php
- new file mode 100644
- index 00000000000..51037eb637c
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/TemporaryResolver.php
- @@ -0,0 +1,43 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +
- +use Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver;
- +use Magento\Framework\Search\Request\Dimension;
- +
- +/**
- + * Resolves name of a temporary table for indexation
- + */
- +class TemporaryResolver implements \Magento\Framework\Search\Request\IndexScopeResolverInterface
- +{
- + /**
- + * @var IndexScopeResolver
- + */
- + private $indexScopeResolver;
- +
- + /**
- + * @inheritDoc
- + */
- + public function __construct(IndexScopeResolver $indexScopeResolver)
- + {
- + $this->indexScopeResolver = $indexScopeResolver;
- + }
- +
- + /**
- + * @param string $index
- + * @param Dimension[] $dimensions
- + * @return string
- + */
- + public function resolve($index, array $dimensions)
- + {
- + $tableName = $this->indexScopeResolver->resolve($index, $dimensions);
- + $tableName .= \Magento\Framework\Indexer\Table\StrategyInterface::TMP_SUFFIX;
- +
- + return $tableName;
- + }
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Indexer/Scope/UnknownStateException.php b/vendor/magento/module-catalog-search/Model/Indexer/Scope/UnknownStateException.php
- new file mode 100644
- index 00000000000..04803ef2748
- --- /dev/null
- +++ b/vendor/magento/module-catalog-search/Model/Indexer/Scope/UnknownStateException.php
- @@ -0,0 +1,18 @@
- +<?php
- +/**
- + * Copyright © 2016 Magento. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogSearch\Model\Indexer\Scope;
- +
- +
- +use Magento\Framework\Exception\LocalizedException;
- +
- +/**
- + * Exception for situation where used state which is not defined in configuration
- + */
- +class UnknownStateException extends LocalizedException
- +{
- +
- +}
- diff --git a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/ExclusionStrategy.php b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/ExclusionStrategy.php
- index 03675f27cac..9575f6efe51 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/ExclusionStrategy.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/ExclusionStrategy.php
- @@ -9,27 +9,21 @@ namespace Magento\CatalogSearch\Model\Search\FilterMapper;
- use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver;
- /**
- - * Strategy which processes exclusions from general rules.
- + * Strategy which processes exclusions from general rules
- */
- class ExclusionStrategy implements FilterStrategyInterface
- {
- /**
- - * Resource connection.
- - *
- * @var \Magento\Framework\App\ResourceConnection
- */
- - private $resourceConnection;
- + private $resourceConnection;
- /**
- - * Resolving table alias for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- /**
- - * Store manager interface.
- - *
- * @var \Magento\Store\Model\StoreManagerInterface
- */
- private $storeManager;
- @@ -62,7 +56,9 @@ class ExclusionStrategy implements FilterStrategyInterface
- $alias = $this->aliasResolver->getAlias($filter);
- $tableName = $this->resourceConnection->getTableName('catalog_product_index_price');
- $select->joinInner(
- - [$alias => $tableName],
- + [
- + $alias => $tableName
- + ],
- $this->resourceConnection->getConnection()->quoteInto(
- 'search_index.entity_id = price_index.entity_id AND price_index.website_id = ?',
- $this->storeManager->getWebsite()->getId()
- @@ -74,13 +70,14 @@ class ExclusionStrategy implements FilterStrategyInterface
- $alias = $this->aliasResolver->getAlias($filter);
- $tableName = $this->resourceConnection->getTableName('catalog_category_product_index');
- $select->joinInner(
- - [$alias => $tableName],
- + [
- + $alias => $tableName
- + ],
- 'search_index.entity_id = category_ids_index.product_id',
- []
- );
- $isApplied = true;
- }
- -
- return $isApplied;
- }
- }
- diff --git a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterContext.php b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterContext.php
- index e1901afce4f..d8d3efc65e7 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterContext.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterContext.php
- @@ -6,47 +6,38 @@
- namespace Magento\CatalogSearch\Model\Search\FilterMapper;
- +
- use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver;
- use Magento\Eav\Model\Config as EavConfig;
- use Magento\Eav\Model\Entity\Attribute\AbstractAttribute;
- /**
- - * FilterContext represents a Context of the Strategy pattern.
- - * Its responsibility is to choose appropriate strategy to apply passed filter to the Select.
- + * FilterContext represents a Context of the Strategy pattern
- + * Its responsibility is to choose appropriate strategy to apply passed filter to the Select
- */
- class FilterContext implements FilterStrategyInterface
- {
- /**
- - * Strategy which processes exclusions from general rules.
- - *
- * @var ExclusionStrategy
- */
- private $exclusionStrategy;
- /**
- - * Eav attributes config.
- - *
- * @var EavConfig
- */
- private $eavConfig;
- /**
- - * Strategy for handling dropdown or multi-select attributes.
- - *
- * @var TermDropdownStrategy
- */
- private $termDropdownStrategy;
- /**
- - * Strategy for handling static attributes.
- - *
- * @var StaticAttributeStrategy
- */
- private $staticAttributeStrategy;
- /**
- - * Resolving table alias for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- @@ -83,7 +74,6 @@ class FilterContext implements FilterStrategyInterface
- if (!$isApplied) {
- $attribute = $this->getAttributeByCode($filter->getField());
- -
- if ($attribute) {
- if ($filter->getType() === \Magento\Framework\Search\Request\FilterInterface::TYPE_TERM
- && in_array($attribute->getFrontendInput(), ['select', 'multiselect'], true)
- @@ -99,12 +89,8 @@ class FilterContext implements FilterStrategyInterface
- }
- /**
- - * Returns attribute by attribute_code.
- - *
- * @param string $field
- - *
- * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
- - *
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function getAttributeByCode($field)
- diff --git a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterStrategyInterface.php b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterStrategyInterface.php
- index 0e41e0cd69f..92b06154977 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterStrategyInterface.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/FilterStrategyInterface.php
- @@ -7,16 +7,13 @@
- namespace Magento\CatalogSearch\Model\Search\FilterMapper;
- /**
- - * FilterStrategyInterface provides the interface to work with strategies.
- + * FilterStrategyInterface provides the interface to work with strategies
- */
- interface FilterStrategyInterface
- {
- /**
- - * Applies filter.
- - *
- * @param \Magento\Framework\Search\Request\FilterInterface $filter
- * @param \Magento\Framework\DB\Select $select
- - *
- * @return bool is filter was applied
- */
- public function apply(
- diff --git a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/StaticAttributeStrategy.php b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/StaticAttributeStrategy.php
- index a930219d2e2..bb4a18ce163 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/StaticAttributeStrategy.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/StaticAttributeStrategy.php
- @@ -10,27 +10,21 @@ use Magento\CatalogSearch\Model\Adapter\Mysql\Filter\AliasResolver;
- use Magento\Eav\Model\Config as EavConfig;
- /**
- - * This strategy handles static attributes.
- + * This strategy handles static attributes
- */
- class StaticAttributeStrategy implements FilterStrategyInterface
- {
- /**
- - * Resource connection.
- - *
- * @var \Magento\Framework\App\ResourceConnection
- */
- private $resourceConnection;
- /**
- - * Resolving table alias for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- /**
- - * Eav attributes config.
- - *
- * @var EavConfig
- */
- private $eavConfig;
- @@ -65,17 +59,12 @@ class StaticAttributeStrategy implements FilterStrategyInterface
- . $this->resourceConnection->getConnection()->quoteIdentifier("$alias.entity_id"),
- []
- );
- -
- return true;
- }
- /**
- - * Returns attribute by attribute_code.
- - *
- * @param string $field
- - *
- * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
- - *
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function getAttributeByCode($field)
- diff --git a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/TermDropdownStrategy.php b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/TermDropdownStrategy.php
- index a0f7f706b41..917450044a6 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/FilterMapper/TermDropdownStrategy.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/FilterMapper/TermDropdownStrategy.php
- @@ -23,36 +23,26 @@ use Magento\Store\Model\StoreManagerInterface;
- class TermDropdownStrategy implements FilterStrategyInterface
- {
- /**
- - * Resolving table alias for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- /**
- - * Store manager.
- - *
- * @var StoreManagerInterface
- */
- private $storeManager;
- /**
- - * Eav attributes config.
- - *
- * @var EavConfig
- */
- private $eavConfig;
- /**
- - * Resource connection.
- - *
- * @var ResourceConnection
- */
- private $resourceConnection;
- /**
- - * Scope config.
- - *
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- @@ -63,6 +53,7 @@ class TermDropdownStrategy implements FilterStrategyInterface
- * @param EavConfig $eavConfig
- * @param ScopeConfigInterface $scopeConfig
- * @param AliasResolver $aliasResolver
- + * @SuppressWarnings(Magento.TypeDuplication)
- */
- public function __construct(
- StoreManagerInterface $storeManager,
- @@ -79,13 +70,7 @@ class TermDropdownStrategy implements FilterStrategyInterface
- }
- /**
- - * Applies filter.
- - *
- - * @param \Magento\Framework\Search\Request\FilterInterface $filter
- - * @param \Magento\Framework\DB\Select $select
- - *
- - * @return bool is filter was applied
- - *
- + * {@inheritDoc}
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- public function apply(
- @@ -105,11 +90,12 @@ class TermDropdownStrategy implements FilterStrategyInterface
- $joinCondition,
- []
- );
- -
- if ($this->isAddStockFilter()) {
- $stockAlias = $alias . AliasResolver::STOCK_FILTER_SUFFIX;
- $select->joinLeft(
- - [$stockAlias => $this->resourceConnection->getTableName('cataloginventory_stock_status')],
- + [
- + $stockAlias => $this->resourceConnection->getTableName('cataloginventory_stock_status'),
- + ],
- sprintf('%2$s.product_id = %1$s.source_id', $alias, $stockAlias),
- []
- );
- @@ -119,12 +105,8 @@ class TermDropdownStrategy implements FilterStrategyInterface
- }
- /**
- - * Returns attribute by attribute code.
- - *
- * @param string $field
- - *
- * @return \Magento\Catalog\Model\ResourceModel\Eav\Attribute
- - *
- * @throws \Magento\Framework\Exception\LocalizedException
- */
- private function getAttributeByCode($field)
- @@ -133,8 +115,6 @@ class TermDropdownStrategy implements FilterStrategyInterface
- }
- /**
- - * Check if it is necessary to show out of stock products.
- - *
- * @return bool
- */
- private function isAddStockFilter()
- diff --git a/vendor/magento/module-catalog-search/Model/Search/IndexBuilder.php b/vendor/magento/module-catalog-search/Model/Search/IndexBuilder.php
- index 03129b0d698..05995895ed3 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/IndexBuilder.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/IndexBuilder.php
- @@ -21,7 +21,7 @@ use Magento\CatalogInventory\Model\Stock;
- use Magento\Framework\App\ScopeResolverInterface;
- /**
- - * Build base Query for Index.
- + * Build base Query for Index
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class IndexBuilder implements IndexBuilderInterface
- @@ -148,7 +148,7 @@ class IndexBuilder implements IndexBuilderInterface
- {
- if ($this->stockConfiguration === null) {
- $this->stockConfiguration = \Magento\Framework\App\ObjectManager::getInstance()
- - ->get(\Magento\CatalogInventory\Api\StockConfigurationInterface::class);
- + ->get('Magento\CatalogInventory\Api\StockConfigurationInterface');
- }
- return $this->stockConfiguration;
- }
- diff --git a/vendor/magento/module-catalog-search/Model/Search/TableMapper.php b/vendor/magento/module-catalog-search/Model/Search/TableMapper.php
- index 2b8b79127c9..e96c6a36e20 100644
- --- a/vendor/magento/module-catalog-search/Model/Search/TableMapper.php
- +++ b/vendor/magento/module-catalog-search/Model/Search/TableMapper.php
- @@ -24,7 +24,7 @@ use Magento\Framework\App\ObjectManager;
- /**
- * Responsibility of the TableMapper is to collect all filters from the search query
- * and pass them one by one for processing in the FilterContext,
- - * which will apply them to the Select.
- + * which will apply them to the Select
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @SuppressWarnings(PHPMD.NPathComplexity)
- @@ -32,8 +32,6 @@ use Magento\Framework\App\ObjectManager;
- class TableMapper
- {
- /**
- - * Resource connection.
- - *
- * @var AppResource
- */
- private $resource;
- @@ -44,49 +42,36 @@ class TableMapper
- private $storeManager;
- /**
- - * @deprecated
- - *
- - * @var \Magento\Catalog\Model\ResourceModel\Product\Attribute\Collection
- - */
- - private $attributeCollection;
- -
- - /**
- - * Eav attribute config.
- - *
- * @var EavConfig
- */
- - private $eavConfig;
- + private $eavConfig;
- /**
- - * Scope config.
- - *
- * @var ScopeConfigInterface
- */
- private $scopeConfig;
- /**
- - * FilterStrategyInterface provides the interface to work with strategies.
- - *
- * @var FilterStrategyInterface
- */
- private $filterStrategy;
- /**
- - * Table alias resolver for Search Request filter.
- - *
- * @var AliasResolver
- */
- private $aliasResolver;
- /**
- - * TableMapper constructor.
- * @param AppResource $resource
- * @param StoreManagerInterface $storeManager
- * @param CollectionFactory $attributeCollectionFactory
- - * @param EavConfig|null $eavConfig
- - * @param ScopeConfigInterface|null $scopeConfig
- - * @param FilterStrategyInterface|null $filterStrategy
- - * @param AliasResolver|null $aliasResolver
- + * @param EavConfig $eavConfig
- + * @param ScopeConfigInterface $scopeConfig
- + * @param FilterStrategyInterface $filterStrategy
- + * @param AliasResolver $aliasResolver
- + *
- + * Added for backwards compatibility(can not delete parameter from constructor)
- + * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function __construct(
- AppResource $resource,
- @@ -99,7 +84,6 @@ class TableMapper
- ) {
- $this->resource = $resource;
- $this->storeManager = $storeManager;
- - $this->attributeCollection = $attributeCollectionFactory->create();
- $this->eavConfig = $eavConfig ?: ObjectManager::getInstance()->get(EavConfig::class);
- $this->scopeConfig = $scopeConfig ?: ObjectManager::getInstance()->get(ScopeConfigInterface::class);
- $this->filterStrategy = $filterStrategy ?: ObjectManager::getInstance()->get(FilterStrategyInterface::class);
- @@ -107,21 +91,16 @@ class TableMapper
- }
- /**
- - * Adds tables to select.
- - *
- * @param Select $select
- * @param RequestInterface $request
- - *
- * @return Select
- */
- public function addTables(Select $select, RequestInterface $request)
- {
- $appliedFilters = [];
- $filters = $this->getFiltersFromQuery($request->getQuery());
- -
- foreach ($filters as $filter) {
- $alias = $this->aliasResolver->getAlias($filter);
- -
- if (!array_key_exists($alias, $appliedFilters)) {
- $isApplied = $this->filterStrategy->apply($filter, $select);
- if ($isApplied) {
- @@ -152,7 +131,7 @@ class TableMapper
- * @param RequestQueryInterface $query
- * @return FilterInterface[]
- */
- - private function getFiltersFromQuery(RequestQueryInterface $query)
- + private function getFiltersFromQuery(RequestQueryInterface $query)
- {
- $filters = [];
- switch ($query->getType()) {
- @@ -180,6 +159,7 @@ class TableMapper
- default:
- break;
- }
- +
- return $filters;
- }
- diff --git a/vendor/magento/module-catalog-search/etc/di.xml b/vendor/magento/module-catalog-search/etc/di.xml
- index 25993adf353..dc104cc7816 100644
- --- a/vendor/magento/module-catalog-search/etc/di.xml
- +++ b/vendor/magento/module-catalog-search/etc/di.xml
- @@ -12,6 +12,7 @@
- <preference for="Magento\Framework\Search\Dynamic\DataProviderInterface" type="Magento\CatalogSearch\Model\Adapter\Mysql\Dynamic\DataProvider" />
- <preference for="Magento\Framework\Search\Adapter\OptionsInterface" type="Magento\CatalogSearch\Model\Adapter\Options" />
- <preference for="Magento\CatalogSearch\Model\Search\FilterMapper\FilterStrategyInterface" type="Magento\CatalogSearch\Model\Search\FilterMapper\FilterContext"/>
- + <preference for="\Magento\CatalogSearch\Model\Indexer\IndexSwitcherInterface" type="\Magento\CatalogSearch\Model\Indexer\IndexSwitcherProxy"/>
- <type name="Magento\CatalogSearch\Model\Indexer\IndexerHandlerFactory">
- <arguments>
- <argument name="configPath" xsi:type="const">Magento\CatalogSearch\Model\ResourceModel\EngineInterface::CONFIG_ENGINE_PATH</argument>
- @@ -20,6 +21,14 @@
- </argument>
- </arguments>
- </type>
- + <type name="Magento\CatalogSearch\Model\Indexer\IndexSwitcherProxy">
- + <arguments>
- + <argument name="configPath" xsi:type="const">Magento\CatalogSearch\Model\ResourceModel\EngineInterface::CONFIG_ENGINE_PATH</argument>
- + <argument name="handlers" xsi:type="array">
- + <item name="mysql" xsi:type="string">\Magento\CatalogSearch\Model\Indexer\Scope\IndexSwitcher</item>
- + </argument>
- + </arguments>
- + </type>
- <type name="Magento\CatalogSearch\Model\Indexer\IndexStructureFactory">
- <arguments>
- <argument name="configPath" xsi:type="const">Magento\CatalogSearch\Model\ResourceModel\EngineInterface::CONFIG_ENGINE_PATH</argument>
- @@ -246,4 +255,27 @@
- </argument>
- </arguments>
- </type>
- + <type name="\Magento\CatalogSearch\Model\Indexer\IndexerHandler">
- + <arguments>
- + <argument name="indexScopeResolver" xsi:type="object">\Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy</argument>
- + </arguments>
- + </type>
- + <type name="\Magento\CatalogSearch\Model\Indexer\IndexStructure">
- + <arguments>
- + <argument name="indexScopeResolver" xsi:type="object">\Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy</argument>
- + </arguments>
- + </type>
- + <type name="\Magento\CatalogSearch\Model\Indexer\Scope\IndexSwitcher">
- + <arguments>
- + <argument name="indexScopeResolver" xsi:type="object">\Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy</argument>
- + </arguments>
- + </type>
- + <type name="\Magento\CatalogSearch\Model\Indexer\Scope\ScopeProxy">
- + <arguments>
- + <argument name="states" xsi:type="array">
- + <item name="use_temporary_table" xsi:type="string">\Magento\CatalogSearch\Model\Indexer\Scope\TemporaryResolver</item>
- + <item name="use_main_table" xsi:type="string">\Magento\Framework\Indexer\ScopeResolver\IndexScopeResolver</item>
- + </argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-catalog-widget/Model/Rule/Condition/Product.php b/vendor/magento/module-catalog-widget/Model/Rule/Condition/Product.php
- index 7b4ecf5ffe9..f441135e7bf 100644
- --- a/vendor/magento/module-catalog-widget/Model/Rule/Condition/Product.php
- +++ b/vendor/magento/module-catalog-widget/Model/Rule/Condition/Product.php
- @@ -12,6 +12,7 @@ namespace Magento\CatalogWidget\Model\Rule\Condition;
- /**
- * Class Product
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- class Product extends \Magento\Rule\Model\Condition\Product\AbstractProduct
- {
- diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Indexer/Stock/Configurable.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Indexer/Stock/Configurable.php
- index ada5d90b938..0b8eaead585 100644
- --- a/vendor/magento/module-configurable-product/Model/ResourceModel/Indexer/Stock/Configurable.php
- +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Indexer/Stock/Configurable.php
- @@ -13,9 +13,44 @@ namespace Magento\ConfigurableProduct\Model\ResourceModel\Indexer\Stock;
- * @author Magento Core Team <core@magentocommerce.com>
- */
- use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
- +use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
- +use Magento\Framework\App\ObjectManager;
- +/**
- + * Stock indexer for configurable product.
- + *
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- + */
- 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
- *
- @@ -27,7 +62,10 @@ class Configurable extends \Magento\CatalogInventory\Model\ResourceModel\Indexer
- {
- $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
- $connection = $this->getConnection();
- - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
- + $table = $this->getActionType() === Full::ACTION_TYPE
- + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable())
- + : $this->getMainTable();
- + $idxTable = $usePrimaryTable ? $table : $this->getIdxTable();
- $select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable);
- $select->reset(
- \Magento\Framework\DB\Select::COLUMNS
- diff --git a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php
- index 7f4f0f9e937..75cc5a8c958 100644
- --- a/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php
- +++ b/vendor/magento/module-configurable-product/Model/ResourceModel/Product/Indexer/Price/Configurable.php
- @@ -28,7 +28,7 @@ class Configurable extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\
- * @param \Magento\Eav\Model\Config $eavConfig
- * @param \Magento\Framework\Event\ManagerInterface $eventManager
- * @param \Magento\Framework\Module\Manager $moduleManager
- - * @param string $connectionName
- + * @param string|null $connectionName
- * @param StoreResolverInterface $storeResolver
- */
- public function __construct(
- @@ -41,8 +41,9 @@ class Configurable extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\
- StoreResolverInterface $storeResolver = null
- ) {
- parent::__construct($context, $tableStrategy, $eavConfig, $eventManager, $moduleManager, $connectionName);
- - $this->storeResolver = $storeResolver ?:
- - \Magento\Framework\App\ObjectManager::getInstance()->get(StoreResolverInterface::class);
- + $this->storeResolver = $storeResolver ?: \Magento\Framework\App\ObjectManager::getInstance()->get(
- + StoreResolverInterface::class
- + );
- }
- /**
- @@ -50,18 +51,11 @@ class Configurable extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\
- *
- * @return $this
- * @throws \Exception
- + * @deprecated
- */
- public function reindexAll()
- {
- - $this->tableStrategy->setUseIdxTable(true);
- - $this->beginTransaction();
- - try {
- - $this->reindex();
- - $this->commit();
- - } catch (\Exception $e) {
- - $this->rollBack();
- - throw $e;
- - }
- + parent::reindexAll();
- return $this;
- }
- @@ -70,10 +64,11 @@ class Configurable extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\
- *
- * @param int|array $entityIds
- * @return \Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable
- + * @deprecated
- */
- public function reindexEntity($entityIds)
- {
- - $this->reindex($entityIds);
- + parent::reindexEntity($entityIds);
- return $this;
- }
- diff --git a/vendor/magento/module-configurable-product/etc/di.xml b/vendor/magento/module-configurable-product/etc/di.xml
- index 66d6073f75d..92c9f6762d0 100644
- --- a/vendor/magento/module-configurable-product/etc/di.xml
- +++ b/vendor/magento/module-configurable-product/etc/di.xml
- @@ -168,4 +168,17 @@
- </argument>
- </arguments>
- </type>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
- + <arguments>
- + <argument name="estimators" xsi:type="array">
- + <item name="configurable" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
- + </argument>
- + </arguments>
- + </type>
- + <type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-downloadable/Model/ResourceModel/Indexer/Price.php b/vendor/magento/module-downloadable/Model/ResourceModel/Indexer/Price.php
- index 843e690e342..2df2382931e 100644
- --- a/vendor/magento/module-downloadable/Model/ResourceModel/Indexer/Price.php
- +++ b/vendor/magento/module-downloadable/Model/ResourceModel/Indexer/Price.php
- @@ -19,18 +19,11 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D
- *
- * @throws \Exception
- * @return $this
- + * @deprecated
- */
- public function reindexAll()
- {
- - $this->tableStrategy->setUseIdxTable(true);
- - $this->beginTransaction();
- - try {
- - $this->reindex();
- - $this->commit();
- - } catch (\Exception $e) {
- - $this->rollBack();
- - throw $e;
- - }
- + parent::reindexAll();
- return $this;
- }
- @@ -39,10 +32,12 @@ class Price extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\D
- *
- * @param int|array $entityIds
- * @return $this
- + * @deprecated
- */
- public function reindexEntity($entityIds)
- {
- - return $this->reindex($entityIds);
- + parent::reindexEntity($entityIds);
- + return $this;
- }
- /**
- diff --git a/vendor/magento/module-downloadable/etc/di.xml b/vendor/magento/module-downloadable/etc/di.xml
- index 84b6de602ac..d399806bfba 100644
- --- a/vendor/magento/module-downloadable/etc/di.xml
- +++ b/vendor/magento/module-downloadable/etc/di.xml
- @@ -123,4 +123,10 @@
- </argument>
- </arguments>
- </type>
- + <type name="Magento\Downloadable\Model\ResourceModel\Indexer\Price">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-grouped-product/Model/ResourceModel/Indexer/Stock/Grouped.php b/vendor/magento/module-grouped-product/Model/ResourceModel/Indexer/Stock/Grouped.php
- index 740dec1aa27..c17597ab252 100644
- --- a/vendor/magento/module-grouped-product/Model/ResourceModel/Indexer/Stock/Grouped.php
- +++ b/vendor/magento/module-grouped-product/Model/ResourceModel/Indexer/Stock/Grouped.php
- @@ -12,9 +12,44 @@
- namespace Magento\GroupedProduct\Model\ResourceModel\Indexer\Stock;
- use Magento\Catalog\Model\Product\Attribute\Source\Status as ProductStatus;
- +use Magento\Framework\App\ObjectManager;
- +use Magento\CatalogInventory\Model\Indexer\Stock\Action\Full;
- +/**
- + * Stock indexer for grouped product.
- + *
- + * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- + */
- 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
- *
- @@ -25,7 +60,10 @@ class Grouped extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stoc
- protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
- {
- $connection = $this->getConnection();
- - $idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
- + $table = $this->getActionType() === Full::ACTION_TYPE
- + ? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable())
- + : $this->getMainTable();
- + $idxTable = $usePrimaryTable ? $table : $this->getIdxTable();
- $metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
- $select = parent::_getStockStatusSelect($entityIds, $usePrimaryTable);
- $select->reset(
- diff --git a/vendor/magento/module-grouped-product/Model/ResourceModel/Product/Indexer/Price/Grouped.php b/vendor/magento/module-grouped-product/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- index eaed75a967c..55882b40b47 100644
- --- a/vendor/magento/module-grouped-product/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- +++ b/vendor/magento/module-grouped-product/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- @@ -12,23 +12,21 @@ use Magento\Catalog\Api\Data\ProductInterface;
- class Grouped extends DefaultPrice implements GroupedInterface
- {
- + /**
- + * Prefix for temporary table support.
- + */
- + const TRANSIT_PREFIX = 'transit_';
- +
- /**
- * Reindex temporary (price result data) for all products
- *
- * @throws \Exception
- * @return \Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped
- + * @deprecated
- */
- public function reindexAll()
- {
- - $this->tableStrategy->setUseIdxTable(true);
- - $this->beginTransaction();
- - try {
- - $this->_prepareGroupedProductPriceData();
- - $this->commit();
- - } catch (\Exception $e) {
- - $this->rollBack();
- - throw $e;
- - }
- + parent::reindexAll();
- return $this;
- }
- @@ -37,26 +35,72 @@ class Grouped extends DefaultPrice implements GroupedInterface
- *
- * @param int|array $entityIds
- * @return \Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped
- + * @deprecated
- */
- public function reindexEntity($entityIds)
- {
- - $this->_prepareGroupedProductPriceData($entityIds);
- -
- + parent::reindexEntity($entityIds);
- return $this;
- }
- + /**
- + * @inheritdoc
- + */
- + protected function reindex($entityIds = null)
- + {
- + $this->_prepareGroupedProductPriceData($entityIds);
- + }
- +
- /**
- * Calculate minimal and maximal prices for Grouped products
- * Use calculated price for relation products
- *
- * @param int|array $entityIds the parent entity ids limitation
- - * @return \Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped
- + * @return $this
- */
- protected function _prepareGroupedProductPriceData($entityIds = null)
- {
- if (!$this->hasEntity() && empty($entityIds)) {
- return $this;
- }
- +
- + $connection = $this->getConnection();
- + $table = $this->getIdxTable();
- +
- + if (!$this->tableStrategy->getUseIdxTable()) {
- + $additionalIdxTable = $connection->getTableName(self::TRANSIT_PREFIX . $this->getIdxTable());
- + $connection->createTemporaryTableLike($additionalIdxTable, $table);
- + $query = $connection->insertFromSelect(
- + $this->_prepareGroupedProductPriceDataSelect($entityIds),
- + $additionalIdxTable,
- + []
- + );
- + $connection->query($query);
- +
- + $select = $connection->select()->from($additionalIdxTable);
- + $query = $connection->insertFromSelect(
- + $select,
- + $table,
- + [],
- + \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_ON_DUPLICATE
- + );
- + $connection->query($query);
- + $connection->dropTemporaryTable($additionalIdxTable);
- + } else {
- + $query = $this->_prepareGroupedProductPriceDataSelect($entityIds)->insertFromSelect($table);
- + $connection->query($query);
- + }
- + return $this;
- + }
- +
- + /**
- + * Prepare data index select for Grouped products prices
- + *
- + * @param int|array $entityIds the parent entity ids limitation
- + * @return \Magento\Framework\DB\Select
- + */
- + protected function _prepareGroupedProductPriceDataSelect($entityIds = null)
- + {
- $connection = $this->getConnection();
- $table = $this->getIdxTable();
- $linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
- @@ -123,10 +167,6 @@ class Grouped extends DefaultPrice implements GroupedInterface
- 'store_field' => new \Zend_Db_Expr('cs.store_id')
- ]
- );
- -
- - $query = $select->insertFromSelect($table);
- - $connection->query($query);
- -
- - return $this;
- + return $select;
- }
- }
- diff --git a/vendor/magento/module-grouped-product/etc/di.xml b/vendor/magento/module-grouped-product/etc/di.xml
- index 788052d07fc..17c9a644b7b 100644
- --- a/vendor/magento/module-grouped-product/etc/di.xml
- +++ b/vendor/magento/module-grouped-product/etc/di.xml
- @@ -89,4 +89,11 @@
- </type>
- <preference for="Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\GroupedInterface"
- type="Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped"/>
- + <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\BatchSizeCalculator">
- + <arguments>
- + <argument name="estimators" xsi:type="array">
- + <item name="grouped" xsi:type="object">Magento\Catalog\Model\Indexer\Price\CompositeProductBatchSizeManagement</item>
- + </argument>
- + </arguments>
- + </type>
- </config>
- diff --git a/vendor/magento/module-indexer/Model/Indexer.php b/vendor/magento/module-indexer/Model/Indexer.php
- index feea37a2636..e799ab04a71 100644
- --- a/vendor/magento/module-indexer/Model/Indexer.php
- +++ b/vendor/magento/module-indexer/Model/Indexer.php
- @@ -59,6 +59,7 @@ class Indexer extends \Magento\Framework\DataObject implements IdxInterface
- protected $indexersFactory;
- /**
- + * Indexer constructor.
- * @param ConfigInterface $config
- * @param ActionFactory $actionFactory
- * @param StructureFactory $structureFactory
- @@ -413,7 +414,7 @@ class Indexer extends \Magento\Framework\DataObject implements IdxInterface
- $state->setStatus(StateInterface::STATUS_VALID);
- $state->save();
- $this->getView()->resume();
- - } catch (\Exception $exception) {
- + } catch (\Throwable $exception) {
- $state->setStatus(StateInterface::STATUS_INVALID);
- $state->save();
- $this->getView()->resume();
- @@ -436,7 +437,7 @@ class Indexer extends \Magento\Framework\DataObject implements IdxInterface
- /**
- * Regenerate rows in index by ID list
- - *5
- + *
- * @param int[] $ids
- * @return void
- */
- diff --git a/vendor/magento/module-indexer/etc/di.xml b/vendor/magento/module-indexer/etc/di.xml
- index 1d3f125406f..7cb8971dfda 100644
- --- a/vendor/magento/module-indexer/etc/di.xml
- +++ b/vendor/magento/module-indexer/etc/di.xml
- @@ -55,4 +55,5 @@
- </argument>
- </arguments>
- </type>
- + <preference for="Magento\Framework\Indexer\BatchSizeManagementInterface" type="Magento\Framework\Indexer\BatchSizeManagement" />
- </config>
- diff --git a/vendor/magento/module-indexer/etc/module.xml b/vendor/magento/module-indexer/etc/module.xml
- index a2beac15990..27c6a47d56a 100644
- --- a/vendor/magento/module-indexer/etc/module.xml
- +++ b/vendor/magento/module-indexer/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_Indexer" setup_version="2.0.0">
- + <module name="Magento_Indexer" setup_version="2.0.1.1.2">
- <sequence>
- <module name="Magento_Store"/>
- <module name="Magento_AdminNotification"/>
- diff --git a/vendor/magento/framework/Indexer/BatchProvider.php b/vendor/magento/framework/Indexer/BatchProvider.php
- new file mode 100644
- index 00000000000..9f8a1b1ace4
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/BatchProvider.php
- @@ -0,0 +1,64 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\Framework\Indexer;
- +
- +use \Magento\Framework\DB\Adapter\AdapterInterface;
- +
- +/**
- + * Generator of consecutive entity ID ranges that must be handled as a batch.
- + *
- + * Some ranges may contain non existent entity IDs.
- + * So the code that uses the generator must check if any entities were loaded during batch load.
- + */
- +class BatchProvider implements BatchProviderInterface
- +{
- + /**
- + * @inheritdoc
- + */
- + public function getBatches(AdapterInterface $adapter, $tableName, $linkField, $batchSize)
- + {
- + $maxLinkFieldValue = $adapter->fetchOne(
- + $adapter->select()->from(
- + ['entity' => $tableName],
- + [
- + 'max_value' => new \Zend_Db_Expr('MAX(entity.' . $linkField . ')')
- + ]
- + )
- + );
- +
- + /** @var int $truncatedBatchSize size of the last batch that is smaller than expected batch size */
- + $truncatedBatchSize = $maxLinkFieldValue % $batchSize;
- + /** @var int $fullBatchCount count of the batches that have expected batch size */
- + $fullBatchCount = ($maxLinkFieldValue - $truncatedBatchSize) / $batchSize;
- +
- + for ($batchIndex = 0; $batchIndex < $fullBatchCount; $batchIndex ++) {
- + yield ['from' => $batchIndex * $batchSize + 1, 'to' => ($batchIndex + 1) * $batchSize];
- + }
- + // return the last batch if it has smaller size
- + if ($truncatedBatchSize > 0) {
- + yield ['from' => $fullBatchCount * $batchSize + 1, 'to' => $maxLinkFieldValue];
- + }
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function getBatchIds(
- + \Magento\Framework\DB\Adapter\AdapterInterface $connection,
- + \Magento\Framework\DB\Select $select,
- + array $batch
- + ) {
- + $betweenCondition = sprintf(
- + '(%s BETWEEN %s AND %s)',
- + 'entity_id',
- + $connection->quote($batch['from']),
- + $connection->quote($batch['to'])
- + );
- +
- + $ids = $connection->fetchCol($select->where($betweenCondition));
- + return array_map('intval', $ids);
- + }
- +}
- diff --git a/vendor/magento/framework/Indexer/BatchProviderInterface.php b/vendor/magento/framework/Indexer/BatchProviderInterface.php
- new file mode 100644
- index 00000000000..09972f48bfd
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/BatchProviderInterface.php
- @@ -0,0 +1,39 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\Framework\Indexer;
- +
- +use Magento\Framework\DB\Adapter\AdapterInterface;
- +use Magento\Framework\DB\Select;
- +
- +/**
- + * Generator of consecutive entity ID ranges that must be handled as a batch.
- + *
- + * Can be used during indexation process to split large amount of data into batches
- + * and process them one by one in order to reduce memory consumption and improve overall performance.
- + */
- +interface BatchProviderInterface
- +{
- + /**
- + * Retrieve batches (entity ID ranges) from the given table.
- + *
- + * @param AdapterInterface $adapter database adapter.
- + * @param string $tableName target table name.
- + * @param string $linkField field that is used as a record identifier.
- + * @param int $batchSize size of the single range.
- + * @return \Generator generator that produces entity ID ranges in the format of ['from' => ..., 'to' => ...]
- + */
- + public function getBatches(AdapterInterface $adapter, $tableName, $linkField, $batchSize);
- +
- + /**
- + * Get list of entity ids based on batch
- + *
- + * @param AdapterInterface $connection
- + * @param Select $select
- + * @param array $batch
- + * @return array
- + */
- + public function getBatchIds(AdapterInterface $connection, Select $select, array $batch);
- +}
- diff --git a/vendor/magento/framework/Indexer/BatchSizeManagement.php b/vendor/magento/framework/Indexer/BatchSizeManagement.php
- new file mode 100644
- index 00000000000..2733aae4bd5
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/BatchSizeManagement.php
- @@ -0,0 +1,65 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Framework\Indexer;
- +
- +/**
- + * Class set MEMORY table size for indexer processes according batch size and index row size.
- + */
- +class BatchSizeManagement implements \Magento\Framework\Indexer\BatchSizeManagementInterface
- +{
- + /**
- + * @var \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface
- + */
- + private $rowSizeEstimator;
- +
- + /**
- + * @var \Psr\Log\LoggerInterface
- + */
- + private $logger;
- +
- + /**
- + * CompositeProductBatchSizeCalculator constructor.
- + * @param \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface $rowSizeEstimator
- + * @param \Psr\Log\LoggerInterface $logger
- + */
- + public function __construct(
- + \Magento\Framework\Indexer\IndexTableRowSizeEstimatorInterface $rowSizeEstimator,
- + \Psr\Log\LoggerInterface $logger
- + ) {
- + $this->rowSizeEstimator = $rowSizeEstimator;
- + $this->logger = $logger;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function ensureBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $connection, $batchSize)
- + {
- + $rowMemory = $this->rowSizeEstimator->estimateRowSize();
- +
- + $maxHeapTableSize = $connection->fetchOne('SELECT @@max_heap_table_size;');
- + $tmpTableSize = $connection->fetchOne('SELECT @@tmp_table_size;');
- + $bufferPoolSize = $connection->fetchOne('SELECT @@innodb_buffer_pool_size;');
- + $maxMemoryTableSize = min($maxHeapTableSize, $tmpTableSize);
- +
- + $size = (int) ($rowMemory * $batchSize);
- +
- + // Log warning if allocated memory for temp table greater than 20% of innodb_buffer_pool_size
- + if ($size > $bufferPoolSize * .2) {
- + $message = 'Memory size allocated for the temporary table is more than 20% of innodb_buffer_pool_size. ' .
- + 'Please update innodb_buffer_pool_size or decrease batch size value '.
- + '(which decreases memory usages for the temporary table). ' .
- + 'Current batch size: %1; Allocated memory size: %2 bytes; InnoDB buffer pool size: %3 bytes.';
- + $this->logger->warning(new \Magento\Framework\Phrase($message, [$batchSize, $size, $bufferPoolSize]));
- + }
- +
- + if ($maxMemoryTableSize < $size) {
- + $connection->query('SET SESSION tmp_table_size = ' . $size . ';');
- + $connection->query('SET SESSION max_heap_table_size = ' . $size . ';');
- + }
- + }
- +}
- diff --git a/vendor/magento/framework/Indexer/BatchSizeManagementInterface.php b/vendor/magento/framework/Indexer/BatchSizeManagementInterface.php
- new file mode 100644
- index 00000000000..ac5b5dae291
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/BatchSizeManagementInterface.php
- @@ -0,0 +1,24 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +namespace Magento\Framework\Indexer;
- +
- +use \Magento\Framework\DB\Adapter\AdapterInterface;
- +
- +/**
- + * Batch size manager can be used to ensure that MEMORY table has enough memory for data in batch.
- + * @api
- + */
- +interface BatchSizeManagementInterface
- +{
- + /**
- + * Ensure memory size for data in batch.
- + *
- + * @param AdapterInterface $adapter database adapter.
- + * @param int $batchSize
- + * @return void
- + */
- + public function ensureBatchSize(\Magento\Framework\DB\Adapter\AdapterInterface $adapter, $batchSize);
- +}
- diff --git a/vendor/magento/framework/Indexer/IndexTableRowSizeEstimator.php b/vendor/magento/framework/Indexer/IndexTableRowSizeEstimator.php
- new file mode 100644
- index 00000000000..d26c85a6d02
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/IndexTableRowSizeEstimator.php
- @@ -0,0 +1,34 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Framework\Indexer;
- +
- +/**
- + * Generic implementation for row size estimation.
- + */
- +class IndexTableRowSizeEstimator implements IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * @var int
- + */
- + private $rowMemorySize;
- +
- + /**
- + * @param int $rowMemorySize
- + */
- + public function __construct($rowMemorySize)
- + {
- + $this->rowMemorySize = $rowMemorySize;
- + }
- +
- + /**
- + * @inheritdoc
- + */
- + public function estimateRowSize()
- + {
- + return $this->rowMemorySize;
- + }
- +}
- diff --git a/vendor/magento/framework/Indexer/IndexTableRowSizeEstimatorInterface.php b/vendor/magento/framework/Indexer/IndexTableRowSizeEstimatorInterface.php
- new file mode 100644
- index 00000000000..c2c25ef4969
- --- /dev/null
- +++ b/vendor/magento/framework/Indexer/IndexTableRowSizeEstimatorInterface.php
- @@ -0,0 +1,21 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\Framework\Indexer;
- +
- +/**
- + * Calculate memory size for entity according different dimensions.
- + * @api
- + */
- +interface IndexTableRowSizeEstimatorInterface
- +{
- + /**
- + * Calculate memory size for entity row.
- + *
- + * @return float
- + */
- + public function estimateRowSize();
- +}
- diff --git a/vendor/magento/framework/Indexer/ScopeResolver/IndexScopeResolver.php b/vendor/magento/framework/Indexer/ScopeResolver/IndexScopeResolver.php
- index 20365b399fc..77f2c7a1b64 100644
- --- a/vendor/magento/framework/Indexer/ScopeResolver/IndexScopeResolver.php
- +++ b/vendor/magento/framework/Indexer/ScopeResolver/IndexScopeResolver.php
- @@ -52,6 +52,7 @@ class IndexScopeResolver implements IndexScopeResolverInterface
- $tableNameParts[] = $dimension->getName() . $dimension->getValue();
- }
- }
- +
- return $this->resource->getTableName(implode('_', $tableNameParts));
- }
- @@ -63,10 +64,12 @@ class IndexScopeResolver implements IndexScopeResolverInterface
- */
- private function getScopeId($dimension)
- {
- - if (is_numeric($dimension->getValue())) {
- - return $dimension->getValue();
- - } else {
- - return $this->scopeResolver->getScope($dimension->getValue())->getId();
- + $scopeId = $dimension->getValue();
- +
- + if (!is_numeric($scopeId)) {
- + $scopeId = $this->scopeResolver->getScope($scopeId)->getId();
- }
- +
- + return $scopeId;
- }
- }
- diff --git a/vendor/magento/framework/Search/Adapter/Mysql/Adapter.php b/vendor/magento/framework/Search/Adapter/Mysql/Adapter.php
- index b348d5a454b..d89b7eaa13d 100644
- --- a/vendor/magento/framework/Search/Adapter/Mysql/Adapter.php
- +++ b/vendor/magento/framework/Search/Adapter/Mysql/Adapter.php
- @@ -70,12 +70,7 @@ class Adapter implements AdapterInterface
- }
- /**
- - * Process Search Request.
- - *
- - * @param RequestInterface $request
- - *
- - * @return \Magento\Framework\Search\Response\QueryResponse
- - *
- + * {@inheritdoc}
- * @throws \LogicException
- */
- public function query(RequestInterface $request)
- diff --git a/vendor/magento/framework/Search/Adapter/Mysql/Aggregation/Builder/Metrics.php b/vendor/magento/framework/Search/Adapter/Mysql/Aggregation/Builder/Metrics.php
- index 239bb22ee77..864dfc45b2c 100644
- --- a/vendor/magento/framework/Search/Adapter/Mysql/Aggregation/Builder/Metrics.php
- +++ b/vendor/magento/framework/Search/Adapter/Mysql/Aggregation/Builder/Metrics.php
- @@ -10,14 +10,14 @@ use Magento\Framework\Search\Request\BucketInterface as RequestBucketInterface;
- class Metrics
- {
- /**
- - * Available metrics.
- + * Available metrics
- *
- * @var string[]
- */
- private $allowedMetrics = ['count', 'sum', 'min', 'max', 'avg'];
- /**
- - * Build metrics for Select->columns.
- + * Build metrics for Select->columns
- *
- * @param RequestBucketInterface $bucket
- * @return string[]
- diff --git a/vendor/magento/module-advanced-catalog/Model/Indexer/Table/Strategy.php b/vendor/magento/module-advanced-catalog/Model/Indexer/Table/Strategy.php
- index 0da6535c26e..3c25541c924 100644
- --- a/vendor/magento/module-advanced-catalog/Model/Indexer/Table/Strategy.php
- +++ b/vendor/magento/module-advanced-catalog/Model/Indexer/Table/Strategy.php
- @@ -5,15 +5,39 @@
- */
- namespace Magento\AdvancedCatalog\Model\Indexer\Table;
- +use Magento\Framework\App\ObjectManager;
- +
- /**
- * Class Strategy
- *
- * @author Magento Core Team <core@magentocommerce.com>
- + * @deprecated logic moved to catalog module
- + * @see \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy
- */
- class Strategy extends \Magento\Framework\Indexer\Table\Strategy
- {
- const TEMP_SUFFIX = '_temp';
- + /**
- + * @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy
- + */
- + private $tableStrategy;
- +
- + /**
- + * Strategy constructor.
- + * @param \Magento\Framework\App\ResourceConnection $resource
- + * @param \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy|null $tableStrategy
- + */
- + public function __construct(
- + \Magento\Framework\App\ResourceConnection $resource,
- + \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy $tableStrategy = null
- + ) {
- + parent::__construct($resource);
- + $this->tableStrategy = $tableStrategy ?: ObjectManager::getInstance()->get(
- + \Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy::class
- + );
- + }
- +
- /**
- * Prepare index table name
- *
- @@ -23,15 +47,6 @@ class Strategy extends \Magento\Framework\Indexer\Table\Strategy
- */
- public function prepareTableName($tablePrefix)
- {
- - if ($this->getUseIdxTable()) {
- - return $tablePrefix . self::IDX_SUFFIX;
- - } else {
- - $this->resource->getConnection('indexer')->createTemporaryTableLike(
- - $this->resource->getTableName($tablePrefix . self::TEMP_SUFFIX),
- - $this->resource->getTableName($tablePrefix . self::TMP_SUFFIX),
- - true
- - );
- - return $tablePrefix . self::TEMP_SUFFIX;
- - }
- + return $this->tableStrategy->prepareTableName($tablePrefix);
- }
- }
- diff --git a/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php b/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- index 478b195cef7..f4dee8e8b95 100644
- --- a/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- +++ b/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Eav/Source.php
- @@ -8,53 +8,21 @@ namespace Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Eav;
- /**
- * Catalog Product Eav Select and Multiply Select Attributes Indexer resource model
- *
- - * @author Magento Core Team <core@magentocommerce.com>
- + * @deprecated Logic moved to parent class implementation
- + * @see \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source
- */
- class Source extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source
- {
- - const TRANSIT_PREFIX = 'transit_';
- -
- /**
- * Prepare data index for product relations
- *
- * @param array $parentIds the parent entity ids limitation
- * @return $this
- + * @deprecated
- */
- protected function _prepareRelationIndex($parentIds = null)
- {
- - $connection = $this->getConnection();
- - $idxTable = $this->getIdxTable();
- -
- - if (!$this->tableStrategy->getUseIdxTable()) {
- - $additionalIdxTable = $connection->getTableName(self::TRANSIT_PREFIX . $this->getIdxTable());
- - $connection->createTemporaryTableLike($additionalIdxTable, $idxTable);
- -
- - $query = $connection->insertFromSelect(
- - $this->_prepareRelationIndexSelect($parentIds),
- - $additionalIdxTable,
- - []
- - );
- - $connection->query($query);
- -
- - $select = $connection->select()->from($additionalIdxTable);
- - $query = $connection->insertFromSelect(
- - $select,
- - $idxTable,
- - [],
- - \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
- - );
- - $connection->query($query);
- -
- - $connection->dropTemporaryTable($additionalIdxTable);
- - } else {
- - $query = $connection->insertFromSelect(
- - $this->_prepareRelationIndexSelect($parentIds),
- - $idxTable,
- - [],
- - \Magento\Framework\DB\Adapter\AdapterInterface::INSERT_IGNORE
- - );
- - $connection->query($query);
- - }
- + parent::_prepareRelationIndex($parentIds);
- return $this;
- }
- }
- diff --git a/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Price/Grouped.php b/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- index 5f71b385826..f9b564a2876 100644
- --- a/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- +++ b/vendor/magento/module-advanced-catalog/Model/ResourceModel/Product/Indexer/Price/Grouped.php
- @@ -9,44 +9,15 @@ namespace Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Price;
- use Magento\Catalog\Api\Data\ProductInterface;
- +/**
- + * @deprecated logic moved to default price indexer.
- + * @see \Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped
- + */
- class Grouped extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice
- {
- const TRANSIT_PREFIX = 'transit_';
- const LINK_TYPE_GROUPED = 3;
- - /**
- - * Reindex temporary (price result data) for all products
- - *
- - * @throws \Exception
- - * @return $this
- - */
- - public function reindexAll()
- - {
- - $this->tableStrategy->setUseIdxTable(true);
- - $this->beginTransaction();
- - try {
- - $this->_prepareGroupedProductPriceData();
- - $this->commit();
- - } catch (\Exception $e) {
- - $this->rollBack();
- - throw $e;
- - }
- - return $this;
- - }
- -
- - /**
- - * Reindex temporary (price result data) for defined product(s)
- - *
- - * @param int|array $entityIds
- - * @return $this
- - */
- - public function reindexEntity($entityIds)
- - {
- - $this->_prepareGroupedProductPriceData($entityIds);
- -
- - return $this;
- - }
- -
- /**
- * Calculate minimal and maximal prices for Grouped products
- * Use calculated price for relation products
- @@ -165,4 +136,12 @@ class Grouped extends \Magento\Catalog\Model\ResourceModel\Product\Indexer\Price
- );
- return $select;
- }
- +
- + /**
- + * @inheritdoc
- + */
- + protected function reindex($entityIds = null)
- + {
- + $this->_prepareGroupedProductPriceData($entityIds);
- + }
- }
- diff --git a/vendor/magento/module-advanced-catalog/etc/di.xml b/vendor/magento/module-advanced-catalog/etc/di.xml
- index 5a8f894d3e5..7aef529f80c 100644
- --- a/vendor/magento/module-advanced-catalog/etc/di.xml
- +++ b/vendor/magento/module-advanced-catalog/etc/di.xml
- @@ -7,48 +7,4 @@
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
- <type name="Magento\AdvancedCatalog\Model\Indexer\Table\Strategy" shared="false" />
- - <preference for="Magento\Catalog\Model\ResourceModel\Product\Indexer\Eav\Source" type="Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Eav\Source" />
- - <type name="Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Eav\Source">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <type name="Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <preference for="Magento\GroupedProduct\Model\ResourceModel\Product\Indexer\Price\Grouped" type="Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Price\Grouped" />
- - <type name="Magento\AdvancedCatalog\Model\ResourceModel\Product\Indexer\Price\Grouped">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <type name="Magento\Bundle\Model\ResourceModel\Indexer\Price">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <type name="Magento\ConfigurableProduct\Model\ResourceModel\Product\Indexer\Price\Configurable">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <type name="Magento\Downloadable\Model\ResourceModel\Indexer\Price">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- - <type name="Magento\GiftCard\Model\ResourceModel\Indexer\Price">
- - <arguments>
- - <argument name="tableStrategy" xsi:type="object">Magento\AdvancedCatalog\Model\Indexer\Table\Strategy</argument>
- - <argument name="connectionName" xsi:type="string">indexer</argument>
- - </arguments>
- - </type>
- </config>
- diff --git a/vendor/magento/module-advanced-search/Model/ResourceModel/Index.php b/vendor/magento/module-advanced-search/Model/ResourceModel/Index.php
- index 8f7804fba62..6eb9f34d8c7 100644
- --- a/vendor/magento/module-advanced-search/Model/ResourceModel/Index.php
- +++ b/vendor/magento/module-advanced-search/Model/ResourceModel/Index.php
- @@ -36,9 +36,9 @@ class Index extends AbstractDb
- MetadataPool $metadataPool,
- $connectionName = null
- ) {
- + parent::__construct($context, $connectionName);
- $this->storeManager = $storeManager;
- $this->metadataPool = $metadataPool;
- - parent::__construct($context, $connectionName);
- }
- /**
- diff --git a/vendor/magento/module-catalog-rule-staging/Setup/UpgradeSchema.php b/vendor/magento/module-catalog-rule-staging/Setup/UpgradeSchema.php
- new file mode 100644
- index 00000000000..768f22beb3b
- --- /dev/null
- +++ b/vendor/magento/module-catalog-rule-staging/Setup/UpgradeSchema.php
- @@ -0,0 +1,36 @@
- +<?php
- +/**
- + * Copyright © Magento, Inc. All rights reserved.
- + * See COPYING.txt for license details.
- + */
- +
- +namespace Magento\CatalogRuleStaging\Setup;
- +
- +use Magento\Framework\Setup\UpgradeSchemaInterface;
- +use Magento\Framework\Setup\ModuleContextInterface;
- +use Magento\Framework\Setup\SchemaSetupInterface;
- +
- +class UpgradeSchema implements UpgradeSchemaInterface
- +{
- + /**
- + * {@inheritdoc}
- + */
- + public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
- + {
- + $setup->startSetup();
- +
- + if (version_compare($context->getVersion(), '2.0.0.1.2', '<')) {
- + $connection = $setup->getConnection();
- + $connection->dropForeignKey(
- + $setup->getTable('catalogrule_group_website'),
- + $setup->getFkName(
- + 'catalogrule_group_website',
- + 'rule_id',
- + 'sequence_catalogrule',
- + 'sequence_value'
- + )
- + );
- + }
- + $setup->endSetup();
- + }
- +}
- diff --git a/vendor/magento/module-catalog-rule-staging/etc/module.xml b/vendor/magento/module-catalog-rule-staging/etc/module.xml
- index d357a65a2ff..547e0a9659c 100644
- --- a/vendor/magento/module-catalog-rule-staging/etc/module.xml
- +++ b/vendor/magento/module-catalog-rule-staging/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_CatalogRuleStaging" setup_version="2.0.0">
- + <module name="Magento_CatalogRuleStaging" setup_version="2.0.0.1.2">
- <sequence>
- <module name="Magento_Staging"/>
- <module name="Magento_CatalogRule"/>
- diff --git a/vendor/magento/module-catalog-staging/Setup/UpgradeSchema.php b/vendor/magento/module-catalog-staging/Setup/UpgradeSchema.php
- index f1967de20f1..28678702132 100644
- --- a/vendor/magento/module-catalog-staging/Setup/UpgradeSchema.php
- +++ b/vendor/magento/module-catalog-staging/Setup/UpgradeSchema.php
- @@ -26,11 +26,26 @@ class UpgradeSchema implements UpgradeSchemaInterface
- */
- public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
- {
- - $this->addIndexIfNotExist(
- - $setup,
- - 'catalog_product_entity',
- - ['entity_id', 'created_in', 'updated_in']
- - );
- + $setup->startSetup();
- + if (version_compare($context->getVersion(), '2.1.1', '<')) {
- + $this->addIndexIfNotExist(
- + $setup,
- + 'catalog_product_entity',
- + ['entity_id', 'created_in', 'updated_in']
- + );
- + }
- +
- + if (version_compare($context->getVersion(), '2.1.1.1.2', '<')) {
- + $setup->getConnection()->dropForeignKey(
- + $setup->getTable('catalog_product_index_price'),
- + $setup->getFkName(
- + 'catalog_product_index_price',
- + 'entity_id',
- + 'sequence_product',
- + 'sequence_value'
- + )
- + );
- + }
- }
- /**
- diff --git a/vendor/magento/module-catalog-staging/etc/module.xml b/vendor/magento/module-catalog-staging/etc/module.xml
- index d3bb700ced4..ad3f51121c1 100644
- --- a/vendor/magento/module-catalog-staging/etc/module.xml
- +++ b/vendor/magento/module-catalog-staging/etc/module.xml
- @@ -6,7 +6,7 @@
- */
- -->
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
- - <module name="Magento_CatalogStaging" setup_version="2.1.1">
- + <module name="Magento_CatalogStaging" setup_version="2.1.1.1.2">
- <sequence>
- <module name="Magento_Catalog"/>
- <module name="Magento_CatalogInventory"/>
- diff --git a/vendor/magento/module-elasticsearch/Model/ResourceModel/Index.php b/vendor/magento/module-elasticsearch/Model/ResourceModel/Index.php
- index f384260ad84..869b9e89f02 100644
- --- a/vendor/magento/module-elasticsearch/Model/ResourceModel/Index.php
- +++ b/vendor/magento/module-elasticsearch/Model/ResourceModel/Index.php
- @@ -42,6 +42,7 @@ class Index extends \Magento\AdvancedSearch\Model\ResourceModel\Index
- * @param CategoryRepositoryInterface $categoryRepository
- * @param Config $eavConfig
- * @param null $connectionName
- + * @SuppressWarnings(Magento.TypeDuplication)
- */
- public function __construct(
- Context $context,
- @@ -55,7 +56,12 @@ class Index extends \Magento\AdvancedSearch\Model\ResourceModel\Index
- $this->productRepository = $productRepository;
- $this->categoryRepository = $categoryRepository;
- $this->eavConfig = $eavConfig;
- - parent::__construct($context, $storeManager, $metadataPool, $connectionName);
- + parent::__construct(
- + $context,
- + $storeManager,
- + $metadataPool,
- + $connectionName
- + );
- }
- /**
- diff --git a/vendor/magento/module-gift-card/etc/di.xml b/vendor/magento/module-gift-card/etc/di.xml
- index 53233e3ab39..2de0249cded 100644
- --- a/vendor/magento/module-gift-card/etc/di.xml
- +++ b/vendor/magento/module-gift-card/etc/di.xml
- @@ -149,4 +149,10 @@
- </argument>
- </arguments>
- </type>
- + <type name="Magento\GiftCard\Model\ResourceModel\Indexer\Price">
- + <arguments>
- + <argument name="tableStrategy" xsi:type="object">Magento\Catalog\Model\ResourceModel\Product\Indexer\TemporaryTableStrategy</argument>
- + <argument name="connectionName" xsi:type="string">indexer</argument>
- + </arguments>
- + </type>
- </config>
Add Comment
Please, Sign In to add comment