Skip to content

Commit 90045f0

Browse files
author
Oleksii Korshenko
authored
Merge pull request #451 from magento-okapis/okapis-2.1.3-pr
Fixed issues: - MAGETWO-56928: CLONE - Wrong algorithm for calculation batch size on category indexing - MAGETWO-57001: [Backport] - Admin user with access to only one website is unable to edit a product - for 2.1 - MAGETWO-58742: [Backport] After upgrading from 2.0.7 to 2.1, editing a category gives a 500 error - for 2.1.3
2 parents b0f4bfc + 155cdc0 commit 90045f0

File tree

10 files changed

+786
-50
lines changed

10 files changed

+786
-50
lines changed

app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,9 @@ public function reindexByIds(array $ids)
159159
$this->doReindexByIds($ids);
160160
} catch (\Exception $e) {
161161
$this->critical($e);
162-
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
162+
throw new \Magento\Framework\Exception\LocalizedException(
163+
__("Catalog rule indexing failed. See details in exception log.")
164+
);
163165
}
164166
}
165167

app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
use Magento\Framework\Model\Entity\ScopeInterface;
1414
use Magento\Framework\EntityManager\Operation\AttributeInterface;
1515
use Magento\Eav\Model\Entity\AttributeCache;
16+
use Psr\Log\LoggerInterface;
1617

1718
/**
1819
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -49,6 +50,11 @@ class ReadHandler implements AttributeInterface
4950
*/
5051
protected $scopeResolver;
5152

53+
/**
54+
* @var LoggerInterface
55+
*/
56+
private $logger;
57+
5258
/**
5359
* ReadHandler constructor.
5460
*
@@ -75,14 +81,27 @@ public function __construct(
7581
$this->attributeCache = $attributeCache;
7682
}
7783

84+
/**
85+
* Get Logger
86+
*
87+
* @return LoggerInterface
88+
* @deprecated
89+
*/
90+
private function getLogger()
91+
{
92+
if ($this->logger === null) {
93+
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()->create(LoggerInterface::class);
94+
}
95+
return $this->logger;
96+
}
97+
7898
/**
7999
* @param string $entityType
80100
* @return \Magento\Eav\Api\Data\AttributeInterface[]
81101
* @throws \Exception
82102
*/
83103
protected function getAttributes($entityType)
84104
{
85-
86105
$attributes = $this->attributeCache->getAttributes($entityType);
87106
if ($attributes) {
88107
return $attributes;
@@ -163,7 +182,14 @@ public function execute($entityType, $entityData, $arguments = [])
163182
\Magento\Framework\DB\Select::SQL_UNION_ALL
164183
);
165184
foreach ($connection->fetchAll($unionSelect) as $attributeValue) {
166-
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
185+
if (isset($attributesMap[$attributeValue['attribute_id']])) {
186+
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
187+
} else {
188+
$this->getLogger()->warning(
189+
"Attempt to load value of nonexistent EAV attribute '{$attributeValue['attribute_id']}'
190+
for entity type '$entityType'."
191+
);
192+
}
167193
}
168194
}
169195
return $entityData;

