Skip to content

Commit 4b9c132

Browse files
committed
Merge pull request #428 from magento-south/BUGS
[South] Sprint #52
2 parents b04dffa + 456fc04 commit 4b9c132

File tree

48 files changed

+304
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+304
-119
lines changed

app/code/Magento/Catalog/Model/ProductRepository.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,8 @@ public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveO
512512
if ($tierPrices !== null) {
513513
$product->setData('tier_price', $tierPrices);
514514
}
515+
unset($this->instances[$product->getSku()]);
516+
unset($this->instancesById[$product->getId()]);
515517
$this->resourceModel->save($product);
516518
} catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
517519
throw \Magento\Framework\Exception\InputException::invalidFieldValue(
@@ -535,6 +537,8 @@ public function delete(\Magento\Catalog\Api\Data\ProductInterface $product)
535537
$sku = $product->getSku();
536538
$productId = $product->getId();
537539
try {
540+
unset($this->instances[$product->getSku()]);
541+
unset($this->instancesById[$product->getId()]);
538542
$this->resourceModel->delete($product);
539543
} catch (\Exception $e) {
540544
throw new \Magento\Framework\Exception\StateException(

app/code/Magento/Catalog/Test/Unit/Model/ProductRepositoryTest.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ public function testSaveException()
541541
->willReturn(true);
542542
$this->resourceModelMock->expects($this->once())->method('save')->with($this->productMock)
543543
->willThrowException(new \Magento\Eav\Model\Entity\Attribute\Exception(__('123')));
544-
$this->productMock->expects($this->never())->method('getId');
544+
$this->productMock->expects($this->once())->method('getId')->willReturn(null);
545545
$this->extensibleDataObjectConverterMock
546546
->expects($this->once())
547547
->method('toNestedArray')
@@ -576,7 +576,8 @@ public function testSaveInvalidProductException()
576576

577577
public function testDelete()
578578
{
579-
$this->productMock->expects($this->once())->method('getSku')->willReturn('product-42');
579+
$this->productMock->expects($this->exactly(2))->method('getSku')->willReturn('product-42');
580+
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(42);
580581
$this->resourceModelMock->expects($this->once())->method('delete')->with($this->productMock)
581582
->willReturn(true);
582583
$this->assertTrue($this->model->delete($this->productMock));
@@ -588,7 +589,8 @@ public function testDelete()
588589
*/
589590
public function testDeleteException()
590591
{
591-
$this->productMock->expects($this->once())->method('getSku')->willReturn('product-42');
592+
$this->productMock->expects($this->exactly(2))->method('getSku')->willReturn('product-42');
593+
$this->productMock->expects($this->exactly(2))->method('getId')->willReturn(42);
592594
$this->resourceModelMock->expects($this->once())->method('delete')->with($this->productMock)
593595
->willThrowException(new \Exception());
594596
$this->model->delete($this->productMock);

app/code/Magento/CatalogRule/Model/ResourceModel/Rule.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -250,16 +250,8 @@ public function save(\Magento\Framework\Model\AbstractModel $object)
250250
if ($object->isDeleted()) {
251251
return $this->delete($object);
252252
}
253-
254253
$this->beginTransaction();
255-
256254
try {
257-
if (!$this->isModified($object)) {
258-
$this->processNotModifiedSave($object);
259-
$this->commit();
260-
$object->setHasDataChanges(false);
261-
return $this;
262-
}
263255
$object->validateBeforeSave();
264256
$object->beforeSave();
265257
if ($object->isSaveAllowed()) {

app/code/Magento/Cms/Model/ResourceModel/Block.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -236,16 +236,8 @@ public function save(AbstractModel $object)
236236
if ($object->isDeleted()) {
237237
return $this->delete($object);
238238
}
239-
240239
$this->beginTransaction();
241-
242240
try {
243-
if (!$this->isModified($object)) {
244-
$this->processNotModifiedSave($object);
245-
$this->commit();
246-
$object->setHasDataChanges(false);
247-
return $this;
248-
}
249241
$object->validateBeforeSave();
250242
$object->beforeSave();
251243
if ($object->isSaveAllowed()) {

app/code/Magento/Cms/Model/ResourceModel/Page.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -386,16 +386,8 @@ public function save(AbstractModel $object)
386386
if ($object->isDeleted()) {
387387
return $this->delete($object);
388388
}
389-
390389
$this->beginTransaction();
391-
392390
try {
393-
if (!$this->isModified($object)) {
394-
$this->processNotModifiedSave($object);
395-
$this->commit();
396-
$object->setHasDataChanges(false);
397-
return $this;
398-
}
399391
$object->validateBeforeSave();
400392
$object->beforeSave();
401393
if ($object->isSaveAllowed()) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Plugin for \Magento\Customer\Api\CustomerRepositoryInterface
4+
*
5+
* Copyright © 2015 Magento. All rights reserved.
6+
* See COPYING.txt for license details.
7+
*/
8+
namespace Magento\Customer\Model\Plugin\CustomerRepository;
9+
10+
class TransactionWrapper
11+
{
12+
/**
13+
* @var \Magento\Customer\Model\ResourceModel\Customer
14+
*/
15+
protected $resourceModel;
16+
17+
/**
18+
* @param \Magento\Customer\Model\ResourceModel\Customer $resourceModel
19+
*/
20+
public function __construct(
21+
\Magento\Customer\Model\ResourceModel\Customer $resourceModel
22+
) {
23+
$this->resourceModel = $resourceModel;
24+
}
25+
26+
/**
27+
* @param \Magento\Customer\Api\CustomerRepositoryInterface $subject
28+
* @param callable $proceed
29+
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
30+
* @param string $passwordHash
31+
* @return \Magento\Customer\Api\Data\CustomerInterface
32+
* @throws \Exception
33+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
34+
*/
35+
public function aroundSave(
36+
\Magento\Customer\Api\CustomerRepositoryInterface $subject,
37+
\Closure $proceed,
38+
\Magento\Customer\Api\Data\CustomerInterface $customer,
39+
$passwordHash = null
40+
) {
41+
$this->resourceModel->beginTransaction();
42+
try {
43+
/** @var $result \Magento\Customer\Api\Data\CustomerInterface */
44+
$result = $proceed($customer, $passwordHash);
45+
$this->resourceModel->commit();
46+
return $result;
47+
} catch (\Exception $e) {
48+
$this->resourceModel->rollBack();
49+
throw $e;
50+
}
51+
}
52+
}
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Customer\Test\Unit\Model\Plugin\CustomerRepository;
7+
8+
class TransactionWrapperTest extends \PHPUnit_Framework_TestCase
9+
{
10+
/**
11+
* @var \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper
12+
*/
13+
protected $model;
14+
15+
/**
16+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Model\ResourceModel\Customer
17+
*/
18+
protected $resourceMock;
19+
20+
/**
21+
* @var \PHPUnit_Framework_MockObject_MockObject|\Magento\Customer\Api\CustomerRepositoryInterface
22+
*/
23+
protected $subjectMock;
24+
25+
/**
26+
* @var \Closure
27+
*/
28+
protected $closureMock;
29+
30+
/**
31+
* @var \Closure
32+
*/
33+
protected $rollbackClosureMock;
34+
35+
/**
36+
* @var \PHPUnit_Framework_MockObject_MockObject
37+
*/
38+
protected $customerMock;
39+
40+
/**
41+
* @var string
42+
*/
43+
protected $passwordHash = true;
44+
45+
const ERROR_MSG = "error occurred";
46+
47+
protected function setUp()
48+
{
49+
$this->resourceMock = $this->getMock('Magento\Customer\Model\ResourceModel\Customer', [], [], '', false);
50+
$this->subjectMock = $this->getMock('Magento\Customer\Api\CustomerRepositoryInterface', [], [], '', false);
51+
$this->customerMock = $this->getMock('Magento\Customer\Api\Data\CustomerInterface', [], [], '', false);
52+
$customerMock = $this->customerMock;
53+
$this->closureMock = function () use ($customerMock) {
54+
return $customerMock;
55+
};
56+
$this->rollbackClosureMock = function () use ($customerMock) {
57+
throw new \Exception(self::ERROR_MSG);
58+
};
59+
60+
$this->model = new \Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper($this->resourceMock);
61+
}
62+
63+
public function testAroundSaveCommit()
64+
{
65+
$this->resourceMock->expects($this->once())->method('beginTransaction');
66+
$this->resourceMock->expects($this->once())->method('commit');
67+
68+
$this->assertEquals(
69+
$this->customerMock,
70+
$this->model->aroundSave($this->subjectMock, $this->closureMock, $this->customerMock, $this->passwordHash)
71+
);
72+
}
73+
74+
/**
75+
* @expectedException \Exception
76+
* @expectedExceptionMessage error occurred
77+
*/
78+
public function testAroundSaveRollBack()
79+
{
80+
$this->resourceMock->expects($this->once())->method('beginTransaction');
81+
$this->resourceMock->expects($this->once())->method('rollBack');
82+
83+
$this->model->aroundSave(
84+
$this->subjectMock,
85+
$this->rollbackClosureMock,
86+
$this->customerMock,
87+
$this->passwordHash
88+
);
89+
}
90+
}

app/code/Magento/Customer/etc/di.xml

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -205,26 +205,6 @@
205205
<argument name="concatExpression" xsi:type="object">BillingAddressExpression</argument>
206206
</arguments>
207207
</virtualType>
208-
<virtualType name="LastVisitAtHandler" type="Magento\Framework\Indexer\Handler\ConcatHandler">
209-
<arguments>
210-
<argument name="concatExpression" xsi:type="object">LastVisitAtSubSelect</argument>
211-
</arguments>
212-
</virtualType>
213-
<virtualType name="LastVisitAtSubSelect" type="Magento\Framework\DB\Sql\LookupExpression">
214-
<arguments>
215-
<argument name="targetTable" xsi:type="string">customer_visitor</argument>
216-
<argument name="targetColumn" xsi:type="string">last_visit_at</argument>
217-
<argument name="referenceColumns" xsi:type="array">
218-
<item name="customer_id" xsi:type="array">
219-
<item name="tableAlias" xsi:type="string">e</item>
220-
<item name="columnName" xsi:type="string">entity_id</item>
221-
</item>
222-
</argument>
223-
<argument name="sortOrder" xsi:type="array">
224-
<item name="DESC" xsi:type="string">last_visit_at</item>
225-
</argument>
226-
</arguments>
227-
</virtualType>
228208
<virtualType name="CustomerNameExpression" type="Magento\Framework\DB\Sql\ConcatExpression">
229209
<arguments>
230210
<argument name="tableName" xsi:type="string">e</argument>
@@ -319,4 +299,7 @@
319299
</argument>
320300
</arguments>
321301
</type>
302+
<type name="Magento\Customer\Api\CustomerRepositoryInterface">
303+
<plugin name="transactionWrapper" type="Magento\Customer\Model\Plugin\CustomerRepository\TransactionWrapper" sortOrder="-1"/>
304+
</type>
322305
</config>

app/code/Magento/Customer/etc/indexer.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
<field name="dob" xsi:type="filterable" dataType="date"/>
2424
<field name="gender" xsi:type="filterable" dataType="int"/>
2525
<field name="taxvat" xsi:type="searchable" dataType="varchar"/>
26-
<field name="last_visit_at" xsi:type="filterable" dataType="datetime" handler="LastVisitAtHandler"/>
2726
<field name="lock_expires" xsi:type="filterable" dataType="timestamp" />
2827
</fieldset>
2928

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -257,18 +257,6 @@
257257
</item>
258258
</argument>
259259
</column>
260-
<column name="last_visit_at" class="Magento\Ui\Component\Listing\Columns\Date">
261-
<argument name="data" xsi:type="array">
262-
<item name="config" xsi:type="array">
263-
<item name="component" xsi:type="string">Magento_Ui/js/grid/columns/date</item>
264-
<item name="filter" xsi:type="string">dateRange</item>
265-
<item name="visible" xsi:type="boolean">false</item>
266-
<item name="dataType" xsi:type="string">date</item>
267-
<item name="label" xsi:type="string" translate="true">Last Logged In</item>
268-
<item name="sortOrder" xsi:type="number">120</item>
269-
</item>
270-
</argument>
271-
</column>
272260
<column name="confirmation">
273261
<argument name="data" xsi:type="array">
274262
<item name="config" xsi:type="array">

0 commit comments

Comments
 (0)