Skip to content

Commit 24d92e2

Browse files
Merge branch 'develop' of https://github.com/magento/magento2ce into MAGETWO-67099
2 parents 28879fd + c80d266 commit 24d92e2

File tree

29 files changed

+927
-162
lines changed

29 files changed

+927
-162
lines changed

app/code/Magento/CatalogWidget/Test/Unit/Block/Product/ProductsListTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,9 @@ protected function setUp()
9797
$this->builder = $this->getMock(\Magento\Rule\Model\Condition\Sql\Builder::class, [], [], '', false);
9898
$this->rule = $this->getMock(\Magento\CatalogWidget\Model\Rule::class, [], [], '', false);
9999
$this->serializer = $this->getMock(\Magento\Framework\Serialize\Serializer\Json::class, [], [], '', false);
100-
$this->widgetConditionsHelper = $this->getMock(
101-
\Magento\Widget\Helper\Conditions::class,
102-
[],
103-
['serializer' => $this->serializer]
104-
);
100+
$this->widgetConditionsHelper = $this->getMockBuilder(\Magento\Widget\Helper\Conditions::class)
101+
->disableOriginalConstructor()
102+
->getMock();
105103
$this->storeManager = $this->getMock(\Magento\Store\Model\StoreManagerInterface::class);
106104
$this->design = $this->getMock(\Magento\Framework\View\DesignInterface::class);
107105

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Cms\Setup;
7+
8+
use Magento\Widget\Model\Widget\Wysiwyg\Normalizer;
9+
use Magento\Framework\DB\DataConverter\DataConversionException;
10+
use Magento\Framework\DB\DataConverter\SerializedToJson;
11+
use Magento\Framework\Serialize\Serializer\Json;
12+
use Magento\Framework\Serialize\Serializer\Serialize;
13+
14+
/**
15+
* Convert conditions_encoded part of cms block content data from serialized to JSON format
16+
*/
17+
class ContentConverter extends SerializedToJson
18+
{
19+
/**
20+
* @var \Magento\Framework\Filter\Template\Tokenizer\ParameterFactory
21+
*/
22+
private $parameterFactory;
23+
24+
/**
25+
* @var Normalizer
26+
*/
27+
private $normalizer;
28+
29+
/**
30+
* ContentConverter constructor
31+
*
32+
* @param Serialize $serialize
33+
* @param Json $json
34+
* @param \Magento\Framework\Filter\Template\Tokenizer\ParameterFactory $parameterFactory
35+
* @param Normalizer $normalizer
36+
*/
37+
public function __construct(
38+
Serialize $serialize,
39+
Json $json,
40+
\Magento\Framework\Filter\Template\Tokenizer\ParameterFactory $parameterFactory,
41+
Normalizer $normalizer
42+
) {
43+
$this->parameterFactory = $parameterFactory;
44+
$this->normalizer = $normalizer;
45+
parent::__construct($serialize, $json);
46+
}
47+
48+
/**
49+
* Convert conditions_encoded part of block content from serialized to JSON format
50+
*
51+
* @param string $value
52+
* @return string
53+
* @throws DataConversionException
54+
*/
55+
public function convert($value)
56+
{
57+
preg_match_all('/(.*?){{widget(.*?)}}/si', $value, $matches, PREG_SET_ORDER);
58+
if (empty($matches)) {
59+
return $value;
60+
}
61+
$convertedValue = '';
62+
foreach ($matches as $match) {
63+
$convertedValue .= $match[1] . '{{widget' . $this->convertWidgetParams($match[2]) . '}}';
64+
}
65+
preg_match_all('/(.*?{{widget.*?}})*(?<ending>.*?)$/si', $value, $matchesTwo, PREG_SET_ORDER);
66+
if (isset($matchesTwo[0])) {
67+
$convertedValue .= $matchesTwo[0]['ending'];
68+
}
69+
70+
return $convertedValue;
71+
}
72+
73+
/**
74+
* Convert widget parameters from serialized format to JSON format
75+
*
76+
* @param string $paramsString
77+
* @return string
78+
*/
79+
private function convertWidgetParams($paramsString)
80+
{
81+
/** @var \Magento\Framework\Filter\Template\Tokenizer\Parameter $tokenizer */
82+
$tokenizer = $this->parameterFactory->create();
83+
$tokenizer->setString($paramsString);
84+
$widgetParameters = $tokenizer->tokenize();
85+
if (isset($widgetParameters['conditions_encoded'])) {
86+
$conditions = $this->normalizer->restoreReservedCharaters($widgetParameters['conditions_encoded']);
87+
if ($this->isValidJsonValue($conditions)) {
88+
return $paramsString;
89+
}
90+
$widgetParameters['conditions_encoded'] = $this->normalizer->replaceReservedCharaters(
91+
parent::convert($conditions)
92+
);
93+
$newParamsString = '';
94+
foreach ($widgetParameters as $key => $parameter) {
95+
$newParamsString .= ' ' . $key . '="' . $parameter . '"';
96+
}
97+
return $newParamsString;
98+
} else {
99+
return $paramsString;
100+
}
101+
}
102+
}