app/code/Magento/Rule/Model/ResourceModel/Rule/Collection/AbstractCollection.php

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,18 @@ public function addWebsitesToResult($flag = null)
7474
*/
7575
public function addWebsiteFilter($websiteId)
7676
{
77-
$entityInfo = $this->_getAssociatedEntityInfo('website');
7877
if (!$this->getFlag('is_website_table_joined')) {
78+
$websiteIds = is_array($websiteId) ? $websiteId : [$websiteId];
79+
$entityInfo = $this->_getAssociatedEntityInfo('website');
7980
$this->setFlag('is_website_table_joined', true);
80-
if ($websiteId instanceof \Magento\Store\Model\Website) {
81-
$websiteId = $websiteId->getId();
81+
foreach ($websiteIds as $index => $website) {
82+
if ($website instanceof \Magento\Store\Model\Website) {
83+
$websiteIds[$index] = $website->getId();
84+
}
8285
}
8386
$this->getSelect()->join(
8487
['website' => $this->getTable($entityInfo['associations_table'])],
85-
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' = ?', $websiteId)
88+
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
8689
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
8790
[]
8891
);

app/code/Magento/Rule/Test/Unit/Model/ResourceModel/Rule/Collection/AbstractCollectionTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,16 @@ class AbstractCollectionTest extends \PHPUnit_Framework_TestCase
4545
*/
4646
protected $_db;
4747

48+
/**
49+
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
50+
*/
51+
private $connectionMock;
52+
53+
/**
54+
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
55+
*/
56+
private $selectMock;
57+
4858
protected function setUp()
4959
{
5060
$this->_entityFactoryMock = $this->getMock('Magento\Framework\Data\Collection\EntityFactoryInterface');
@@ -152,6 +162,30 @@ public function testAddWebsiteFilter()
152162
);
153163
}
154164

165+
public function testAddWebsiteFilterArray()
166+
{
167+
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
168+
->disableOriginalConstructor()
169+
->getMock();
170+
171+
$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
172+
->disableOriginalConstructor()
173+
->getMockForAbstractClass();
174+
$this->connectionMock->expects($this->atLeastOnce())
175+
->method('quoteInto')
176+
->with($this->equalTo('website. IN (?)'), $this->equalTo(['2', '3']))
177+
->willReturn(true);
178+
179+
$this->abstractCollection->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock);
180+
$this->abstractCollection->expects($this->atLeastOnce())->method('getConnection')
181+
->willReturn($this->connectionMock);
182+
183+
$this->assertInstanceOf(
184+
\Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::class,
185+
$this->abstractCollection->addWebsiteFilter(['2', '3'])
186+
);
187+
}
188+
155189
public function testAddFieldToFilter()
156190
{
157191
$this->_prepareAddFilterStubs();

lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
use Magento\Framework\Phrase;
2424
use Magento\Framework\Stdlib\DateTime;
2525
use Magento\Framework\Stdlib\StringUtils;
26+
use Magento\Framework\DB\Query\Generator as QueryGenerator;
2627

2728
/**
2829
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
@@ -189,6 +190,11 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
189190
*/
190191
protected $logger;
191192

193+
/**
194+
* @var QueryGenerator
195+
*/
196+
private $queryGenerator;
197+
192198
/**
193199
* @param StringUtils $string
194200
* @param DateTime $dateTime
@@ -3329,57 +3335,32 @@ public function insertFromSelect(Select $select, $table, array $fields = [], $mo
33293335
* @param int $stepCount
33303336
* @return \Magento\Framework\DB\Select[]
33313337
* @throws LocalizedException
3338+
* @deprecated
33323339
*/
33333340
public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100)
33343341
{
3335-
$fromSelect = $select->getPart(\Magento\Framework\DB\Select::FROM);
3336-
if (empty($fromSelect)) {
3337-
throw new LocalizedException(
3338-
new \Magento\Framework\Phrase('Select object must have correct "FROM" part')
3339-
);
3340-
}
3341-
3342-
$tableName = [];
3343-
$correlationName = '';
3344-
foreach ($fromSelect as $correlationName => $formPart) {
3345-
if ($formPart['joinType'] == \Magento\Framework\DB\Select::FROM) {
3346-
$tableName = $formPart['tableName'];
3347-
break;
3348-
}
3349-
}
3350-
3351-
$selectRange = $this->select()
3352-
->from(
3353-
$tableName,
3354-
[
3355-
new \Zend_Db_Expr('MIN(' . $this->quoteIdentifier($rangeField) . ') AS min'),
3356-
new \Zend_Db_Expr('MAX(' . $this->quoteIdentifier($rangeField) . ') AS max'),
3357-
]
3358-
);
3359-
3360-
$rangeResult = $this->fetchRow($selectRange);
3361-
$min = $rangeResult['min'];
3362-
$max = $rangeResult['max'];
3363-
3342+
$iterator = $this->getQueryGenerator()->generate($rangeField, $select, $stepCount);
33643343
$queries = [];
3365-
while ($min <= $max) {
3366-
$partialSelect = clone $select;
3367-
$partialSelect->where(
3368-
$this->quoteIdentifier($correlationName) . '.'
3369-
. $this->quoteIdentifier($rangeField) . ' >= ?',
3370-
$min
3371-
)
3372-
->where(
3373-
$this->quoteIdentifier($correlationName) . '.'
3374-
. $this->quoteIdentifier($rangeField) . ' < ?',
3375-
$min + $stepCount
3376-
);
3377-
$queries[] = $partialSelect;
3378-
$min += $stepCount;
3344+
foreach ($iterator as $query) {
3345+
$queries[] = $query;
33793346
}
33803347
return $queries;
33813348
}
33823349

3350+
/**
3351+
* Get query generator
3352+
*
3353+
* @return QueryGenerator
3354+
* @deprecated
3355+
*/
3356+
private function getQueryGenerator()
3357+
{
3358+
if ($this->queryGenerator === null) {
3359+
$this->queryGenerator = \Magento\Framework\App\ObjectManager::getInstance()->create(QueryGenerator::class);
3360+
}
3361+
return $this->queryGenerator;
3362+
}
3363+
33833364
/**
33843365
* Get update table query using select object for join and update
33853366
*

0 commit comments

Comments
 (0)