Skip to content

Commit

Permalink
Merge pull request #451 from magento-okapis/okapis-2.1.3-pr
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Oleksii Korshenko authored Sep 30, 2016
2 parents b0f4bfc + 155cdc0 commit 90045f0
Show file tree
Hide file tree
Showing 10 changed files with 786 additions and 50 deletions.
4 changes: 3 additions & 1 deletion app/code/Magento/CatalogRule/Model/Indexer/IndexBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,9 @@ public function reindexByIds(array $ids)
$this->doReindexByIds($ids);
} catch (\Exception $e) {
$this->critical($e);
throw new \Magento\Framework\Exception\LocalizedException(__($e->getMessage()), $e);
throw new \Magento\Framework\Exception\LocalizedException(
__("Catalog rule indexing failed. See details in exception log.")
);
}
}

Expand Down
30 changes: 28 additions & 2 deletions app/code/Magento/Eav/Model/ResourceModel/ReadHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\Model\Entity\ScopeInterface;
use Magento\Framework\EntityManager\Operation\AttributeInterface;
use Magento\Eav\Model\Entity\AttributeCache;
use Psr\Log\LoggerInterface;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -49,6 +50,11 @@ class ReadHandler implements AttributeInterface
*/
protected $scopeResolver;

/**
* @var LoggerInterface
*/
private $logger;

/**
* ReadHandler constructor.
*
Expand All @@ -75,14 +81,27 @@ public function __construct(
$this->attributeCache = $attributeCache;
}

/**
* Get Logger
*
* @return LoggerInterface
* @deprecated
*/
private function getLogger()
{
if ($this->logger === null) {
$this->logger = \Magento\Framework\App\ObjectManager::getInstance()->create(LoggerInterface::class);
}
return $this->logger;
}

