Skip to content

Commit

Permalink
Merge pull request #1220 from magento-folks/MAGETWO-69261
Browse files Browse the repository at this point in the history
Fixed issue:
- MAGETWO-69261: Magento\Framework\App\ResourceConnection::getTableName does not support index table name switching
  • Loading branch information
MomotenkoNatalia authored Jun 23, 2017
2 parents d816ce7 + 87bd339 commit e1774ec
Show file tree
Hide file tree
Showing 90 changed files with 375 additions and 1,755 deletions.
27 changes: 13 additions & 14 deletions app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

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
Expand All @@ -16,33 +17,31 @@
class Stock extends \Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\DefaultStock
{
/**
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
* @var \Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher
*/
private $indexerStockFrontendResource;
private $activeTableSwitcher;

/**
* Class constructor
*
* 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 string $connectionName
* @param null|\Magento\Indexer\Model\Indexer\StateFactory $stateFactory
* @param null|\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource
* @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\Indexer\Model\Indexer\StateFactory $stateFactory = null,
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher $activeTableSwitcher = null
) {
parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName, $stateFactory);
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
parent::__construct($context, $tableStrategy, $eavConfig, $scopeConfig, $connectionName);
$this->activeTableSwitcher = $activeTableSwitcher ?: ObjectManager::getInstance()->get(
\Magento\Catalog\Model\ResourceModel\Indexer\ActiveTableSwitcher::class
);
}

/**
Expand All @@ -67,8 +66,8 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
$this->_cleanBundleOptionStockData();
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
$table = $this->getActionType() === Full::ACTION_TYPE
? $this->getMainTable()
: $this->indexerStockFrontendResource->getMainTable();
? $this->activeTableSwitcher->getAdditionalTableName($this->getMainTable())
: $this->getMainTable();
$idxTable = $usePrimaryTable ? $table : $this->getIdxTable();
$connection = $this->getConnection();
$select = $connection->select()->from(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,99 +44,6 @@ class Collection extends \Magento\Catalog\Model\ResourceModel\Product\Collection
*/
private $websiteScopePriceJoined = false;

/**
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource
*/
private $indexerStockFrontendResource;

/**
* Collection constructor.
* @param \Magento\Framework\Data\Collection\EntityFactory $entityFactory
* @param \Psr\Log\LoggerInterface $logger
* @param \Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy
* @param \Magento\Framework\Event\ManagerInterface $eventManager
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Framework\App\ResourceConnection $resource
* @param \Magento\Eav\Model\EntityFactory $eavEntityFactory
* @param \Magento\Catalog\Model\ResourceModel\Helper $resourceHelper
* @param \Magento\Framework\Validator\UniversalFactory $universalFactory
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\Module\Manager $moduleManager
* @param \Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState
* @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
* @param \Magento\Catalog\Model\Product\OptionFactory $productOptionFactory
* @param \Magento\Catalog\Model\ResourceModel\Url $catalogUrl
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param GroupManagementInterface $groupManagement
* @param \Magento\Framework\DB\Adapter\AdapterInterface|null $connection
* @param ProductLimitationFactory|null $productLimitationFactory
* @param MetadataPool|null $metadataPool
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerFrontendResource
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $indexerStockFrontendResource
*
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
* @SuppressWarnings(Magento.TypeDuplication)
*/
public function __construct(
\Magento\Framework\Data\Collection\EntityFactory $entityFactory,
\Psr\Log\LoggerInterface $logger,
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
\Magento\Framework\Event\ManagerInterface $eventManager,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Eav\Model\EntityFactory $eavEntityFactory,
\Magento\Catalog\Model\ResourceModel\Helper $resourceHelper,
\Magento\Framework\Validator\UniversalFactory $universalFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\Module\Manager $moduleManager,
\Magento\Catalog\Model\Indexer\Product\Flat\State $catalogProductFlatState,
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Catalog\Model\Product\OptionFactory $productOptionFactory,
\Magento\Catalog\Model\ResourceModel\Url $catalogUrl,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\Stdlib\DateTime $dateTime,
GroupManagementInterface $groupManagement,
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
ProductLimitationFactory $productLimitationFactory = null,
MetadataPool $metadataPool = null,
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerFrontendResource = null,
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null,
\Magento\Indexer\Model\ResourceModel\FrontendResource $indexerStockFrontendResource = null
) {
parent::__construct(
$entityFactory,
$logger,
$fetchStrategy,
$eventManager,
$eavConfig,
$resource,
$eavEntityFactory,
$resourceHelper,
$universalFactory,
$storeManager,
$moduleManager,
$catalogProductFlatState,
$scopeConfig,
$productOptionFactory,
$catalogUrl,
$localeDate,
$customerSession,
$dateTime,
$groupManagement,
$connection,
$productLimitationFactory,
$metadataPool,
$indexerFrontendResource,
$categoryProductIndexerFrontend
);
$this->indexerStockFrontendResource = $indexerStockFrontendResource ?: ObjectManager::getInstance()
->get(\Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource::class);
}

/**
* Initialize collection
*
Expand Down Expand Up @@ -261,7 +168,7 @@ public function addQuantityFilter()
{
$this->getSelect()
->joinInner(
['stock' => $this->indexerStockFrontendResource->getMainTable()],
['stock' => $this->getTable('cataloginventory_stock_status')],
'selection.product_id = stock.product_id',
[]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
namespace Magento\Bundle\Test\Unit\Model\ResourceModel\Selection;

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Indexer\Model\ResourceModel\FrontendResource;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
use Magento\Framework\Validator\UniversalFactory;
Expand All @@ -17,15 +16,9 @@

/**
* Class CollectionTest.
* Unit test for \Magento\Indexer\Model\ResourceModel\FrontendResource.
*/
class CollectionTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
private $frontendResource;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
Expand Down Expand Up @@ -64,9 +57,6 @@ class CollectionTest extends \PHPUnit_Framework_TestCase
protected function setUp()
{
$objectManager = new ObjectManager($this);
$this->frontendResource = $this->getMockBuilder(FrontendResource::class)
->disableOriginalConstructor()
->getMock();
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)
->disableOriginalConstructor()
->getMock();
Expand Down Expand Up @@ -114,17 +104,16 @@ protected function setUp()
[
'storeManager' => $this->storeManager,
'universalFactory' => $this->universalFactory,
'productLimitationFactory' => $factory,
'indexerStockFrontendResource' => $this->frontendResource
'productLimitationFactory' => $factory
]
);
}

