Skip to content

Commit 8c3bf37

Browse files
author
Bohdan Korablov
committed
Merge remote-tracking branch 'mainline/develop' into MAGETWO-63341
2 parents 06475cc + a2cf9b8 commit 8c3bf37

File tree

126 files changed

+4065
-257
lines changed

Some content is hidden

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

126 files changed

+4065
-257
lines changed

app/code/Magento/Catalog/Model/Indexer/Category/Product/Action/Full.php

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

88
class Full extends \Magento\Catalog\Model\Indexer\Category\Product\AbstractAction
99
{
10-
/**
11-
* Whether to use main or temporary index table
12-
*
13-
* @var bool
14-
*/
15-
protected $useTempTable = false;
16-
1710
/**
1811
* Refresh entities index
1912
*

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ protected function processDeletedImages($product, array &$images)
2929
if (!empty($image['removed'])) {
3030
if (!empty($image['value_id']) && !isset($picturesInOtherStores[$image['file']])) {
3131
$recordsToDelete[] = $image['value_id'];
32-
$filesToDelete[] = ltrim($image['file'], '/');
32+
// only delete physical files if they are not used by any other products
33+
if (!$this->resourceModel->countImageUses($image['file']) > 1) {
34+
$filesToDelete[] = ltrim($image['file'], '/');
35+
}
3336
}
3437
}
3538
}

app/code/Magento/Catalog/Model/Product/Pricing/Renderer/SalableResolver.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ class SalableResolver implements SalableResolverInterface
1919
*/
2020
public function isSalable(\Magento\Framework\Pricing\SaleableInterface $salableItem)
2121
{
22-
return $salableItem->getCanShowPrice() !== false && $salableItem->isSalable();
22+
return $salableItem->getCanShowPrice() !== false;
2323
}
2424
}

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2195,16 +2195,22 @@ public function addMediaGalleryData()
21952195
$linkField = $this->getProductEntityMetadata()->getLinkField();
21962196
$items = $this->getItems();
21972197

2198-
$select->where('entity.' . $linkField . ' IN (?)', array_map(function ($item) {
2199-
return $item->getId();
2200-
}, $items));
2201-
2198+
$select->where(
2199+
'entity.' . $linkField . ' IN (?)',
2200+
array_map(
2201+
function ($item) use ($linkField) {
2202+
return $item->getData($linkField);
2203+
},
2204+
$items
2205+
)
2206+
);
22022207
foreach ($this->getConnection()->fetchAll($select) as $row) {
22032208
$mediaGalleries[$row[$linkField]][] = $row;
22042209
}
22052210

22062211
foreach ($items as $item) {
2207-
$mediaEntries = isset($mediaGalleries[$item->getId()]) ? $mediaGalleries[$item->getId()] : [];
2212+
$mediaEntries = isset($mediaGalleries[$item->getData($linkField)]) ?
2213+
$mediaGalleries[$item->getData($linkField)] : [];
22082214
$this->getGalleryReadHandler()->addMediaDataToProduct($item, $mediaEntries);
22092215
}
22102216

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,21 @@ public function getProductImages($product, $storeIds)
449449

450450
return $this->getConnection()->fetchAll($select);
451451
}
452+
453+
/**
454+
* Counts uses of this image.
455+
*
456+
* @param string $image
457+
* @return int
458+
*/
459+
public function countImageUses($image)
460+
{
461+
$select = $this->getConnection()->select()
462+
->from([$this->getMainTableAlias() => $this->getMainTable()])
463+
->where(
464+
'value = ?',
465+
$image
466+
);
467+
return count($this->getConnection()->fetchAll($select));
468+
}
452469
}

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

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,10 @@ public function upgrade(SchemaSetupInterface $setup, ModuleContextInterface $con
6565
$this->addSourceEntityIdToProductEavIndex($setup);
6666
}
6767

68+
if (version_compare($context->getVersion(), '2.1.4', '<')) {
69+
$this->recreateCatalogCategoryProductIndexTmpTable($setup);
70+
}
71+
6872
$setup->endSetup();
6973
}
7074

@@ -375,4 +379,74 @@ private function addPercentageValueColumn(SchemaSetupInterface $setup)
375379
]
376380
);
377381
}
382+
383+
/**
384+
* Drop and recreate catalog_category_product_index_tmp table
385+
*
386+
* Before this update the catalog_category_product_index_tmp table was created without usage of PK
387+
* and with engine=MEMORY. Such structure of catalog_category_product_index_tmp table causes
388+
* issues with MySQL DB replication.
389+
*
390+
* To avoid replication issues this method drops catalog_category_product_index_tmp table
391+
* and creates new one with PK and engine=InnoDB
392+
*
393+
* @param SchemaSetupInterface $setup
394+
* @return void
395+
*/
396+
private function recreateCatalogCategoryProductIndexTmpTable(SchemaSetupInterface $setup)
397+
{
398+
$tableName = $setup->getTable('catalog_category_product_index_tmp');
399+
400+
// Drop catalog_category_product_index_tmp table
401+
$setup->getConnection()->dropTable($tableName);
402+
403+
// Create catalog_category_product_index_tmp table with PK and engine=InnoDB
404+
$table = $setup->getConnection()
405+
->newTable($tableName)
406+
->addColumn(
407+
'category_id',
408+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
409+
null,
410+
['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'],
411+
'Category ID'
412+
)
413+
->addColumn(
414+
'product_id',
415+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
416+
null,
417+
['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'],
418+
'Product ID'
419+
)
420+
->addColumn(
421+
'position',
422+
\Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
423+
null,
424+
['nullable' => false, 'default' => '0'],
425+
'Position'
426+
)
427+
->addColumn(
428+
'is_parent',
429+
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
430+
null,
431+
['unsigned' => true, 'nullable' => false, 'default' => '0'],
432+
'Is Parent'
433+
)
434+
->addColumn(
435+
'store_id',
436+
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
437+
null,
438+
['unsigned' => true, 'nullable' => false, 'primary' => true, 'default' => '0'],
439+
'Store ID'
440+
)
441+
->addColumn(
442+
'visibility',
443+
\Magento\Framework\DB\Ddl\Table::TYPE_SMALLINT,
444+
null,
445+
['unsigned' => true, 'nullable' => false],
446+
'Visibility'
447+
)
448+
->setComment('Catalog Category Product Indexer temporary table');
449+
450+
$setup->getConnection()->createTable($table);
451+
}
378452
}

