Skip to content

Commit 3533103

Browse files
author
Stanislav Idolov
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-83893
2 parents ddddc50 + 5d10ddd commit 3533103

File tree

291 files changed

+4580
-5078
lines changed

Some content is hidden

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

291 files changed

+4580
-5078
lines changed

app/code/Magento/Catalog/Block/Product/ListProduct.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -265,13 +265,21 @@ public function prepareSortableFieldsByCategory($category)
265265
public function getIdentities()
266266
{
267267
$identities = [];
268-
foreach ($this->_getProductCollection() as $item) {
269-
$identities = array_merge($identities, $item->getIdentities());
270-
}
268+
271269
$category = $this->getLayer()->getCurrentCategory();
272270
if ($category) {
273271
$identities[] = Product::CACHE_PRODUCT_CATEGORY_TAG . '_' . $category->getId();
274272
}
273+
274+
//Check if category page shows only static block (No products)
275+
if ($category->getData('display_mode') == Category::DM_PAGE) {
276+
return $identities;
277+
}
278+
279+
foreach ($this->_getProductCollection() as $item) {
280+
$identities = array_merge($identities, $item->getIdentities());
281+
}
282+
275283
return $identities;
276284
}
277285

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/Block/Product/ListProductTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ public function testGetIdentities()
192192
->will($this->returnValue($this->toolbarMock));
193193

194194
$this->assertEquals(
195-
[$productTag, $categoryTag],
195+
[$categoryTag, $productTag],
196196
$this->block->getIdentities()
197197
);
198198
$this->assertEquals(
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"/>

app/code/Magento/Indexer/Console/Command/IndexerStatusCommand.php

Lines changed: 77 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
use Symfony\Component\Console\Input\InputInterface;
99
use Symfony\Component\Console\Output\OutputInterface;
10+
use Magento\Framework\Indexer;
11+
use Magento\Framework\Mview;
1012

1113
/**
1214
* Command for displaying status of indexers.
@@ -30,21 +32,84 @@ protected function configure()
3032
*/
3133
protected function execute(InputInterface $input, OutputInterface $output)
3234
{
35+
$table = $this->getHelperSet()->get('table');
36+
$table->setHeaders(['Title', 'Status', 'Update On', 'Schedule Status', 'Schedule Updated']);
37+
38+
$rows = [];
39+
3340
$indexers = $this->getIndexers($input);
3441
foreach ($indexers as $indexer) {
35-
$status = 'unknown';
36-
switch ($indexer->getStatus()) {
37-
case \Magento\Framework\Indexer\StateInterface::STATUS_VALID:
38-
$status = 'Ready';
39-
break;
40-
case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID:
41-
$status = 'Reindex required';
42-
break;
43-
case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING:
44-
$status = 'Processing';
45-
break;
42+
$view = $indexer->getView();
43+
44+
$rowData = [
45+
'Title' => $indexer->getTitle(),
46+
'Status' => $this->getStatus($indexer),
47+
'Update On' => $indexer->isScheduled() ? 'Schedule' : 'Save',
48+
'Schedule Status' => '',
49+
'Updated' => '',
50+
];
51+
52+
if ($indexer->isScheduled()) {
53+
$state = $view->getState();
54+
$rowData['Schedule Status'] = "{$state->getStatus()} ({$this->getPendingCount($view)} in backlog)";
55+
$rowData['Updated'] = $state->getUpdated();
4656
}
47-
$output->writeln(sprintf('%-50s ', $indexer->getTitle() . ':') . $status);
57+
58+
$rows[] = $rowData;
59+
}
60+
61+
usort($rows, function ($comp1, $comp2) {
62+
return strcmp($comp1['Title'], $comp2['Title']);
63+
});
64+
65+
$table->addRows($rows);
66+
$table->render($output);
67+
}
68+
69+
/**
70+
* @param Indexer\IndexerInterface $indexer
71+
* @return string
72+
*/
73+
private function getStatus(Indexer\IndexerInterface $indexer)
74+
{
75+
$status = 'unknown';
76+
switch ($indexer->getStatus()) {
77+
case \Magento\Framework\Indexer\StateInterface::STATUS_VALID:
78+
$status = 'Ready';
79+
break;
80+
case \Magento\Framework\Indexer\StateInterface::STATUS_INVALID:
81+
$status = 'Reindex required';
82+
break;
83+
case \Magento\Framework\Indexer\StateInterface::STATUS_WORKING:
84+
$status = 'Processing';
85+
break;
4886
}
87+
return $status;
88+
}
89+
90+
/**
91+
* @param Mview\ViewInterface $view
92+
* @return string
93+
*/
94+
private function getPendingCount(Mview\ViewInterface $view)
95+
{
96+
$changelog = $view->getChangelog();
97+
98+
try {
99+
$currentVersionId = $changelog->getVersion();
100+
} catch (Mview\View\ChangelogTableNotExistsException $e) {
101+
return '';
102+
}
103+
104+
$state = $view->getState();
105+
106+
$pendingCount = count($changelog->getList($state->getVersionId(), $currentVersionId));
107+
108+
$pendingString = "<error>$pendingCount</error>";
109+
if ($pendingCount <= 0) {
110+
$pendingString = "<info>$pendingCount</info>";
111+
}
112+
113+
return $pendingString;
49114
}
50115
}

0 commit comments

Comments
 (0)