Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit 14eeea2

Browse files
authored
🔃 [EngCom] Public Pull Requests - 2.3-develop
Accepted Public Pull Requests: - magento-engcom/magento2ce#1195: Ability to switch to default mode[forwardport]. (by @nmalevanec) - magento-engcom/magento2ce#1193: Format generated config files using the short array syntax[forwardport]. (by @nmalevanec) - magento/magento2#13012: [Port to 2.3-develop] Add trim filter to first, middle and lastname. (by @wardcapp) - magento/magento2#12949: [Backport #12668 into 2.3-develop] Fix for reverting stock twice for cancelled orders (by @dverkade) Fixed GitHub Issues: - magento/magento2#4292: Why can't one switch back to default mode ? (reported by @digitalpianism) has been fixed in magento-engcom/magento2ce#1195 by @nmalevanec in 2.3-develop branch Related commits: 1. 3967190 - magento/magento2#758: Coding standards: arrays (reported by @tzyganu) has been fixed in magento-engcom/magento2ce#1193 by @nmalevanec in 2.3-develop branch Related commits: 1. 6d86db1 - magento/magento2#10415: Customer First and Last names not being trimmed of leading and trailing spaces on save. (reported by @spyrule) has been fixed in magento/magento2#13012 by @wardcapp in 2.3-develop branch Related commits: 1. e8dad7a 2. 9a45695 3. 03f250a - magento/magento2#9969: Cancel order and restore quote methods increase stocks twice (reported by @simpleadm) has been fixed in magento/magento2#12949 by @dverkade in 2.3-develop branch Related commits: 1. 1055076
2 parents 3d0135f + 22a634c commit 14eeea2

File tree

10 files changed

+194
-37
lines changed

10 files changed

+194
-37
lines changed

app/code/Magento/CatalogInventory/etc/events.xml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,6 @@
2727
<event name="sales_model_service_quote_submit_failure">
2828
<observer name="inventory" instance="Magento\CatalogInventory\Observer\RevertQuoteInventoryObserver"/>
2929
</event>
30-
<event name="restore_quote">
31-
<observer name="inventory" instance="Magento\CatalogInventory\Observer\RevertQuoteInventoryObserver"/>
32-
</event>
3330
<event name="sales_order_item_cancel">
3431
<observer name="inventory" instance="Magento\CatalogInventory\Observer\CancelOrderItemObserver"/>
3532
</event>

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

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,10 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
159159
$this->upgradeVersionTwoZeroTwelve($customerSetup);
160160
}
161161

162+
if (version_compare($context->getVersion(), '2.0.13', '<')) {
163+
$this->upgradeVersionTwoZeroThirteen($customerSetup);
164+
}
165+
162166
$indexer = $this->indexerRegistry->get(Customer::CUSTOMER_GRID_INDEXER_ID);
163167
$indexer->reindexAll();
164168
$this->eavConfig->clear();
@@ -663,4 +667,36 @@ private function upgradeCustomerPasswordResetlinkExpirationPeriodConfig($setup)
663667
['path = ?' => \Magento\Customer\Model\Customer::XML_PATH_CUSTOMER_RESET_PASSWORD_LINK_EXPIRATION_PERIOD]
664668
);
665669
}
670+
671+
/**
672+
* @param CustomerSetup $customerSetup
673+
*/
674+
private function upgradeVersionTwoZeroThirteen(CustomerSetup $customerSetup)
675+
{
676+
$entityAttributes = [
677+
'customer_address' => [
678+
'firstname' => [
679+
'input_filter' => 'trim'
680+
],
681+
'lastname' => [
682+
'input_filter' => 'trim'
683+
],
684+
'middlename' => [
685+
'input_filter' => 'trim'
686+
],
687+
],
688+
'customer' => [
689+
'firstname' => [
690+
'input_filter' => 'trim'
691+
],
692+
'lastname' => [
693+
'input_filter' => 'trim'
694+
],
695+
'middlename' => [
696+
'input_filter' => 'trim'
697+
],
698+
],
699+
];
700+
$this->upgradeAttributes($entityAttributes, $customerSetup);
701+
}
666702
}

app/code/Magento/Customer/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_Customer" setup_version="2.0.12">
9+
<module name="Magento_Customer" setup_version="2.0.13">
1010
<sequence>
1111
<module name="Magento_Eav"/>
1212
<module name="Magento_Directory"/>

app/code/Magento/Deploy/Console/Command/SetModeCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
101101
$modeController->enableProductionMode();
102102
}
103103
break;
104+
case State::MODE_DEFAULT:
105+
$modeController->enableDefaultMode();
106+
break;
104107
default:
105108
throw new LocalizedException(__('Cannot switch into given mode "%1"', $toMode));
106109
}

