Skip to content

Commit 9c14af7

Browse files
authored
Merge pull request #1528 from magento-engcom/2.2-develop-prs
[EngCom] Public Pull Requests2.2
2 parents 2fccb81 + 5fc2169 commit 9c14af7

File tree

5 files changed

+153
-42
lines changed

5 files changed

+153
-42
lines changed

app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,21 @@
4141
<item name="total" xsi:type="string" translate="true">Row Total</item>
4242
</argument>
4343
</arguments>
44-
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/view/items/renderer/default.phtml">
45-
<arguments>
46-
<argument name="columns" xsi:type="array">
47-
<item name="product" xsi:type="string" translate="false">col-product</item>
48-
<item name="status" xsi:type="string" translate="false">col-status</item>
49-
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
50-
<item name="price" xsi:type="string" translate="false">col-price</item>
51-
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
52-
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
53-
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
54-
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
55-
<item name="discont" xsi:type="string" translate="false">col-discont</item>
56-
<item name="total" xsi:type="string" translate="false">col-total</item>
57-
</argument>
58-
</arguments>
44+
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" name="default_order_items_renderer" template="Magento_Sales::order/view/items/renderer/default.phtml">
45+
<arguments>
46+
<argument name="columns" xsi:type="array">
47+
<item name="product" xsi:type="string" translate="false">col-product</item>
48+
<item name="status" xsi:type="string" translate="false">col-status</item>
49+
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
50+
<item name="price" xsi:type="string" translate="false">col-price</item>
51+
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
52+
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
53+
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
54+
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
55+
<item name="discont" xsi:type="string" translate="false">col-discont</item>
56+
<item name="total" xsi:type="string" translate="false">col-total</item>
57+
</argument>
58+
</arguments>
5959
</block>
6060
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
6161
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>

app/design/frontend/Magento/luma/Magento_Theme/web/css/source/_module.less

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -333,6 +333,7 @@
333333
.widget.block {
334334
.lib-css(margin, @indent__base 0);
335335
}
336+
.links .widget.block { margin: 0; }
336337
}
337338

