Skip to content

Commit

Permalink
Merge pull request #1528 from magento-engcom/2.2-develop-prs
Browse files Browse the repository at this point in the history
[EngCom] Public Pull Requests2.2
  • Loading branch information
vrann authored Sep 28, 2017
2 parents 2fccb81 + 5fc2169 commit 9c14af7
Show file tree
Hide file tree
Showing 5 changed files with 153 additions and 42 deletions.
30 changes: 15 additions & 15 deletions app/code/Magento/Sales/view/adminhtml/layout/sales_order_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,21 @@
<item name="total" xsi:type="string" translate="true">Row Total</item>
</argument>
</arguments>
<block class="Magento\Sales\Block\Adminhtml\Order\View\Items\Renderer\DefaultRenderer" as="default" template="Magento_Sales::order/view/items/renderer/default.phtml">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
</argument>
</arguments>
<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">
<arguments>
<argument name="columns" xsi:type="array">
<item name="product" xsi:type="string" translate="false">col-product</item>
<item name="status" xsi:type="string" translate="false">col-status</item>
<item name="price-original" xsi:type="string" translate="false">col-price-original</item>
<item name="price" xsi:type="string" translate="false">col-price</item>
<item name="qty" xsi:type="string" translate="false">col-ordered-qty</item>
<item name="subtotal" xsi:type="string" translate="false">col-subtotal</item>
<item name="tax-amount" xsi:type="string" translate="false">col-tax-amount</item>
<item name="tax-percent" xsi:type="string" translate="false">col-tax-percent</item>
<item name="discont" xsi:type="string" translate="false">col-discont</item>
<item name="total" xsi:type="string" translate="false">col-total</item>
</argument>
</arguments>
</block>
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Qty" name="column_qty" template="Magento_Sales::items/column/qty.phtml" group="column"/>
<block class="Magento\Sales\Block\Adminhtml\Items\Column\Name" name="column_name" template="Magento_Sales::items/column/name.phtml" group="column"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@
.widget.block {
.lib-css(margin, @indent__base 0);
}
.links .widget.block { margin: 0; }
}