app/code/Magento/Cms/Setup/UpgradeData.php

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

88
use Magento\Cms\Model\Page;
99
use Magento\Cms\Model\PageFactory;
10+
use Magento\Framework\EntityManager\MetadataPool;
1011
use Magento\Framework\Setup\ModuleContextInterface;
1112
use Magento\Framework\Setup\ModuleDataSetupInterface;
1213
use Magento\Framework\Setup\UpgradeDataInterface;
@@ -24,11 +25,95 @@ class UpgradeData implements UpgradeDataInterface
2425
private $pageFactory;
2526

2627
/**
28+
* @var \Magento\Framework\DB\FieldDataConverterFactory
29+
*/
30+
private $fieldDataConverterFactory;
31+
32+
/**
33+
* @var \Magento\Framework\DB\Select\QueryModifierFactory
34+
*/
35+
private $queryModifierFactory;
36+
37+
/**
38+
* @var MetadataPool
39+
*/
40+
private $metadataPool;
41+
42+
/**
43+
* UpgradeData constructor.
44+
*
2745
* @param PageFactory $pageFactory
46+
* @param \Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory
47+
* @param \Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory
48+
* @param MetadataPool $metadataPool
2849
*/
29-
public function __construct(PageFactory $pageFactory)
30-
{
50+
public function __construct(
51+
PageFactory $pageFactory,
52+
\Magento\Framework\DB\FieldDataConverterFactory $fieldDataConverterFactory,
53+
\Magento\Framework\DB\Select\QueryModifierFactory $queryModifierFactory,
54+
MetadataPool $metadataPool
55+
) {
3156
$this->pageFactory = $pageFactory;
57+
$this->fieldDataConverterFactory = $fieldDataConverterFactory;
58+
$this->queryModifierFactory = $queryModifierFactory;
59+
$this->metadataPool = $metadataPool;
60+
}
61+
62+
/**
63+
* Upgrades data for a module
64+
*
65+
* @param ModuleDataSetupInterface $setup
66+
* @param ModuleContextInterface $context
67+
* @return void
68+
*/
69+
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
70+
{
71+
if (version_compare($context->getVersion(), '2.0.1', '<')) {
72+
$this->upgradeVersionTwoZeroOne();
73+
}
74+
if (version_compare($context->getVersion(), '2.0.2', '<')) {
75+
$this->convertWidgetConditionsToJson($setup);
76+
}
77+
}
78+
79+
/**
80+
* Upgrade data to version 2.0.2
81+
*
82+
* @param ModuleDataSetupInterface $setup
83+
* @return void
84+
*/
85+
private function convertWidgetConditionsToJson(ModuleDataSetupInterface $setup)
86+
{
87+
$fieldDataConverter = $this->fieldDataConverterFactory->create(
88+
\Magento\Cms\Setup\ContentConverter::class
89+
);
90+
91+
$queryModifier = $this->queryModifierFactory->create(
92+
'like',
93+
[
94+
'values' => [
95+
'content' => '%conditions_encoded%'
96+
]
97+
]
98+
);
99+
100+
$blockMetadata = $this->metadataPool->getMetadata(\Magento\Cms\Api\Data\BlockInterface::class);
101+
$fieldDataConverter->convert(
102+
$setup->getConnection(),
103+
$setup->getTable('cms_block'),
104+
$blockMetadata->getIdentifierField(),
105+
'content',
106+
$queryModifier
107+
);
108+
109+
$pageMetadata = $this->metadataPool->getMetadata(\Magento\Cms\Api\Data\PageInterface::class);
110+
$fieldDataConverter->convert(
111+
$setup->getConnection(),
112+
$setup->getTable('cms_page'),
113+
$pageMetadata->getIdentifierField(),
114+
'content',
115+
$queryModifier
116+
);
32117
}
33118

34119
/**
@@ -42,18 +127,14 @@ private function createPage()
42127
}
43128

44129
/**
45-
* Upgrades data for a module
130+
* Upgrade data to version 2.0.1,
46131
*
47-
* @param ModuleDataSetupInterface $setup
48-
* @param ModuleContextInterface $context
49132
* @return void
50133
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
51134
*/
52-
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
135+
private function upgradeVersionTwoZeroOne()
53136
{
54-
$setup->startSetup();
55-
if (version_compare($context->getVersion(), '2.0.1', '<')) {
56-
$newPageContent = <<<EOD
137+
$newPageContent = <<<EOD
57138
<div class="privacy-policy cms-content">
58139
<div class="message info">
59140
<span>
@@ -237,16 +318,14 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
237318
</table>
238319
</div>
239320
EOD;
240-
$privacyAndCookiePolicyPage = $this->createPage()->load(
241-
'privacy-policy-cookie-restriction-mode',
242-
'identifier'
243-
);
244-
$privacyAndCookiePolicyPageId = $privacyAndCookiePolicyPage->getId();
245-
if ($privacyAndCookiePolicyPageId) {
246-
$privacyAndCookiePolicyPage->setContent($newPageContent);
247-
$privacyAndCookiePolicyPage->save();
248-
}
321+
$privacyAndCookiePolicyPage = $this->createPage()->load(
322+
'privacy-policy-cookie-restriction-mode',
323+
'identifier'
324+
);
325+
$privacyAndCookiePolicyPageId = $privacyAndCookiePolicyPage->getId();
326+
if ($privacyAndCookiePolicyPageId) {
327+
$privacyAndCookiePolicyPage->setContent($newPageContent);
328+
$privacyAndCookiePolicyPage->save();
249329
}
250-
$setup->endSetup();
251330
}
252331
}

app/code/Magento/Cms/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_Cms" setup_version="2.0.1">
9+
<module name="Magento_Cms" setup_version="2.0.2">
1010
<sequence>
1111
<module name="Magento_Store"/>
1212
<module name="Magento_Theme"/>

app/code/Magento/Config/Test/Unit/App/Config/Type/SystemTest.php

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public function testGet($isCached)
8888
{
8989
$path = 'default/dev/unsecure/url';
9090
$url = 'http://magento.test/';
91-
$data = [
91+
$unserializedData = [
9292
'default' => [
9393
'dev' => [
9494
'unsecure' => [
@@ -97,41 +97,42 @@ public function testGet($isCached)
9797
]
9898
]
9999
];
100+
$serializedDataString = '{"serialized-data"}';
100101

101102
$this->cache->expects($this->once())
102103
->method('load')
103104
->with(System::CONFIG_TYPE)
104-
->willReturn($isCached ? $data : null);
105+
->willReturn($isCached ? $unserializedData : null);
105106

106107
if ($isCached) {
107108
$this->serializer->expects($this->once())
108109
->method('unserialize')
109-
->willReturn($data);
110+
->willReturn($unserializedData);
110111
}
111112

112113
if (!$isCached) {
113114
$this->serializer->expects($this->once())
114115
->method('serialize')
115-
->willReturn(serialize($data));
116+
->willReturn($serializedDataString);
116117
$this->source->expects($this->once())
117118
->method('get')
118-
->willReturn($data);
119+
->willReturn($unserializedData);
119120
$this->fallback->expects($this->once())
120121
->method('process')
121-
->with($data)
122+
->with($unserializedData)
122123
->willReturnArgument(0);
123124
$this->preProcessor->expects($this->once())
124125
->method('process')
125-
->with($data)
126+
->with($unserializedData)
126127
->willReturnArgument(0);
127128
$this->postProcessor->expects($this->once())
128129
->method('process')
129-
->with($data)
130+
->with($unserializedData)
130131
->willReturnArgument(0);
131132
$this->cache->expects($this->once())
132133
->method('save')
133134
->with(
134-
serialize($data),
135+
$serializedDataString,
135136
System::CONFIG_TYPE,
136137
[System::CACHE_TAG]
137138
);

app/code/Magento/Quote/Setup/ConvertSerializedDataToJson.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,12 @@ public function convert()
7272
'payment_id',
7373
'additional_information'
7474
);
75+
$fieldDataConverter->convert(
76+
$this->quoteSetup->getConnection(),
77+
$this->quoteSetup->getTable('quote_payment'),
78+
'payment_id',
79+
'additional_data'
80+
);
7581
$fieldDataConverter->convert(
7682
$this->quoteSetup->getConnection(),
7783
$this->quoteSetup->getTable('quote_address'),

0 commit comments

Comments
 (0)