app/code/Magento/Deploy/Model/Mode.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,25 @@ public function enableDeveloperMode()
167167
$this->setStoreMode(State::MODE_DEVELOPER);
168168
}
169169

170+
/**
171+
* Enable Default mode.
172+
*
173+
* @return void
174+
*/
175+
public function enableDefaultMode()
176+
{
177+
$this->filesystem->cleanupFilesystem(
178+
[
179+
DirectoryList::CACHE,
180+
DirectoryList::GENERATED_CODE,
181+
DirectoryList::GENERATED_METADATA,
182+
DirectoryList::TMP_MATERIALIZATION_DIR,
183+
DirectoryList::STATIC_VIEW,
184+
]
185+
);
186+
$this->setStoreMode(State::MODE_DEFAULT);
187+
}
188+
170189
/**
171190
* Get current mode information
172191
*

app/code/Magento/Deploy/Test/Unit/Console/Command/SetModeCommandTest.php

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

88
use Magento\Deploy\Console\Command\SetModeCommand;
99
use Symfony\Component\Console\Tester\CommandTester;
10-
use Magento\Framework\App\State;
1110

1211
/**
1312
* @package Magento\Deploy\Test\Unit\Console\Command
@@ -67,6 +66,18 @@ public function testSetDeveloperMode()
6766
);
6867
}
6968

69+
public function testSetDefaultMode()
70+
{
71+
$this->modeMock->expects($this->once())->method('enableDefaultMode');
72+
73+
$tester = new CommandTester($this->command);
74+
$tester->execute(['mode' => 'default']);
75+
$this->assertContains(
76+
"default mode",
77+
$tester->getDisplay()
78+
);
79+
}
80+
7081
public function testSetProductionSkipCompilation()
7182
{
7283
$this->modeMock->expects($this->once())->method('enableProductionModeMinimal');

dev/tests/api-functional/testsuite/Magento/Customer/Api/CustomerMetadataTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function getAttributeMetadataDataProvider()
6363
Customer::FIRSTNAME,
6464
[
6565
AttributeMetadata::FRONTEND_INPUT => 'text',
66-
AttributeMetadata::INPUT_FILTER => '',
66+
AttributeMetadata::INPUT_FILTER => 'trim',
6767
AttributeMetadata::STORE_LABEL => 'First Name',
6868
AttributeMetadata::MULTILINE_COUNT => 0,
6969
AttributeMetadata::VALIDATION_RULES => [

lib/internal/Magento/Framework/App/DeploymentConfig/Writer/PhpFormatter.php

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
*/
1212
class PhpFormatter implements FormatterInterface
1313
{
14+
/**
15+
* 2 space indentation for array formatting.
16+
*/
17+
const INDENT = ' ';
18+
1419
/**
1520
* Format deployment configuration.
1621
* If $comments is present, each item will be added
@@ -21,9 +26,9 @@ class PhpFormatter implements FormatterInterface
2126
public function format($data, array $comments = [])
2227
{
2328
if (!empty($comments) && is_array($data)) {
24-
return "<?php\nreturn array (\n" . $this->formatData($data, $comments) . "\n);\n";
29+
return "<?php\nreturn [\n" . $this->formatData($data, $comments) . "\n];\n";
2530
}
26-
return "<?php\nreturn " . var_export($data, true) . ";\n";
31+
return "<?php\nreturn " . $this->varExportShort($data, true) . ";\n";
2732
}
2833

2934
/**
@@ -51,18 +56,43 @@ private function formatData($data, $comments = [], $prefix = ' ')
5156
$elements[] = $prefix . " */";
5257
}
5358

54-
$elements[] = $prefix . var_export($key, true) . ' => ' .
55-
(!is_array($value) ? var_export($value, true) . ',' : '');
59+
$elements[] = $prefix . $this->varExportShort($key) . ' => ' .
60+
(!is_array($value) ? $this->varExportShort($value) . ',' : '');
5661

5762
if (is_array($value)) {
58-
$elements[] = $prefix . 'array (';
63+
$elements[] = $prefix . '[';
5964
$elements[] = $this->formatData($value, [], ' ' . $prefix);
60-
$elements[] = $prefix . '),';
65+
$elements[] = $prefix . '],';
6166
}
6267
}
6368
return implode("\n", $elements);
6469
}
6570