public function testAddQuantityFilter()
{
$tableName = 'cataloginventory_stock_status';
$this->frontendResource->expects($this->once())
->method('getMainTable')
$this->entity->expects($this->once())
->method('getTable')
->willReturn($tableName);
$this->select->expects($this->once())
->method('joinInner')
Expand Down
3 changes: 1 addition & 2 deletions app/code/Magento/Bundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@
"magento/framework": "100.2.*",
"magento/module-quote": "100.2.*",
"magento/module-media-storage": "100.2.*",
"magento/module-ui": "100.2.*",
"magento/module-indexer": "100.2.*"
"magento/module-ui": "100.2.*"
},
"suggest": {
"magento/module-webapi": "100.2.*",
Expand Down
12 changes: 1 addition & 11 deletions app/code/Magento/Bundle/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -155,19 +155,9 @@
</type>
<type name="Magento\CatalogInventory\Model\Indexer\Stock\Action\Full">
<arguments>
<argument name="memoryTablesMinRows" xsi:type="array">
<argument name="batchRowsCount" xsi:type="array">
<item name="bundle" xsi:type="number">136</item>
</argument>
</arguments>
</type>
<type name="Magento\Bundle\Model\ResourceModel\Selection\Collection">
<arguments>
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
</arguments>
</type>
<type name="Magento\Bundle\Model\ResourceModel\Indexer\Stock">
<arguments>
<argument name="indexerStockFrontendResource" xsi:type="object">Magento\CatalogInventory\Model\ResourceModel\Indexer\Stock\FrontendResource</argument>
</arguments>
</type>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use Magento\Framework\DB\Query\Generator as QueryGenerator;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Catalog\Model\ResourceModel\Product\Indexer\Category\Product\FrontendResource as CategoryProductFrontend;

/**
* Class AbstractAction
Expand Down Expand Up @@ -112,33 +111,24 @@ abstract class AbstractAction
*/
private $queryGenerator;

/**
* @var \Magento\Indexer\Model\ResourceModel\FrontendResource|null
*/
private $categoryProductIndexerFrontend;

/**
* @param ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Model\Config $config
* @param QueryGenerator $queryGenerator
* @param \Magento\Indexer\Model\ResourceModel\FrontendResource|null $categoryProductIndexerFrontend
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Config $config,
QueryGenerator $queryGenerator = null,
\Magento\Indexer\Model\ResourceModel\FrontendResource $categoryProductIndexerFrontend = null
QueryGenerator $queryGenerator = null
) {
$this->resource = $resource;
$this->connection = $resource->getConnection();
$this->storeManager = $storeManager;
$this->config = $config;
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(QueryGenerator::class);
$this->categoryProductIndexerFrontend = $categoryProductIndexerFrontend
?: \Magento\Framework\App\ObjectManager::getInstance()->get(CategoryProductFrontend::class);
}

/**
Expand Down Expand Up @@ -185,7 +175,7 @@ protected function getTable($table)
*/
protected function getMainTable()
{
return $this->categoryProductIndexerFrontend->getMainTable();
return $this->getTable(self::MAIN_INDEX_TABLE);
}

/**
Expand Down
Loading

0 comments on commit e1774ec

Please sign in to comment.