Skip to content

Commit

Permalink
Merge pull request #428 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[South] Sprint #52
  • Loading branch information
slavvka committed Mar 18, 2016
2 parents b04dffa + 456fc04 commit 4b9c132
Show file tree
Hide file tree
Showing 48 changed files with 304 additions and 119 deletions.
4 changes: 4 additions & 0 deletions app/code/Magento/Catalog/Model/ProductRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,8 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
if ($tierPrices !== null) {
$product->setData('tier_price', $tierPrices);
}
unset($this->instances[$product->getSku()]);
unset($this->instancesById[$product->getId()]);
$this->resourceModel->save($product);
} catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
throw \Magento\Framework\Exception\InputException::invalidFieldValue(
Expand All @@ -535,6 +537,8 @@ public function delete(\Magento\Catalog\Api\Data\ProductInterface $product)
$sku = $product->getSku();
$productId = $product->getId();
try {
unset($this->instances[$product->getSku()]);
unset($this->instancesById[$product->getId()]);
$this->resourceModel->delete($product);
} catch (\Exception $e) {
throw new \Magento\Framework\Exception\StateException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ public function testSaveException()
->willReturn(true);
$this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock)
->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123')));
$this->productMock->expects($this->never())->method('getId');
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
$this->extensibleDataObjectConverterMock
->expects($this->once())
->method('toNestedArray')
Expand Down Expand Up @@ -576,7 +576,8 @@ public function testSaveInvalidProductException()

public function testDelete()
{
$this->productMock->expects($this->once())->method('getSku')->willReturn('product-42');
$this->productMock->expects($this->exactly(2))->method('getSku')->willReturn('product-42');
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(42);
$this->resourceModelMock->expects($this->once())->method('delete')->with($this->productMock)
->willReturn(true);
$this->assertTrue($this->model->delete($this->productMock));
Expand All @@ -588,7 +589,8 @@ public function testDelete()
*/
public function testDeleteException()
{
$this->productMock->expects($this->once())->method('getSku')->willReturn('product-42');
$this->productMock->expects($this->exactly(2))->method('getSku')->willReturn('product-42');
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(42);
$this->resourceModelMock->expects($this->once())->method('delete')->with($this->productMock)
->willThrowException(new \Exception());
$this->model->delete($this->productMock);
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,16 +250,8 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
if ($object->isDeleted()) {
return $this->delete($object);
}

$this->beginTransaction();

try {
if (!$this->isModified($object)) {
$this->processNotModifiedSave($object);
$this->commit();
$object->setHasDataChanges(false);
return $this;
}
$object->validateBeforeSave();
$object->beforeSave();
if ($object->isSaveAllowed()) {
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/Cms/Model/ResourceModel/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,8 @@ public function save(AbstractModel $object)
if ($object->isDeleted()) {
return $this->delete($object);
}

$this->beginTransaction();

try {
if (!$this->isModified($object)) {
$this->processNotModifiedSave($object);
$this->commit();
$object->setHasDataChanges(false);
return $this;
}
$object->validateBeforeSave();
$object->beforeSave();
if ($object->isSaveAllowed()) {
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/Cms/Model/ResourceModel/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,8 @@ public function save(AbstractModel $object)
if ($object->isDeleted()) {
return $this->delete($object);
}

$this->beginTransaction();

try {
if (!$this->isModified($object)) {
$this->processNotModifiedSave($object);
$this->commit();
$object->setHasDataChanges(false);
return $this;
}
$object->validateBeforeSave();
$object->beforeSave();
if ($object->isSaveAllowed()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* Plugin for \Magento\Customer\Api\CustomerRepositoryInterface
*
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Model\Plugin\CustomerRepository;

class TransactionWrapper
{
/**
* @var \Magento\Customer\Model\ResourceModel\Customer
*/
protected $resourceModel;

/**
* @param \Magento\Customer\Model\ResourceModel\Customer $resourceModel
*/
public function __construct(
\Magento\Customer\Model\ResourceModel\Customer $resourceModel
) {
$this->resourceModel = $resourceModel;
}

/**
* @param \Magento\Customer\Api\CustomerRepositoryInterface $subject
* @param callable $proceed
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @param string $passwordHash
* @return \Magento\Customer\Api\Data\CustomerInterface
* @throws \Exception
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function aroundSave(
\Magento\Customer\Api\CustomerRepositoryInterface $subject,
\Closure $proceed,
\Magento\Customer\Api\Data\CustomerInterface $customer,
$passwordHash = null
) {
$this->resourceModel->beginTransaction();
try {
/** @var $result \Magento\Customer\Api\Data\CustomerInterface */
$result = $proceed($customer, $passwordHash);
$this->resourceModel->commit();
return $result;
} catch (\Exception $e) {
$this->resourceModel->rollBack();
throw $e;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php
/**
* Copyright © 2015 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Customer\Test\Unit\Model\Plugin\CustomerRepository;

class TransactionWrapperTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper
*/
protected $model;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\ResourceModel\Customer
*/
protected $resourceMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Api\CustomerRepositoryInterface
*/
protected $subjectMock;

/**
* @var \Closure
*/
protected $closureMock;

/**
* @var \Closure
*/
protected $rollbackClosureMock;

/**
* @var \PHPUnit_Framework_MockObject_MockObject
*/
protected $customerMock;

/**
* @var string
*/
protected $passwordHash = true;

const ERROR_MSG = "error occurred";

protected function setUp()
{
$this->resourceMock = $this->getMock('Magento\Customer\Model\ResourceModel\Customer', [], [], '', false);
$this->subjectMock = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface', [], [], '', false);
$this->customerMock = $this->getMock('Magento\Customer\Api\Data\CustomerInterface', [], [], '', false);
$customerMock = $this->customerMock;
$this->closureMock = function () use ($customerMock) {
return $customerMock;
};
$this->rollbackClosureMock = function () use ($customerMock) {
throw new \Exception(self::ERROR_MSG);
};

$this->model = new \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper($this->resourceMock);
}

public function testAroundSaveCommit()
{
$this->resourceMock->expects($this->once())->method('beginTransaction');
$this->resourceMock->expects($this->once())->method('commit');

$this->assertEquals(
$this->customerMock,
$this->model->aroundSave($this->subjectMock, $this->closureMock, $this->customerMock, $this->passwordHash)
);
}

/**
* @expectedException \Exception
* @expectedExceptionMessage error occurred
*/
public function testAroundSaveRollBack()
{
$this->resourceMock->expects($this->once())->method('beginTransaction');
$this->resourceMock->expects($this->once())->method('rollBack');

$this->model->aroundSave(
$this->subjectMock,
$this->rollbackClosureMock,
$this->customerMock,
$this->passwordHash
);
}
}
23 changes: 3 additions & 20 deletions app/code/Magento/Customer/etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -205,26 +205,6 @@
<argument name="concatExpression" xsi:type="object">BillingAddressExpression</argument>
</arguments>
</virtualType>
<virtualType name="LastVisitAtHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
<arguments>
<argument name="concatExpression" xsi:type="object">LastVisitAtSubSelect</argument>
</arguments>
</virtualType>
<virtualType name="LastVisitAtSubSelect" type="Magento\Framework\DB\Sql\LookupExpression">
<arguments>
<argument name="targetTable" xsi:type="string">customer_visitor</argument>
<argument name="targetColumn" xsi:type="string">last_visit_at</argument>
<argument name="referenceColumns" xsi:type="array">
<item name="customer_id" xsi:type="array">
<item name="tableAlias" xsi:type="string">e</item>
<item name="columnName" xsi:type="string">entity_id</item>
</item>
</argument>
<argument name="sortOrder" xsi:type="array">
<item name="DESC" xsi:type="string">last_visit_at</item>
</argument>
</arguments>
</virtualType>
<virtualType name="CustomerNameExpression" type="Magento\Framework\DB\Sql\ConcatExpression">
<arguments>
<argument name="tableName" xsi:type="string">e</argument>
Expand Down Expand Up @@ -319,4 +299,7 @@
</argument>
</arguments>
</type>
<type name="Magento\Customer\Api\CustomerRepositoryInterface">
<plugin name="transactionWrapper" type="Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper" sortOrder="-1"/>
</type>
</config>
1 change: 0 additions & 1 deletion app/code/Magento/Customer/etc/indexer.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
<field name="dob" xsi:type="filterable" dataType="date"/>
<field name="gender" xsi:type="filterable" dataType="int"/>
<field name="taxvat" xsi:type="searchable" dataType="varchar"/>
<field name="last_visit_at" xsi:type="filterable" dataType="datetime" handler="LastVisitAtHandler"/>
<field name="lock_expires" xsi:type="filterable" dataType="timestamp" />
</fieldset>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,18 +257,6 @@
</item>
</argument>
</column>
<column name="last_visit_at" class="Magento\Ui\Component\Listing\Columns\Date">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
<item name="filter" xsi:type="string">dateRange</item>
<item name="visible" xsi:type="boolean">false</item>
<item name="dataType" xsi:type="string">date</item>
<item name="label" xsi:type="string" translate="true">Last Logged In</item>
<item name="sortOrder" xsi:type="number">120</item>
</item>
</argument>
</column>
<column name="confirmation">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
Expand Down
19 changes: 15 additions & 4 deletions app/code/Magento/Customer/view/frontend/web/js/customer-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,17 @@ define([
* @return {*}
*/
ko.extenders.disposableCustomerData = function (target, sectionName) {
storage.remove(sectionName);
var sectionDataIds, newSectionDataIds = {};
target.subscribe(function () {
setTimeout(function () {
storage.remove(sectionName);
sectionDataIds = $.cookieStorage.get('section_data_ids') || {};
_.each(sectionDataIds, function (data, name) {
if (name != sectionName) {
newSectionDataIds[name] = data;
}
});
$.cookieStorage.set('section_data_ids', newSectionDataIds);
}, 3000);
});

Expand Down Expand Up @@ -166,7 +173,9 @@ define([
remove: function (sections) {
_.each(sections, function (sectionName) {
storage.remove(sectionName);
storageInvalidation.set(sectionName, true);
if (!sectionConfig.isClientSideSection(sectionName)) {
storageInvalidation.set(sectionName, true);
}
});
}
};
Expand Down Expand Up @@ -202,7 +211,7 @@ define([
if (!_.isEmpty(privateContent)) {
countryData = this.get('directory-data');
if (_.isEmpty(countryData())) {
countryData(customerData.reload(['directory-data'], false));
customerData.reload(['directory-data'], false);
}
}
},
Expand Down Expand Up @@ -304,7 +313,9 @@ define([

// Invalidate section in cookie (increase version of section with 1000)
_.each(sectionsNamesForInvalidation, function (sectionName) {
sectionDataIds[sectionName] += 1000;
if (!sectionConfig.isClientSideSection(sectionName)) {
sectionDataIds[sectionName] += 1000;
}
});
$.cookieStorage.set('section_data_ids', sectionDataIds);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,16 @@ define(['underscore'], function (_) {
},

filterClientSideSections: function (sections) {
if (_.isArray(sections)) {
if (Array.isArray(sections)) {
return _.difference(sections, clientSideSections);
}
return sections;
},

isClientSideSection: function (sectionName) {
return _.contains(clientSideSections, sectionName);
},

'Magento_Customer/js/section-config': function(options) {
baseUrls = options.baseUrls;
sections = options.sections;
Expand Down
8 changes: 0 additions & 8 deletions app/code/Magento/SalesRule/Model/ResourceModel/Rule.php
Original file line number Diff line number Diff line change
Expand Up @@ -373,16 +373,8 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
if ($object->isDeleted()) {
return $this->delete($object);
}

$this->beginTransaction();

try {
if (!$this->isModified($object)) {
$this->processNotModifiedSave($object);
$this->commit();
$object->setHasDataChanges(false);
return $this;
}
$object->validateBeforeSave();
$object->beforeSave();
if ($object->isSaveAllowed()) {
Expand Down
Loading

0 comments on commit 4b9c132

Please sign in to comment.