Skip to content

Commit 845ddbc

Browse files
author
Stanislav Idolov
committed
MAGETWO-66195: SQL Error during price reindexation process for custom profile
1 parent c9c1016 commit 845ddbc

File tree

4 files changed

+37
-8
lines changed

4 files changed

+37
-8
lines changed

app/code/Magento/Catalog/Model/Indexer/Product/Price/Action/Full.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,9 @@ public function execute($ids = null)
117117
$entityIds = $this->batchProvider->getBatchIds($connection, $select, $batch);
118118

119119
if (!empty($entityIds)) {
120-
// Temporary table will created
120+
// Temporary table will created if not exists
121121
$idxTableName = $this->_defaultIndexerResource->getIdxTable();
122+
$this->_emptyTable($idxTableName);
122123

123124
if ($indexer->getIsComposite()) {
124125
$this->_copyRelationIndexData($entityIds);

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/TemporaryTableStrategy.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66

77
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;
88

9+
/**
10+
* Provided logic will create temporary table based on memory table and will return new index table name.
11+
*/
912
class TemporaryTableStrategy implements \Magento\Framework\Indexer\Table\StrategyInterface
1013
{
1114
const TEMP_SUFFIX = '_temp';

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/CompositeProductRowSizeEstimatorTest.php

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,39 +18,64 @@ class CompositeProductRowSizeEstimatorTest extends \PHPUnit_Framework_TestCase
1818
/**
1919
* @var \PHPUnit_Framework_MockObject_MockObject
2020
*/
21-
private $rowSizeEstimatorMock;
21+
private $websiteManagementMock;
2222

2323
/**
2424
* @var \PHPUnit_Framework_MockObject_MockObject
2525
*/
2626
private $defaultPriceMock;
2727

28+
/**
29+
* @var \PHPUnit_Framework_MockObject_MockObject
30+
*/
31+
private $collectionFactoryMock;
32+
2833
protected function setUp()
2934
{
30-
$this->rowSizeEstimatorMock = $this->getMock(
31-
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\IndexTableRowSizeEstimator::class,
35+
$this->websiteManagementMock = $this->getMock(
36+
\Magento\Store\Api\WebsiteManagementInterface::class,
3237
[],
3338
[],
3439
'',
3540
false
3641
);
42+
$this->collectionFactoryMock = $this->getMock(
43+
\Magento\Customer\Model\ResourceModel\Group\CollectionFactory::class,
44+
['create'],
45+
[],
46+
'',
47+
false
48+
);
3749
$this->defaultPriceMock = $this->getMock(
3850
\Magento\Catalog\Model\ResourceModel\Product\Indexer\Price\DefaultPrice::class,
3951
[],
4052
[],
4153
'',
4254
false
4355
);
44-
$this->model = new CompositeProductRowSizeEstimator($this->defaultPriceMock, $this->rowSizeEstimatorMock);
56+
$this->model = new CompositeProductRowSizeEstimator(
57+
$this->defaultPriceMock,
58+
$this->websiteManagementMock,
59+
$this->collectionFactoryMock
60+
);
4561
}
4662

4763
public function testEstimateRowSize()
4864
{
49-
$expectedResult = 2000;
65+
$expectedResult = 40000000;
5066
$tableName = 'catalog_product_relation';
5167
$maxRelatedProductCount = 10;
5268

53-
$this->rowSizeEstimatorMock->expects($this->once())->method('estimateRowSize')->willReturn(200);
69+
$this->websiteManagementMock->expects($this->once())->method('getCount')->willReturn(100);
70+
$collectionMock = $this->getMock(
71+
\Magento\Customer\Model\ResourceModel\Group\Collection::class,
72+
[],
73+
[],
74+
'',
75+
false
76+
);
77+
$this->collectionFactoryMock->expects($this->once())->method('create')->willReturn($collectionMock);
78+
$collectionMock->expects($this->once())->method('getSize')->willReturn(200);
5479

5580
$connectionMock = $this->getMock(\Magento\Framework\DB\Adapter\AdapterInterface::class);
5681
$this->defaultPriceMock->expects($this->once())->method('getConnection')->willReturn($connectionMock);

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/Indexer/Price/IndexTableRowSizeEstimatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ protected function setUp()
4141

4242
public function testEstimateRowSize()
4343
{
44-
$expectedValue = 1800000;
44+
$expectedValue = 2400000;
4545

4646
$this->websiteManagementMock->expects($this->once())->method('getCount')->willReturn(100);
4747
$collectionMock = $this->getMock(

0 commit comments

Comments
 (0)