/**
* @param string $entityType
* @return \Magento\Eav\Api\Data\AttributeInterface[]
* @throws \Exception
*/
protected function getAttributes($entityType)
{

$attributes = $this->attributeCache->getAttributes($entityType);
if ($attributes) {
return $attributes;
Expand Down Expand Up @@ -163,7 +182,14 @@ public function execute($entityType, $entityData, $arguments = [])
\Magento\Framework\DB\Select::SQL_UNION_ALL
);
foreach ($connection->fetchAll($unionSelect) as $attributeValue) {
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
if (isset($attributesMap[$attributeValue['attribute_id']])) {
$entityData[$attributesMap[$attributeValue['attribute_id']]] = $attributeValue['value'];
} else {
$this->getLogger()->warning(
"Attempt to load value of nonexistent EAV attribute '{$attributeValue['attribute_id']}'
for entity type '$entityType'."
);
}
}
}
return $entityData;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,18 @@ public function addWebsitesToResult($flag = null)
*/
public function addWebsiteFilter($websiteId)
{
$entityInfo = $this->_getAssociatedEntityInfo('website');
if (!$this->getFlag('is_website_table_joined')) {
$websiteIds = is_array($websiteId) ? $websiteId : [$websiteId];
$entityInfo = $this->_getAssociatedEntityInfo('website');
$this->setFlag('is_website_table_joined', true);
if ($websiteId instanceof \Magento\Store\Model\Website) {
$websiteId = $websiteId->getId();
foreach ($websiteIds as $index => $website) {
if ($website instanceof \Magento\Store\Model\Website) {
$websiteIds[$index] = $website->getId();
}
}
$this->getSelect()->join(
['website' => $this->getTable($entityInfo['associations_table'])],
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' = ?', $websiteId)
$this->getConnection()->quoteInto('website.' . $entityInfo['entity_id_field'] . ' IN (?)', $websiteIds)
. ' AND main_table.' . $entityInfo['rule_id_field'] . ' = website.' . $entityInfo['rule_id_field'],
[]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class AbstractCollectionTest extends \PHPUnit_Framework_TestCase
*/
protected $_db;

/**
* @var \Magento\Framework\DB\Adapter\AdapterInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $connectionMock;

/**
* @var \Magento\Framework\DB\Select|\PHPUnit_Framework_MockObject_MockObject
*/
private $selectMock;

protected function setUp()
{
$this->_entityFactoryMock = $this->getMock('Magento\Framework\Data\Collection\EntityFactoryInterface');
Expand Down Expand Up @@ -152,6 +162,30 @@ public function testAddWebsiteFilter()
);
}

public function testAddWebsiteFilterArray()
{
$this->selectMock = $this->getMockBuilder(\Magento\Framework\DB\Select::class)
->disableOriginalConstructor()
->getMock();

$this->connectionMock = $this->getMockBuilder(\Magento\Framework\DB\Adapter\AdapterInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
$this->connectionMock->expects($this->atLeastOnce())
->method('quoteInto')
->with($this->equalTo('website. IN (?)'), $this->equalTo(['2', '3']))
->willReturn(true);

$this->abstractCollection->expects($this->atLeastOnce())->method('getSelect')->willReturn($this->selectMock);
$this->abstractCollection->expects($this->atLeastOnce())->method('getConnection')
->willReturn($this->connectionMock);

$this->assertInstanceOf(
\Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection::class,
$this->abstractCollection->addWebsiteFilter(['2', '3'])
);
}

public function testAddFieldToFilter()
{
$this->_prepareAddFilterStubs();
Expand Down
67 changes: 24 additions & 43 deletions lib/internal/Magento/Framework/DB/Adapter/Pdo/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use Magento\Framework\Phrase;
use Magento\Framework\Stdlib\DateTime;
use Magento\Framework\Stdlib\StringUtils;
use Magento\Framework\DB\Query\Generator as QueryGenerator;

/**
* @SuppressWarnings(PHPMD.ExcessivePublicCount)
Expand Down Expand Up @@ -189,6 +190,11 @@ class Mysql extends \Zend_Db_Adapter_Pdo_Mysql implements AdapterInterface
*/
protected $logger;

/**
* @var QueryGenerator
*/
private $queryGenerator;

/**
* @param StringUtils $string
* @param DateTime $dateTime
Expand Down Expand Up @@ -3329,57 +3335,32 @@ public function insertFromSelect(Select $select, $table, array $fields = [], $mo
* @param int $stepCount
* @return \Magento\Framework\DB\Select[]
* @throws LocalizedException
* @deprecated
*/
public function selectsByRange($rangeField, \Magento\Framework\DB\Select $select, $stepCount = 100)
{
$fromSelect = $select->getPart(\Magento\Framework\DB\Select::FROM);
if (empty($fromSelect)) {
throw new LocalizedException(
new \Magento\Framework\Phrase('Select object must have correct "FROM" part')
);
}

$tableName = [];
$correlationName = '';
foreach ($fromSelect as $correlationName => $formPart) {
if ($formPart['joinType'] == \Magento\Framework\DB\Select::FROM) {
$tableName = $formPart['tableName'];
break;
}
}

$selectRange = $this->select()
->from(
$tableName,
[
new \Zend_Db_Expr('MIN(' . $this->quoteIdentifier($rangeField) . ') AS min'),
new \Zend_Db_Expr('MAX(' . $this->quoteIdentifier($rangeField) . ') AS max'),
]
);

$rangeResult = $this->fetchRow($selectRange);
$min = $rangeResult['min'];
$max = $rangeResult['max'];

$iterator = $this->getQueryGenerator()->generate($rangeField, $select, $stepCount);
$queries = [];
while ($min <= $max) {
$partialSelect = clone $select;
$partialSelect->where(
$this->quoteIdentifier($correlationName) . '.'
. $this->quoteIdentifier($rangeField) . ' >= ?',
$min
)
->where(
$this->quoteIdentifier($correlationName) . '.'
. $this->quoteIdentifier($rangeField) . ' < ?',
$min + $stepCount
);
$queries[] = $partialSelect;
$min += $stepCount;
foreach ($iterator as $query) {
$queries[] = $query;
}
return $queries;
}

/**
* Get query generator
*
* @return QueryGenerator
* @deprecated
*/
private function getQueryGenerator()
{
if ($this->queryGenerator === null) {
$this->queryGenerator = \Magento\Framework\App\ObjectManager::getInstance()->create(QueryGenerator::class);
}
return $this->queryGenerator;
}

/**
* Get update table query using select object for join and update
*
Expand Down
Loading

0 comments on commit 90045f0

Please sign in to comment.