.no-display:extend(.abs-no-display all) {
Expand Down
4 changes: 4 additions & 0 deletions dev/tests/unit/framework/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
error_reporting(E_ALL);
ini_set('display_errors', 1);

/* For data consistency between displaying (printing) and serialization a float number */
ini_set('precision', 14);
ini_set('serialize_precision', 14);

/**
* Set custom error handler
*/
Expand Down
64 changes: 59 additions & 5 deletions lib/internal/Magento/Framework/Module/Plugin/DbStatusValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,22 @@ public function __construct(FrontendCacheInterface $cache, DbVersionInfo $dbVers
public function beforeDispatch(FrontController $subject, RequestInterface $request)
{
if (!$this->cache->load('db_is_up_to_date')) {
$errors = $this->dbVersionInfo->getDbVersionErrors();

if ($errors) {
list($versionTooLowErrors, $versionTooHighErrors) = array_values($this->getGroupedDbVersionErrors());
if ($versionTooHighErrors) {
$message = 'Please update your modules: '
. "Run \"composer install\" from the Magento root directory.\n"
. "The following modules are outdated:\n%1";
throw new LocalizedException(
new Phrase($message, [implode("\n", $this->formatVersionTooHighErrors($versionTooHighErrors))])
);
} elseif ($versionTooLowErrors) {
$message = 'Please upgrade your database: '
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
. "The following modules are outdated:\n%1";

throw new LocalizedException(new Phrase($message, [implode("\n", $this->formatErrors($errors))]));
throw new LocalizedException(
new Phrase($message, [implode("\n", $this->formatVersionTooLowErrors($versionTooLowErrors))])
);
} else {
$this->cache->save('true', 'db_is_up_to_date');
}
Expand All @@ -70,7 +78,7 @@ public function beforeDispatch(FrontController $subject, RequestInterface $reque
* @param array $errorsData array of error data from getOutOfDateDbErrors
* @return array Messages that can be used to log the error
*/
private function formatErrors($errorsData)
private function formatVersionTooLowErrors($errorsData)
{
$formattedErrors = [];

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

return $formattedErrors;
}

/**
* Format each error in the error data from getOutOfDataDbErrors into a single message
*
* @param array $errorsData array of error data from getOutOfDateDbErrors
* @return array Messages that can be used to log the error
*/
private function formatVersionTooHighErrors($errorsData)
{
$formattedErrors = [];

foreach ($errorsData as $error) {
$formattedErrors[] = $error[DbVersionInfo::KEY_MODULE] . ' db ' . $error[DbVersionInfo::KEY_TYPE]
. ' version: defined in codebase - ' . $error[DbVersionInfo::KEY_REQUIRED]
. ', currently installed - ' . $error[DbVersionInfo::KEY_CURRENT];
}

return $formattedErrors;
}

/**
* Return DB version errors grouped by 'version_too_low' and 'version_too_high'
*
* @return mixed
*/
private function getGroupedDbVersionErrors()
{
$allDbVersionErrors = $this->dbVersionInfo->getDbVersionErrors();
return array_reduce(
(array)$allDbVersionErrors,
function ($carry, $item) {
if ($item[DbVersionInfo::KEY_CURRENT] === 'none'
|| $item[DbVersionInfo::KEY_CURRENT] < $item[DbVersionInfo::KEY_REQUIRED]
) {
$carry['version_too_low'][] = $item;
} else {
$carry['version_too_high'][] = $item;
}
return $carry;
},
[
'version_too_low' => [],
'version_too_high' => [],
]
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,28 +99,11 @@ public function testBeforeDispatchOutOfDateNoErrors()
$this->plugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
}

public function testBeforeDispatchOutOfDateWithErrors()
/**
* @dataProvider beforeDispatchOutOfDateWithErrorsDataProvider
*/
public function testBeforeDispatchOutOfDateWithErrors(array $errors, string $expectedMessage)
{
$errors = [
[
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
DbVersionInfo::KEY_TYPE => 'schema',
DbVersionInfo::KEY_CURRENT => '3.3.3',
DbVersionInfo::KEY_REQUIRED => '4.4.4'
],
[
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
DbVersionInfo::KEY_TYPE => 'data',
DbVersionInfo::KEY_CURRENT => '2.8.7',
DbVersionInfo::KEY_REQUIRED => '5.1.6'
]
];
$message = 'Please upgrade your database: '
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
. "The following modules are outdated:\n"
. "Magento_Module1 schema: current version - 3.3.3, required version - 4.4.4\n"
. "Magento_Module2 data: current version - 2.8.7, required version - 5.1.6";

$this->cacheMock->expects(static::any())
->method('load')
->with('db_is_up_to_date')
Expand All @@ -131,7 +114,76 @@ public function testBeforeDispatchOutOfDateWithErrors()
$this->cacheMock->expects(static::never())
->method('save');

$this->expectException(LocalizedException::class, $message);
$this->expectException(LocalizedException::class, $expectedMessage);
$this->expectExceptionMessage($expectedMessage);
$this->plugin->beforeDispatch($this->frontControllerMock, $this->requestMock);
}

public static function beforeDispatchOutOfDateWithErrorsDataProvider()
{
return [
'module versions too low' => [
'errors' => [
[
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
DbVersionInfo::KEY_TYPE => 'schema',
DbVersionInfo::KEY_CURRENT => 'none',
DbVersionInfo::KEY_REQUIRED => '4.4.4'
],
[
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
DbVersionInfo::KEY_TYPE => 'data',
DbVersionInfo::KEY_CURRENT => '2.8.7',
DbVersionInfo::KEY_REQUIRED => '5.1.6'
],
],
'expectedMessage' => 'Please upgrade your database: '
. "Run \"bin/magento setup:upgrade\" from the Magento root directory.\n"
. "The following modules are outdated:\n"
. "Magento_Module1 schema: current version - none, required version - 4.4.4\n"
. "Magento_Module2 data: current version - 2.8.7, required version - 5.1.6"
],
'module versions too high' => [
'errors' => [
[
DbVersionInfo::KEY_MODULE => 'Magento_Module3',
DbVersionInfo::KEY_TYPE => 'schema',
DbVersionInfo::KEY_CURRENT => '2.0.0',
DbVersionInfo::KEY_REQUIRED => '1.0.0'
],
[
DbVersionInfo::KEY_MODULE => 'Magento_Module4',
DbVersionInfo::KEY_TYPE => 'data',
DbVersionInfo::KEY_CURRENT => '1.0.1',
DbVersionInfo::KEY_REQUIRED => '1.0.0'
],
],
'expectedMessage' => "Please update your modules: "
. "Run \"composer install\" from the Magento root directory.\n"
. "The following modules are outdated:\n"
. "Magento_Module3 db schema version: defined in codebase - 1.0.0, currently installed - 2.0.0\n"
. "Magento_Module4 db data version: defined in codebase - 1.0.0, currently installed - 1.0.1",
],
'some versions too high, some too low' => [
'errors' => [
[
DbVersionInfo::KEY_MODULE => 'Magento_Module1',
DbVersionInfo::KEY_TYPE => 'schema',
DbVersionInfo::KEY_CURRENT => '2.0.0',
DbVersionInfo::KEY_REQUIRED => '1.0.0'
],
[
DbVersionInfo::KEY_MODULE => 'Magento_Module2',
DbVersionInfo::KEY_TYPE => 'schema',
DbVersionInfo::KEY_CURRENT => '1.0.0',
DbVersionInfo::KEY_REQUIRED => '2.0.0'
],
],
'expectedMessage' => "Please update your modules: "
. "Run \"composer install\" from the Magento root directory.\n"
. "The following modules are outdated:\n"
. "Magento_Module1 db schema version: defined in codebase - 1.0.0, currently installed - 2.0.0"
]
];
}
}

0 comments on commit 9c14af7

Please sign in to comment.