Skip to content

Commit 4b192f3

Browse files
committed
Merge remote-tracking branch 'origin/develop' into MAGETWO-63881
2 parents e55eeed + a2cf9b8 commit 4b192f3

File tree

72 files changed

+1908
-182
lines changed

Some content is hidden

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

72 files changed

+1908
-182
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/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/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"/>

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ protected function _saveProductAttributes(array $attributesData)
12491249
$linkId = $this->_connection->fetchOne(
12501250
$this->_connection->select()
12511251
->from($this->getResource()->getTable('catalog_product_entity'))
1252-
->where('sku = ?', $sku)
1252+
->where('sku = ?', (string)$sku)
12531253
->columns($this->getProductEntityLinkField())
12541254
);
12551255

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

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\CatalogRule\Model\ResourceModel\Rule;
77

8+
use Magento\Framework\Serialize\Serializer\Json;
9+
use Magento\Framework\App\ObjectManager;
10+
811
class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\AbstractCollection
912
{
1013
/**
@@ -14,6 +17,11 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
1417
*/
1518
protected $_associatedEntitiesMap;
1619

20+
/**
21+
* @var Json
22+
*/
23+
protected $serializer;
24+
1725
/**
1826
* Collection constructor.
1927
* @param \Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory
@@ -22,17 +30,20 @@ class Collection extends \Magento\Rule\Model\ResourceModel\Rule\Collection\Abstr
2230
* @param \Magento\Framework\Event\ManagerInterface $eventManager
2331
* @param \Magento\Framework\DB\Adapter\AdapterInterface $connection
2432
* @param \Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource
33+
* @param Json|null $serializer
2534
*/
2635
public function __construct(
2736
\Magento\Framework\Data\Collection\EntityFactoryInterface $entityFactory,
2837
\Psr\Log\LoggerInterface $logger,
2938
\Magento\Framework\Data\Collection\Db\FetchStrategyInterface $fetchStrategy,
3039
\Magento\Framework\Event\ManagerInterface $eventManager,
3140
\Magento\Framework\DB\Adapter\AdapterInterface $connection = null,
32-
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null
41+
\Magento\Framework\Model\ResourceModel\Db\AbstractDb $resource = null,
42+
Json $serializer = null
3343
) {
3444
parent::__construct($entityFactory, $logger, $fetchStrategy, $eventManager, $connection, $resource);
3545
$this->_associatedEntitiesMap = $this->getAssociatedEntitiesMap();
46+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(Json::class);
3647
}
3748

3849
/**
@@ -55,7 +66,7 @@ protected function _construct()
5566
*/
5667
public function addAttributeInConditionFilter($attributeCode)
5768
{
58-
$match = sprintf('%%%s%%', substr(serialize(['attribute' => $attributeCode]), 5, -1));
69+
$match = sprintf('%%%s%%', substr($this->serializer->serialize(['attribute' => $attributeCode]), 1, -1));
5970
$this->addFieldToFilter('conditions_serialized', ['like' => $match]);
6071

6172
return $this;
@@ -96,7 +107,6 @@ protected function mapAssociatedEntities($entityType, $objectField)
96107

97108
/**
98109
* @return $this
99-
* @throws \Exception
100110
*/
101111
protected function _afterLoad()
102112
{

0 commit comments

Comments
 (0)