Skip to content

Commit 98a3188

Browse files
committed
Merge remote-tracking branch 'mainline/2.2-develop' into MAGETWO-75786
2 parents be34777 + 321278b commit 98a3188

File tree

100 files changed

+877
-203
lines changed

Some content is hidden

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

100 files changed

+877
-203
lines changed

app/code/Magento/Backend/Test/Unit/Model/Config/SessionLifetime/BackendModelTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ public function testBeforeSave($value, $errorMessage = null)
2020
\Magento\Backend\Model\Config\SessionLifetime\BackendModel::class
2121
);
2222
if ($errorMessage !== null) {
23-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $errorMessage);
23+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
24+
$this->expectExceptionMessage($errorMessage);
2425
}
2526
$model->setValue($value);
2627
$object = $model->beforeSave();

app/code/Magento/Catalog/Model/Product/Gallery/Processor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ public function addImage(
149149
}
150150

151151
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($pathinfo['basename']);
152-
$dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
152+
$dispretionPath = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
153153
$fileName = $dispretionPath . '/' . $fileName;
154154

155155
$fileName = $this->getNotDuplicatedFilename($fileName, $dispretionPath);

app/code/Magento/Catalog/Model/Product/Option/Type/File/ValidatorFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ public function validate($processingParams, $option)
150150
$extension = pathinfo(strtolower($fileInfo['name']), PATHINFO_EXTENSION);
151151

152152
$fileName = \Magento\MediaStorage\Model\File\Uploader::getCorrectFileName($fileInfo['name']);
153-
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispretionPath($fileName);
153+
$dispersion = \Magento\MediaStorage\Model\File\Uploader::getDispersionPath($fileName);
154154

155155
$filePath = $dispersion;
156156

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Plugin\Model\AttributeSetRepository;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
11+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
12+
use Magento\Eav\Api\Data\AttributeSetInterface;
13+
14+
/**
15+
* Delete related products after attribute set successfully removed.
16+
*/
17+
class RemoveProducts
18+
{
19+
/**
20+
* Retrieve products related to specific attribute set.
21+
*
22+
* @var CollectionFactory
23+
*/
24+
private $collectionFactory;
25+
26+
/**
27+
* RemoveProducts constructor.
28+
*
29+
* @param CollectionFactory $collectionFactory
30+
*/
31+
public function __construct(CollectionFactory $collectionFactory)
32+
{
33+
$this->collectionFactory = $collectionFactory;
34+
}
35+
36+
/**
37+
* Delete related to specific attribute set products, if attribute set was removed successfully.
38+
*
39+
* @param AttributeSetRepositoryInterface $subject
40+
* @param bool $result
41+
* @param AttributeSetInterface $attributeSet
42+
* @return bool
43+
*
44+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
45+
*/
46+
public function afterDelete(
47+
AttributeSetRepositoryInterface $subject,
48+
bool $result,
49+
AttributeSetInterface $attributeSet
50+
) {
51+
/** @var Collection $productCollection */
52+
$productCollection = $this->collectionFactory->create();
53+
$productCollection->addFieldToFilter('attribute_set_id', ['eq' => $attributeSet->getId()]);
54+
$productCollection->delete();
55+
56+
return $result;
57+
}
58+
}

app/code/Magento/Catalog/Setup/UpgradeSchema.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ class UpgradeSchema implements UpgradeSchemaInterface
2121
/**
2222
* {@inheritdoc}
2323
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
24+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
25+
* @SuppressWarnings(PHPMD.NPathComplexity)
2426
*/
2527
public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $context)
2628
{
@@ -126,6 +128,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
126128
$this->fixCustomerGroupIdColumn($setup);
127129
}
128130

131+
if (version_compare($context->getVersion(), '2.2.4', '<')) {
132+
$this->removeAttributeSetRelation($setup);
133+
}
134+
129135
$setup->endSetup();
130136
}
131137

@@ -699,4 +705,20 @@ private function addReplicaTable(SchemaSetupInterface $setup, $existingTable, $r
699705
);
700706
$setup->getConnection()->query($sql);
701707
}
708+
709+
/**
710+
* Remove foreign key between catalog_product_entity and eav_attribute_set tables.
711+
* Drop foreign key to delegate cascade on delete to plugin.
712+
* @see \Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts
713+
*
714+
* @param SchemaSetupInterface $setup
715+
* @return void
716+
*/
717+
private function removeAttributeSetRelation(SchemaSetupInterface $setup)
718+
{
719+
$setup->getConnection()->dropForeignKey(
720+
$setup->getTable('catalog_product_entity'),
721+
$setup->getFkName('catalog_product_entity', 'attribute_set_id', 'eav_attribute_set', 'attribute_set_id')
722+
);
723+
}
702724
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ public function testSaveWithException()
255255
*/
256256
public function testSaveWithValidateCategoryException($error, $expectedException, $expectedExceptionMessage)
257257
{
258-
$this->expectException($expectedException, $expectedExceptionMessage);
258+
$this->expectException($expectedException);
259+
$this->expectExceptionMessage($expectedExceptionMessage);
259260
$categoryId = 5;
260261
$categoryMock = $this->createMock(\Magento\Catalog\Model\Category::class);
261262
$this->extensibleDataObjectConverterMock

app/code/Magento/Catalog/Test/Unit/Model/Indexer/Product/Eav/Action/FullTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public function testExecuteWithAdapterErrorThrowsException()
4848
$tableSwitcherMock
4949
);
5050

