Skip to content

Commit

Permalink
Merge pull request #94 from magento-goinc/MAGETWO-23764
Browse files Browse the repository at this point in the history
[GoInc+Nord] Bugfixing (part3)
  • Loading branch information
Slabko,Michael(mslabko) authored and Slabko,Michael(mslabko) committed Nov 1, 2015
2 parents 74f9337 + 02bfce7 commit e8ff866
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 41 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel;

use Magento\Framework\App\ResourceConnection;

class MaxHeapTableSizeProcessor
{
/**
* Database connection adapter
*
* @var \Magento\Framework\DB\Adapter\AdapterInterface
*/
protected $connection;

/**
* @var int
*/
protected $defaultMaxHeapTableSie;

/**
* Current max_heap_table_size value (in Bytes)
*
* @var int
*/
protected $currentMaxHeapTableSize = null;

/**
* @param ResourceConnection $resource
*/
public function __construct(ResourceConnection $resource)
{
$this->connection = $resource->getConnection();
$this->defaultMaxHeapTableSie = 1024 * 1024 * 64;
}

/**
* Set max_heap_table_size value in Bytes. By default value is 64M
*
* @param int|null $maxHeapTableSize
* @throws \InvalidArgumentException
* @throws \RuntimeException
* @return void
*/
public function set($maxHeapTableSize = null)
{
$maxHeapTableSize = (int) (null === $maxHeapTableSize ? $this->defaultMaxHeapTableSie : $maxHeapTableSize);
if (!$maxHeapTableSize) {
throw new \InvalidArgumentException('Wrong max_heap_table_size parameter');
}

$this->currentMaxHeapTableSize = (int)$this->connection->fetchOne('SELECT @@session.max_heap_table_size');
if (!$this->currentMaxHeapTableSize) {
throw new \RuntimeException('Can not extract max_heap_table_size');
}

$this->connection->query('SET SESSION max_heap_table_size = ' . $maxHeapTableSize);
}

/**
* Restore max_heap_table_size value
*
* @throws \RuntimeException
* @return void
*/
public function restore()
{
if (null === $this->currentMaxHeapTableSize) {
throw new \RuntimeException('max_heap_table_size parameter is not set');
}
$this->connection->query('SET SESSION max_heap_table_size = ' . $this->currentMaxHeapTableSize);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/

namespace Magento\Catalog\Plugin\Model\Indexer\Category\Product;

use Magento\Catalog\Model\Indexer\Category\Product\Action\Full;
use Magento\Catalog\Model\ResourceModel\MaxHeapTableSizeProcessor;
use Psr\Log\LoggerInterface;

class MaxHeapTableSizeProcessorOnFullReindex
{
/**
* @var MaxHeapTableSizeProcessor
*/
protected $maxHeapTableSizeProcessor;

/**
* @param MaxHeapTableSizeProcessor $maxHeapTableSizeProcessor
* @param LoggerInterface $logger
*/
public function __construct(
MaxHeapTableSizeProcessor $maxHeapTableSizeProcessor,
LoggerInterface $logger
) {
$this->maxHeapTableSizeProcessor = $maxHeapTableSizeProcessor;
$this->logger = $logger;
}

/**
* @param Full $subject
* @return void
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function beforeExecute(Full $subject)
{
try {
$this->maxHeapTableSizeProcessor->set();
} catch (\Exception $e) {
$this->logger->error($e);
}
}

/**
* @param Full $subject
* @param Full $result
* @return Full
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterExecute(Full $subject, Full $result)
{
try {
$this->maxHeapTableSizeProcessor->restore();
} catch (\Exception $e) {
$this->logger->error($e);
}
return $result;
}
}
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
</type>
<type name="Magento\Catalog\Model\Indexer\Category\Product\Action\Full">
<plugin name="invalidate_pagecache_after_full_reindex" type="Magento\Catalog\Plugin\Model\Indexer\Category\Product\Execute" />
<plugin name="max_heap_tablse_size_processor_on_full_reindex" type="Magento\Catalog\Plugin\Model\Indexer\Category\Product\MaxHeapTableSizeProcessorOnFullReindex"/>
</type>
<type name="Magento\Catalog\Model\ResourceModel\Attribute">
<plugin name="invalidate_pagecache_after_attribute_save" type="Magento\Catalog\Plugin\Model\ResourceModel\Attribute\Save" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public function testPrepareSummary($useAggregatedData, $mainTable, $isFilter, $g
*/
public function testGetDateRangeFirstPart($range, $customStart, $customEnd, $expectedInterval)
{
$this->markTestIncomplete('MAGETWO-44815');
$result = $this->collection->getDateRange($range, $customStart, $customEnd);
$interval = $result['to']->diff($result['from']);
$intervalResult = $interval->format('%y %m %d %h:%i:%s');
Expand Down
8 changes: 6 additions & 2 deletions app/code/Magento/Sales/Model/Rss/OrderStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,11 @@ public function getRssData()
public function getCacheKey()
{
$order = $this->getOrder();
return 'rss_order_status_data_' . md5($order->getId() . $order->getIncrementId() . $order->getCustomerId());
$key = '';
if ($order !== null) {
$key = md5($order->getId() . $order->getIncrementId() . $order->getCustomerId());
}
return 'rss_order_status_data_' . $key;
}

/**
Expand Down Expand Up @@ -150,7 +154,7 @@ protected function getOrder()
$order = $this->orderFactory->create();
$order->load($data['order_id']);

if ($order->getIncrementId() != $data['increment_id'] || $order->getCustomerId() != $data['customer_id']) {
if ($order->getIncrementId() !== $data['increment_id'] || $order->getCustomerId() !== $data['customer_id']) {
$order = null;
}
$this->order = $order;
Expand Down
57 changes: 47 additions & 10 deletions app/code/Magento/Sales/Test/Unit/Model/Rss/OrderStatusTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,14 @@ protected function setUp()
]
);
}
public function testGetData()

public function testGetRssData()
{
$this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
$this->requestInterface->expects($this->any())->method('getParam')
->with('data')
->will($this->returnValue('eyJvcmRlcl9pZCI6MSwiaW5jcmVtZW50X2lkIjoiMTAwMDAwMDAxIiwiY3VzdG9tZXJfaWQiOjF9'));
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);
$requestData = base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}');

$this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);

$resource = $this->getMockBuilder('\Magento\Sales\Model\ResourceModel\Order\Rss\OrderStatus')
->setMethods(['getAllCommentCollection'])
->disableOriginalConstructor()
Expand All @@ -148,15 +150,34 @@ public function testGetData()
'created_at' => '2014-10-09 18:25:50',
'comment' => 'Some comment',
];
$resource->expects($this->once())->method('getAllCommentCollection')->will($this->returnValue([$comment]));
$this->orderStatusFactory->expects($this->once())->method('create')->will($this->returnValue($resource));
$resource->expects($this->once())->method('getAllCommentCollection')->willReturn([$comment]);
$this->orderStatusFactory->expects($this->once())->method('create')->willReturn($resource);
$this->urlInterface->expects($this->any())->method('getUrl')
->with('sales/order/view', ['order_id' => 1])
->will($this->returnValue('http://magento.com/sales/order/view/order_id/1'));

$this->assertEquals($this->feedData, $this->model->getRssData());
}

/**
* @expectedException \InvalidArgumentException
* @expectedExceptionMessage Order not found.
*/
public function testGetRssDataWithError()
{
$this->orderFactory->expects($this->once())->method('create')->willReturn($this->order);

$requestData = base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}');

$this->requestInterface->expects($this->any())->method('getParam')->with('data')->willReturn($requestData);

$this->orderStatusFactory->expects($this->never())->method('create');

$this->urlInterface->expects($this->never())->method('getUrl');

$this->assertEquals($this->feedData, $this->model->getRssData());
}

public function testIsAllowed()
{
$this->scopeConfigInterface->expects($this->once())->method('getValue')
Expand All @@ -165,13 +186,29 @@ public function testIsAllowed()
$this->assertTrue($this->model->isAllowed());
}

public function testGetCacheKey()
/**
* @param string $requestData
* @param string $result
* @dataProvider getCacheKeyDataProvider
*/
public function testGetCacheKey($requestData, $result)
{
$this->requestInterface->expects($this->any())->method('getParam')
->with('data')
->will($this->returnValue('eyJvcmRlcl9pZCI6MSwiaW5jcmVtZW50X2lkIjoiMTAwMDAwMDAxIiwiY3VzdG9tZXJfaWQiOjF9'));
->will($this->returnValue($requestData));
$this->orderFactory->expects($this->once())->method('create')->will($this->returnValue($this->order));
$this->assertEquals('rss_order_status_data_' . md5('11000000011'), $this->model->getCacheKey());
$this->assertEquals('rss_order_status_data_' . $result, $this->model->getCacheKey());
}

/**
* @return array
*/
public function getCacheKeyDataProvider()
{
return [
[base64_encode('{"order_id":1,"increment_id":"100000001","customer_id":1}'), md5('11000000011')],
[base64_encode('{"order_id":"1","increment_id":true,"customer_id":true}'), '']
];
}

public function testGetCacheLifetime()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ require([
setRowVisibility('is_unique', false);
setRowVisibility('frontend_class', false);
break;
<?php $hiddenFields = $block->helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() ?>
<?php $hiddenFields = $this->helper('Magento\Catalog\Helper\Data')->getAttributeHiddenFields() ?>
<?php foreach ($hiddenFields as $type => $fields): ?>
<?php if (in_array($type, array('swatch_visual', 'swatch_text'))) continue ?>
case '<?php echo $block->escapeHtml($type); ?>':
Expand Down
16 changes: 3 additions & 13 deletions app/code/Magento/Swatches/view/adminhtml/web/js/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define([
template: mageTemplate('#swatch-text-row-template'),
add: function (data, render) {
var isNewOption = false,
element, visibleRadio;
element;

if (typeof data.id == 'undefined') {
data = {
Expand All @@ -44,18 +44,8 @@ define([
data: data
});

if (isNewOption) {
visibleRadio = $$('#swatch-text-options-panel [name="defaulttext[]"]').findAll(function (el) {
return el.up().up().visible();
});

if (visibleRadio.length === 1) {
visibleRadio[0].checked = true;
}

if (!this.isReadOnly) {
this.enableNewOptionDeleteButton(data.id);
}
if (isNewOption && !this.isReadOnly) {
this.enableNewOptionDeleteButton(data.id);
}
this.itemCount++;
this.totalItems++;
Expand Down
18 changes: 3 additions & 15 deletions app/code/Magento/Swatches/view/adminhtml/web/js/visual.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ define([
template: mageTemplate('#swatch-visual-row-template'),
add: function (data, render) {
var isNewOption = false,
element, visibleRadio;
element;

if (typeof data.id == 'undefined') {
data = {
Expand All @@ -46,20 +46,8 @@ define([
data: data
});

if (isNewOption) {
visibleRadio = $$('#swatch-visual-options-panel [name="defaultvisual[]"]').findAll(
function (el) {
return el.up().up().visible();
}
);

if (visibleRadio.length === 1) {
visibleRadio[0].checked = true;
}

if (!this.isReadOnly) {
this.enableNewOptionDeleteButton(data.id);
}
if (isNewOption && !this.isReadOnly) {
this.enableNewOptionDeleteButton(data.id);
}
this.itemCount++;
this.totalItems++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function testMultiRulesWithTimezone()
*/
public function testMultiRulesWithDifferentTimezone()
{
$this->markTestIncomplete('MAGETWO-44815');
$this->setSpecificTimezone('Australia/Sydney');
$collection = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(
'Magento\SalesRule\Model\ResourceModel\Rule\Collection'
Expand Down

0 comments on commit e8ff866

Please sign in to comment.