Skip to content

Commit 8ec8eff

Browse files
author
olysenko
committed
Merge remote-tracking branch 'origin/develop' into MAGETWO-63716
2 parents 68fe4b4 + a2cf9b8 commit 8ec8eff

File tree

61 files changed

+1786
-168
lines changed

Some content is hidden

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

61 files changed

+1786
-168
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/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/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
{

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel implements RuleInterface, I
162162
* @param array $data
163163
* @param ExtensionAttributesFactory|null $extensionFactory
164164
* @param AttributeValueFactory|null $customAttributeFactory
165+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
165166
*
166167
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
167168
*/
@@ -186,7 +187,8 @@ public function __construct(
186187
array $relatedCacheTypes = [],
187188
array $data = [],
188189
ExtensionAttributesFactory $extensionFactory = null,
189-
AttributeValueFactory $customAttributeFactory = null
190+
AttributeValueFactory $customAttributeFactory = null,
191+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
190192
) {
191193
$this->_productCollectionFactory = $productCollectionFactory;
192194
$this->_storeManager = $storeManager;
@@ -210,7 +212,8 @@ public function __construct(
210212
$resourceCollection,
211213
$data,
212214
$extensionFactory,
213-
$customAttributeFactory
215+
$customAttributeFactory,
216+
$serializer
214217
);
215218
}
216219

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
<?php
2+
/**
3+
* Copyright © 2013-2017 Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\CatalogRule\Setup;
8+
9+
use Magento\Framework\DB\FieldDataConverterFactory;
10+
use Magento\Framework\DB\DataConverter\SerializedToJson;
11+
use Magento\Framework\Setup\ModuleContextInterface;
12+
use Magento\Framework\Setup\ModuleDataSetupInterface;
13+
use Magento\Framework\Setup\UpgradeDataInterface;
14+
use Magento\Framework\EntityManager\MetadataPool;
15+
use Magento\CatalogRule\Api\Data\RuleInterface;
16+
17+
class UpgradeData implements UpgradeDataInterface
18+
{
19+
/**
20+
* @var FieldDataConverterFactory
21+
*/
22+
private $fieldDataConverterFactory;
23+
24+
/**
25+
* @var MetadataPool
26+
*/
27+
private $metadataPool;
28+
29+
/**
30+
* UpgradeData constructor.
31+
*
32+
* @param FieldDataConverterFactory $fieldDataConverterFactory
33+
* @param MetadataPool $metadataPool
34+
*/
35+
public function __construct(
36+
FieldDataConverterFactory $fieldDataConverterFactory,
37+
MetadataPool $metadataPool
38+
) {
39+
$this->fieldDataConverterFactory = $fieldDataConverterFactory;
40+
$this->metadataPool = $metadataPool;
41+
}
42+
43+
/**
44+
* @inheritdoc
45+
*/
46+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
47+
{
48+
$setup->startSetup();
49+
50+
if (version_compare($context->getVersion(), '2.0.3', '<')) {
51+
$this->convertSerializedDataToJson($setup);
52+
}
53+
54+
$setup->endSetup();
55+
}
56+
57+
/**
58+
* Convert metadata from serialized to JSON format:
59+
*
60+
* @param ModuleDataSetupInterface $setup
61+
*
62+
* @return void
63+
*/
64+
public function convertSerializedDataToJson($setup)
65+
{
66+
$fieldDataConverter = $this->fieldDataConverterFactory->create(SerializedToJson::class);
67+
$metadata = $this->metadataPool->getMetadata(RuleInterface::class);
68+
69+
$fieldDataConverter->convert(
70+
$setup->getConnection(),
71+
$setup->getTable('catalogrule'),
72+
$metadata->getLinkField(),
73+
'conditions_serialized'
74+
);
75+
$fieldDataConverter->convert(
76+
$setup->getConnection(),
77+
$setup->getTable('catalogrule'),
78+
$metadata->getLinkField(),
79+
'actions_serialized'
80+
);
81+
}
82+
}

app/code/Magento/CatalogRule/Test/Unit/Model/RuleTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,46 @@ protected function setUp()
149149
'resourceIterator' => $this->_resourceIterator,
150150
'extensionFactory' => $extensionFactoryMock,
151151
'customAttributeFactory' => $attributeValueFactoryMock,
152+
'serializer' => $this->getSerializerMock(),
152153
]
153154
);
154155
}
155156

157+
/**
158+
* Get mock for serializer
159+
*
160+
* @return \PHPUnit_Framework_MockObject_MockObject
161+
*/
162+
private function getSerializerMock()
163+
{
164+
$serializerMock = $this->getMockBuilder(\Magento\Framework\Serialize\Serializer\Json::class)
165+
->disableOriginalConstructor()
166+
->setMethods(['serialize', 'unserialize'])
167+
->getMock();
168+
169+
$serializerMock->expects($this->any())
170+
->method('serialize')
171+
->will(
172+
$this->returnCallback(
173+
function ($value) {
174+
return json_encode($value);
175+
}
176+
)
177+
);
178+
179+
$serializerMock->expects($this->any())
180+
->method('unserialize')
181+
->will(
182+
$this->returnCallback(
183+
function ($value) {
184+
return json_decode($value, true);
185+
}
186+
)
187+
);
188+
189+
return $serializerMock;
190+
}
191+
156192
/**
157193
* @dataProvider dataProviderCallbackValidateProduct
158194
* @param bool $validate

app/code/Magento/CatalogRule/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_CatalogRule" setup_version="2.0.2">
9+
<module name="Magento_CatalogRule" setup_version="2.0.3">
1010
<sequence>
1111
<module name="Magento_Rule"/>
1212
<module name="Magento_Catalog"/>

app/code/Magento/CatalogWidget/Model/Rule.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class Rule extends \Magento\Rule\Model\AbstractModel
3232
* @param ExtensionAttributesFactory|null $extensionFactory
3333
* @param AttributeValueFactory|null $customAttributeFactory
3434
*
35+
* @param \Magento\Framework\Serialize\Serializer\Json $serializer
3536
* @SuppressWarnings(PHPMD.ExcessiveParameterList)
3637
*/
3738
public function __construct(
@@ -44,7 +45,8 @@ public function __construct(
4445
\Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
4546
array $data = [],
4647
ExtensionAttributesFactory $extensionFactory = null,
47-
AttributeValueFactory $customAttributeFactory = null
48+
AttributeValueFactory $customAttributeFactory = null,
49+
\Magento\Framework\Serialize\Serializer\Json $serializer = null
4850
) {
4951
$this->conditionsFactory = $conditionsFactory;
5052
parent::__construct(
@@ -56,7 +58,8 @@ public function __construct(
5658
$resourceCollection,
5759
$data,
5860
$extensionFactory,
59-
$customAttributeFactory
61+
$customAttributeFactory,
62+
$serializer
6063
);
6164
}
6265

0 commit comments

Comments
 (0)