app/code/Magento/Catalog/Test/Unit/Model/Product/Pricing/Renderer/SalableResolverTest.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ protected function setUp()
2222
{
2323
$this->product = $this->getMock(
2424
\Magento\Catalog\Model\Product::class,
25-
['__wakeup', 'getCanShowPrice', 'isSalable'],
25+
['__wakeup', 'getCanShowPrice'],
2626
[],
2727
'',
2828
false
@@ -40,8 +40,6 @@ public function testSalableItem()
4040
->method('getCanShowPrice')
4141
->willReturn(true);
4242

43-
$this->product->expects($this->any())->method('isSalable')->willReturn(true);
44-
4543
$result = $this->object->isSalable($this->product);
4644
$this->assertTrue($result);
4745
}
@@ -50,9 +48,7 @@ public function testNotSalableItem()
5048
{
5149
$this->product->expects($this->any())
5250
->method('getCanShowPrice')
53-
->willReturn(true);
54-
55-
$this->product->expects($this->any())->method('isSalable')->willReturn(false);
51+
->willReturn(false);
5652

5753
$result = $this->object->isSalable($this->product);
5854
$this->assertFalse($result);

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/CollectionTest.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -224,11 +224,12 @@ public function testAddProductCategoriesFilter()
224224
public function testAddMediaGalleryData()
225225
{
226226
$attributeId = 42;
227-
$itemId = 4242;
228-
$linkField = 'entity_id';
229-
$mediaGalleriesMock = [[$linkField => $itemId]];
227+
$rowId = 4;
228+
$linkField = 'row_id';
229+
$mediaGalleriesMock = [[$linkField => $rowId]];
230230
$itemMock = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
231231
->disableOriginalConstructor()
232+
->setMethods(['getData'])
232233
->getMock();
233234
$attributeMock = $this->getMockBuilder(\Magento\Eav\Model\Entity\Attribute\AbstractAttribute::class)
234235
->disableOriginalConstructor()
@@ -248,13 +249,13 @@ public function testAddMediaGalleryData()
248249
$this->galleryResourceMock->expects($this->once())->method('createBatchBaseSelect')->willReturn($selectMock);
249250
$attributeMock->expects($this->once())->method('getAttributeId')->willReturn($attributeId);
250251
$this->entityMock->expects($this->once())->method('getAttribute')->willReturn($attributeMock);
251-
$itemMock->expects($this->atLeastOnce())->method('getId')->willReturn($itemId);
252-
$selectMock->expects($this->once())->method('where')->with('entity.' . $linkField . ' IN (?)', [$itemId]);
252+
$itemMock->expects($this->atLeastOnce())->method('getData')->willReturn($rowId);
253+
$selectMock->expects($this->once())->method('where')->with('entity.' . $linkField . ' IN (?)', [$rowId]);
253254
$this->metadataPoolMock->expects($this->once())->method('getMetadata')->willReturn($metadataMock);
254255
$metadataMock->expects($this->once())->method('getLinkField')->willReturn($linkField);
255256

256257
$this->connectionMock->expects($this->once())->method('fetchAll')->with($selectMock)->willReturn(
257-
[['entity_id' => $itemId]]
258+
[['row_id' => $rowId]]
258259
);
259260
$this->galleryReadHandlerMock->expects($this->once())->method('addMediaDataToProduct')
260261
->with($itemMock, $mediaGalleriesMock);

app/code/Magento/Catalog/Test/Unit/Model/ResourceModel/Product/GalleryTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,4 +443,33 @@ public function testDeleteGalleryValueInStore()
443443

444444
$this->resource->deleteGalleryValueInStore($valueId, $entityId, $storeId);
445445
}
446+
447+
public function testCountImageUses()
448+
{
449+
$results = [
450+
[
451+
'value_id' => '1',
452+
'attribute_id' => 90,
453+
'value' => '/d/o/download_7.jpg',
454+
'media_type' => 'image',
455+
'disabled' => '0',
456+
],
457+
];
458+
459+
$this->connection->expects($this->once())->method('select')->will($this->returnValue($this->select));
460+
$this->select->expects($this->at(0))->method('from')->with(
461+
[
462+
'main' => 'table',
463+
],
464+
'*'
465+
)->willReturnSelf();
466+
$this->select->expects($this->at(1))->method('where')->with(
467+
'value = ?',
468+
1
469+
)->willReturnSelf();
470+
$this->connection->expects($this->once())->method('fetchAll')
471+
->with($this->select)
472+
->willReturn($results);
473+
$this->assertEquals($this->resource->countImageUses(1), count($results));
474+
}
446475
}

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.1.3">
9+
<module name="Magento_Catalog" setup_version="2.1.4">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Cms"/>

0 commit comments

Comments
 (0)