6671
return var_export($data, true);
6772
}
73+
74+
/**
75+
* If variable to export is an array, format with the php >= 5.4 short array syntax. Otherwise use
76+
* default var_export functionality.
77+
*
78+
* @param mixed $var
79+
* @param integer $depth
80+
* @return string
81+
*/
82+
private function varExportShort($var, int $depth = 0)
83+
{
84+
if (!is_array($var)) {
85+
return var_export($var, true);
86+
}
87+
88+
$indexed = array_keys($var) === range(0, count($var) - 1);
89+
$expanded = [];
90+
foreach ($var as $key => $value) {
91+
$expanded[] = str_repeat(self::INDENT, $depth)
92+
. ($indexed ? '' : $this->varExportShort($key) . ' => ')
93+
. $this->varExportShort($value, $depth + 1);
94+
}
95+
96+
return sprintf("[\n%s\n%s]", implode(",\n", $expanded), str_repeat(self::INDENT, $depth - 1));
97+
}
6898
}

lib/internal/Magento/Framework/App/Test/Unit/DeploymentConfig/Writer/PhpFormatterTest.php

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,68 +55,68 @@ public function formatWithCommentDataProvider()
5555
];
5656
$expectedResult1 = <<<TEXT
5757
<?php
58-
return array (
58+
return [
5959
'ns1' =>
60-
array (
60+
[
6161
's1' =>
62-
array (
62+
[
6363
0 => 's11',
6464
1 => 's12',
65-
),
65+
],
6666
's2' =>
67-
array (
67+
[
6868
0 => 's21',
6969
1 => 's22',
70-
),
71-
),
70+
],
71+
],
7272
/**
7373
* For the section: ns2
7474
* comment for namespace 2
7575
*/
7676
'ns2' =>
77-
array (
77+
[
7878
's1' =>
79-
array (
79+
[
8080
0 => 's11',
81-
),
82-
),
81+
],
82+
],
8383
'ns3' => 'just text',
8484
'ns4' => 'just text',
85-
);
85+
];
8686
8787
TEXT;
8888
$expectedResult2 = <<<TEXT
8989
<?php
90-
return array (
90+
return [
9191
/**
9292
* For the section: ns1
9393
* comment for' namespace 1
9494
*/
9595
'ns1' =>
96-
array (
96+
[
9797
's1' =>
98-
array (
98+
[
9999
0 => 's11',
100100
1 => 's12',
101-
),
101+
],
102102
's2' =>
103-
array (
103+
[
104104
0 => 's21',
105105
1 => 's22',
106-
),
107-
),
106+
],
107+
],
108108
/**
109109
* For the section: ns2
110110
* comment for namespace 2.
111111
* Next comment for' namespace 2
112112
*/
113113
'ns2' =>
114-
array (
114+
[
115115
's1' =>
116-
array (
116+
[
117117
0 => 's11',
118-
),
119-
),
118+
],
119+
],
120120
/**
121121
* For the section: ns3
122122
* comment for" namespace 3
@@ -127,15 +127,39 @@ public function formatWithCommentDataProvider()
127127
* comment for namespace 4
128128
*/
129129
'ns4' => 'just text',
130-
);
130+
];
131+
132+
TEXT;
133+
134+
$expectedResult3 = <<<TEXT
135+
<?php
136+
return [
137+
'ns1' => [
138+
's1' => [
139+
's11',
140+
's12'
141+
],
142+
's2' => [
143+
's21',
144+
's22'
145+
]
146+
],
147+
'ns2' => [
148+
's1' => [
149+
's11'
150+
]
151+
],
152+
'ns3' => 'just text',
153+
'ns4' => 'just text'
154+
];
131155
132156
TEXT;
133157
return [
134158
['string', [], "<?php\nreturn 'string';\n"],
135159
['string', ['comment'], "<?php\nreturn 'string';\n"],
136-
[$array, [], "<?php\nreturn " . var_export($array, true) . ";\n"],
137160
[$array, $comments1, $expectedResult1],
138161
[$array, $comments2, $expectedResult2],
162+
[$array, [], $expectedResult3],
139163
];
140164
}
141165
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/**
8+
* Form Input/Output Trim Filter
9+
*
10+
* @author Magento Core Team <[email protected]>
11+
*/
12+
namespace Magento\Framework\Data\Form\Filter;
13+
14+
class Trim implements \Magento\Framework\Data\Form\Filter\FilterInterface
15+
{
16+
/**
17+
* Returns the result of filtering $value
18+
*
19+
* @param string $value
20+
* @return string
21+
*/
22+
public function inputFilter($value)
23+
{
24+
return trim($value, ' ');
25+
}
26+
27+
/**
28+
* Returns the result of filtering $value
29+
*
30+
* @param string $value
31+
* @return string
32+
*/
33+
public function outputFilter($value)
34+
{
35+
return $value;
36+
}
37+
}

0 commit comments

Comments
 (0)