51-
$this->expectException(\Magento\Framework\Exception\LocalizedException::class, $exceptionMessage);
51+
$this->expectException(\Magento\Framework\Exception\LocalizedException::class);
52+
$this->expectExceptionMessage($exceptionMessage);
5253

5354
$model->execute();
5455
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\Catalog\Test\Unit\Plugin\Model\AttributeSetRepository;
8+
9+
use Magento\Catalog\Model\ResourceModel\Product\Collection;
10+
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
11+
use Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts;
12+
use Magento\Eav\Api\AttributeSetRepositoryInterface;
13+
use Magento\Eav\Api\Data\AttributeSetInterface;
14+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
15+
use PHPUnit\Framework\TestCase;
16+
17+
/**
18+
* Provide tests for RemoveProducts plugin.
19+
*/
20+
class RemoveProductsTest extends TestCase
21+
{
22+
/**
23+
* @var RemoveProducts
24+
*/
25+
private $testSubject;
26+
27+
/**
28+
* @var CollectionFactory|\PHPUnit_Framework_MockObject_MockObject
29+
*/
30+
private $collectionFactory;
31+
32+
/**
33+
* @inheritdoc
34+
*/
35+
protected function setUp()
36+
{
37+
$objectManager = new ObjectManager($this);
38+
$this->collectionFactory = $this->getMockBuilder(CollectionFactory::class)
39+
->disableOriginalConstructor()
40+
->setMethods(['create'])
41+
->getMock();
42+
$this->testSubject = $objectManager->getObject(
43+
RemoveProducts::class,
44+
[
45+
'collectionFactory' => $this->collectionFactory,
46+
]
47+
);
48+
}
49+
50+
/**
51+
* Test plugin will delete all related products for given attribute set.
52+
*/
53+
public function testAfterDelete()
54+
{
55+
$attributeSetId = '1';
56+
57+
/** @var Collection|\PHPUnit_Framework_MockObject_MockObject $collection */
58+
$collection = $this->getMockBuilder(Collection::class)
59+
->disableOriginalConstructor()
60+
->getMock();
61+
$collection->expects(self::once())
62+
->method('addFieldToFilter')
63+
->with(self::identicalTo('attribute_set_id'), self::identicalTo(['eq' => $attributeSetId]));
64+
$collection->expects(self::once())
65+
->method('delete');
66+
67+
$this->collectionFactory->expects(self::once())
68+
->method('create')
69+
->willReturn($collection);
70+
71+
/** @var AttributeSetRepositoryInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSetRepository */
72+
$attributeSetRepository = $this->getMockBuilder(AttributeSetRepositoryInterface::class)
73+
->disableOriginalConstructor()
74+
->getMockForAbstractClass();
75+
76+
/** @var AttributeSetInterface|\PHPUnit_Framework_MockObject_MockObject $attributeSet */
77+
$attributeSet = $this->getMockBuilder(AttributeSetInterface::class)
78+
->setMethods(['getId'])
79+
->disableOriginalConstructor()
80+
->getMockForAbstractClass();
81+
$attributeSet->expects(self::once())
82+
->method('getId')
83+
->willReturn($attributeSetId);
84+
85+
self::assertTrue($this->testSubject->afterDelete($attributeSetRepository, true, $attributeSet));
86+
}
87+
}

app/code/Magento/Catalog/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,7 @@
184184
<argument name="scopeOverriddenValue" xsi:type="object">Magento\Catalog\Model\Attribute\ScopeOverriddenValue</argument>
185185
</arguments>
186186
</type>
187+
<type name="Magento\Eav\Api\AttributeSetRepositoryInterface">
188+
<plugin name="remove_products" type="Magento\Catalog\Plugin\Model\AttributeSetRepository\RemoveProducts"/>
189+
</type>
187190
</config>

app/code/Magento/Catalog/etc/module.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*/
77
-->
88
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
9-
<module name="Magento_Catalog" setup_version="2.2.3">
9+
<module name="Magento_Catalog" setup_version="2.2.4">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>

0 commit comments

Comments
 (0)