338339
.no-display:extend(.abs-no-display all) {

dev/tests/unit/framework/bootstrap.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
error_reporting(E_ALL);
2121
ini_set('display_errors', 1);
2222

23+
/* For data consistency between displaying (printing) and serialization a float number */
24+
ini_set('precision', 14);
25+
ini_set('serialize_precision', 14);
26+
2327
/**
2428
* Set custom error handler
2529
*/

lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,22 @@ public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVers
5050
public function beforeDispatch(FrontController $subject, RequestInterface $request)
5151
{
5252
if (!$this->cache->load('db_is_up_to_date')) {
53-
$errors = $this->dbVersionInfo->getDbVersionErrors();
54-
55-
if ($errors) {
53+
list($versionTooLowErrors, $versionTooHighErrors) = array_values($this->getGroupedDbVersionErrors());
54+
if ($versionTooHighErrors) {
55+
$message = 'Please update your modules: '
56+
. "Run \"composer install\" from the Magento root directory.\n"
57+
. "The following modules are outdated:\n%1";
58+
throw new LocalizedException(
59+
new Phrase($message, [implode("\n", $this->formatVersionTooHighErrors($versionTooHighErrors))])
60+
);
61+
} elseif ($versionTooLowErrors) {
5662
$message = 'Please upgrade your database: '
5763
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
5864
. "The following modules are outdated:\n%1";
5965

60-
throw new LocalizedException(new Phrase($message, [implode("\n", $this->formatErrors($errors))]));
66+
throw new LocalizedException(
67+
new Phrase($message, [implode("\n", $this->formatVersionTooLowErrors($versionTooLowErrors))])
68+
);
6169
} else {
6270
$this->cache->save('true', 'db_is_up_to_date');
6371
}
@@ -70,7 +78,7 @@ public function beforeDispatch(FrontController $subject, RequestInterface $reque
7078
* @param array $errorsData array of error data from getOutOfDateDbErrors
7179
* @return array Messages that can be used to log the error
7280
*/
73-
private function formatErrors($errorsData)
81+
private function formatVersionTooLowErrors($errorsData)
7482
{
7583
$formattedErrors = [];
7684

@@ -82,4 +90,50 @@ private function formatErrors($errorsData)
8290

8391
return $formattedErrors;
8492
}
93+
94+
/**
95+
* Format each error in the error data from getOutOfDataDbErrors into a single message
96+
*
97+
* @param array $errorsData array of error data from getOutOfDateDbErrors
98+
* @return array Messages that can be used to log the error
99+
*/
100+
private function formatVersionTooHighErrors($errorsData)
101+
{
102+
$formattedErrors = [];
103+
104+
foreach ($errorsData as $error) {
105+
$formattedErrors[] = $error[DbVersionInfo::KEY_MODULE] . ' db ' . $error[DbVersionInfo::KEY_TYPE]
106+
. ' version: defined in codebase - ' . $error[DbVersionInfo::KEY_REQUIRED]
107+
. ', currently installed - ' . $error[DbVersionInfo::KEY_CURRENT];
108+
}
109+
110+
return $formattedErrors;
111+
}
112+
113+
/**
114+
* Return DB version errors grouped by 'version_too_low' and 'version_too_high'
115+
*
116+
* @return mixed
117+
*/
118+
private function getGroupedDbVersionErrors()
119+
{
120+
$allDbVersionErrors = $this->dbVersionInfo->getDbVersionErrors();
121+
return array_reduce(
122+
(array)$allDbVersionErrors,
123+
function ($carry, $item) {
124+
if ($item[DbVersionInfo::KEY_CURRENT] === 'none'
125+
|| $item[DbVersionInfo::KEY_CURRENT] < $item[DbVersionInfo::KEY_REQUIRED]
126+
) {
127+
$carry['version_too_low'][] = $item;
128+
} else {
129+
$carry['version_too_high'][] = $item;
130+
}
131+
return $carry;
132+
},
133+
[
134+
'version_too_low' => [],
135+
'version_too_high' => [],
136+
]
137+
);
138+
}
85139
}

lib/internal/Magento/Framework/Test/Unit/Module/Plugin/DbStatusValidatorTest.php

Lines changed: 74 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -99,28 +99,11 @@ public function testBeforeDispatchOutOfDateNoErrors()
9999
$this->plugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
100100
}
101101

102-
public function testBeforeDispatchOutOfDateWithErrors()
102+
/**
103+
* @dataProvider beforeDispatchOutOfDateWithErrorsDataProvider
104+
*/
105+
public function testBeforeDispatchOutOfDateWithErrors(array $errors, string $expectedMessage)
103106
{
104-
$errors = [
105-
[
106-
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
107-
DbVersionInfo::KEY_TYPE => 'schema',
108-
DbVersionInfo::KEY_CURRENT => '3.3.3',
109-
DbVersionInfo::KEY_REQUIRED => '4.4.4'
110-
],
111-
[
112-
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
113-
DbVersionInfo::KEY_TYPE => 'data',
114-
DbVersionInfo::KEY_CURRENT => '2.8.7',
115-
DbVersionInfo::KEY_REQUIRED => '5.1.6'
116-
]
117-
];
118-
$message = 'Please upgrade your database: '
119-
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
120-
. "The following modules are outdated:\n"
121-
. "Magento_Module1 schema: current version - 3.3.3, required version - 4.4.4\n"
122-
. "Magento_Module2 data: current version - 2.8.7, required version - 5.1.6";
123-
124107
$this->cacheMock->expects(static::any())
125108
->method('load')
126109
->with('db_is_up_to_date')
@@ -131,7 +114,76 @@ public function testBeforeDispatchOutOfDateWithErrors()
131114
$this->cacheMock->expects(static::never())
132115
->method('save');
133116

134-
$this->expectException(LocalizedException::class, $message);
117+
$this->expectException(LocalizedException::class, $expectedMessage);
118+
$this->expectExceptionMessage($expectedMessage);
135119
$this->plugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
136120
}
121+
122+
public static function beforeDispatchOutOfDateWithErrorsDataProvider()
123+
{
124+
return [
125+
'module versions too low' => [
126+
'errors' => [
127+
[
128+
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
129+
DbVersionInfo::KEY_TYPE => 'schema',
130+
DbVersionInfo::KEY_CURRENT => 'none',
131+
DbVersionInfo::KEY_REQUIRED => '4.4.4'
132+
],
133+
[
134+
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
135+
DbVersionInfo::KEY_TYPE => 'data',
136+
DbVersionInfo::KEY_CURRENT => '2.8.7',
137+
DbVersionInfo::KEY_REQUIRED => '5.1.6'
138+
],
139+
],
140+
'expectedMessage' => 'Please upgrade your database: '
141+
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
142+
. "The following modules are outdated:\n"
143+
. "Magento_Module1 schema: current version - none, required version - 4.4.4\n"
144+
. "Magento_Module2 data: current version - 2.8.7, required version - 5.1.6"
145+
],
146+
'module versions too high' => [
147+
'errors' => [
148+
[
149+
DbVersionInfo::KEY_MODULE => 'Magento_Module3',
150+
DbVersionInfo::KEY_TYPE => 'schema',
151+
DbVersionInfo::KEY_CURRENT => '2.0.0',
152+
DbVersionInfo::KEY_REQUIRED => '1.0.0'
153+
],
154+
[
155+
DbVersionInfo::KEY_MODULE => 'Magento_Module4',
156+
DbVersionInfo::KEY_TYPE => 'data',
157+
DbVersionInfo::KEY_CURRENT => '1.0.1',
158+
DbVersionInfo::KEY_REQUIRED => '1.0.0'
159+
],
160+
],
161+
'expectedMessage' => "Please update your modules: "
162+
. "Run \"composer install\" from the Magento root directory.\n"
163+
. "The following modules are outdated:\n"
164+
. "Magento_Module3 db schema version: defined in codebase - 1.0.0, currently installed - 2.0.0\n"
165+
. "Magento_Module4 db data version: defined in codebase - 1.0.0, currently installed - 1.0.1",
166+
],
167+
'some versions too high, some too low' => [
168+
'errors' => [
169+
[
170+
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
171+
DbVersionInfo::KEY_TYPE => 'schema',
172+
DbVersionInfo::KEY_CURRENT => '2.0.0',
173+
DbVersionInfo::KEY_REQUIRED => '1.0.0'
174+
],
175+
[
176+
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
177+
DbVersionInfo::KEY_TYPE => 'schema',
178+
DbVersionInfo::KEY_CURRENT => '1.0.0',
179+
DbVersionInfo::KEY_REQUIRED => '2.0.0'
180+
],
181+
],
182+
'expectedMessage' => "Please update your modules: "
183+
. "Run \"composer install\" from the Magento root directory.\n"
184+
. "The following modules are outdated:\n"
185+
. "Magento_Module1 db schema version: defined in codebase - 1.0.0, currently installed - 2.0.0"
186+
]
187+
];
188+
}
137189
}

0 commit comments

Comments
 (0)