Skip to content

Commit b456cd1

Browse files
committed
Merge pull request #164 from magento-mpi/develop
[MPI] - bug fix
2 parents 8dd4940 + 78bef61 commit b456cd1

File tree

35 files changed

+276
-112
lines changed

35 files changed

+276
-112
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ protected function _convertDate($date)
205205
\IntlDateFormatter::NONE,
206206
$adminTimeZone
207207
);
208-
$simpleRes = new \DateTime('@' . $formatter->parse($date), $adminTimeZone);
208+
$simpleRes = new \DateTime(null, $adminTimeZone);
209+
$simpleRes->setTimestamp($formatter->parse($date));
209210
$simpleRes->setTime(0, 0, 0);
210211
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
211212
return $simpleRes;

app/code/Magento/Backup/Model/Backup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function load($fileName, $filePath)
152152
'extension' => $this->_helper->getExtensionByType($backupData->getType()),
153153
'display_name' => $this->_helper->nameToDisplayName($backupData->getName()),
154154
'name' => $backupData->getName(),
155-
'date_object' => new \DateTime('@' . $backupData->getTime()),
155+
'date_object' => (new \DateTime())->setTimestamp($backupData->getTime()),
156156
]
157157
);
158158

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function prepareForCart()
165165
$timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute'];
166166
}
167167

168-
$date = new \DateTime('@' . $timestamp);
168+
$date = (new \DateTime())->setTimestamp($timestamp);
169169
$result = $date->format('Y-m-d H:i:s');
170170

171171
// Save date in internal format to avoid locale date bugs
@@ -188,19 +188,22 @@ public function getFormattedOptionValue($optionValue)
188188
{
189189
if ($this->_formattedOptionValue === null) {
190190
if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) {
191-
$format = $this->_localeDate->getDateFormat(
192-
\IntlDateFormatter::MEDIUM
191+
$result = $this->_localeDate->formatDateTime(
192+
new \DateTime($optionValue),
193+
\IntlDateFormatter::MEDIUM,
194+
\IntlDateFormatter::NONE
193195
);
194-
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
195196
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) {
196-
$format = $this->_localeDate->getDateTimeFormat(
197+
$result = $this->_localeDate->formatDateTime(
198+
new \DateTime($optionValue),
199+
\IntlDateFormatter::SHORT,
197200
\IntlDateFormatter::SHORT
198201
);
199-
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
200202
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
201-
$result = \IntlDateFormatter::formatObject(
203+
$result = $this->_localeDate->formatDateTime(
202204
new \DateTime($optionValue),
203-
$this->is24hTimeFormat() ? 'H:i' : 'h:i a'
205+
\IntlDateFormatter::NONE,
206+
\IntlDateFormatter::SHORT
204207
);
205208
} else {
206209
$result = $optionValue;

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ protected function _saveProducts()
10861086
$storeIds = [0];
10871087

10881088
if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1089-
$attrValue = new \DateTime('@' . strtotime($attrValue));
1089+
$attrValue = (new \DateTime())->setTimestamp(strtotime($attrValue));
10901090
$attrValue = $attrValue->format(DateTime::DATETIME_PHP_FORMAT);
10911091
} elseif ($backModel) {
10921092
$attribute->getBackend()->beforeSave($product);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function prepareCatalogProductCollectionPrices(EventObserver $observer)
267267
if ($observer->getEvent()->hasDate()) {
268268
$date = new \DateTime($observer->getEvent()->getDate());
269269
} else {
270-
$date = new \DateTime('@' . $this->_localeDate->scopeTimeStamp($store));
270+
$date = (new \DateTime())->setTimestamp($this->_localeDate->scopeTimeStamp($store));
271271
}
272272

273273
$productIds = [];

app/code/Magento/Customer/view/frontend/templates/form/register.phtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@
164164
require([
165165
'jquery',
166166
'mage/mage'
167-
], function(jQuery){
167+
], function($){
168168

169169
var dataForm = $('#form-validate');
170170
var ignore = <?php echo $_dob->isEnabled() ? '\'input[id$="full"]\'' : 'null'; ?>;

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ protected function _prepareDataForUpdate(array $rowData)
473473
if ('select' == $attributeParams['type']) {
474474
$value = $attributeParams['options'][strtolower($rowData[$attributeAlias])];
475475
} elseif ('datetime' == $attributeParams['type']) {
476-
$value = new \DateTime('@' . strtotime($rowData[$attributeAlias]));
476+
$value = (new \DateTime())->setTimestamp(strtotime($rowData[$attributeAlias]));
477477
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
478478
} else {
479479
$value = $rowData[$attributeAlias];

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ protected function _prepareDataForUpdate(array $rowData)
292292
$attributesToSave = [];
293293

294294
// entity table data
295-
$now = new \DateTime('@' . time());
295+
$now = new \DateTime();
296296
if (empty($rowData['created_at'])) {
297297
$createdAt = $now;
298298
} else {
299-
$createdAt = new \DateTime('@' . strtotime($rowData['created_at']));
299+
$createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
300300
}
301301
$entityRow = [
302302
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
@@ -333,7 +333,7 @@ protected function _prepareDataForUpdate(array $rowData)
333333
if ('select' == $attributeParameters['type']) {
334334
$value = $attributeParameters['options'][strtolower($value)];
335335
} elseif ('datetime' == $attributeParameters['type']) {
336-
$value = new \DateTime('@' . strtotime($value));
336+
$value = (new \DateTime())->setTimestamp(strtotime($value));
337337
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
338338
} elseif ($backendModel) {
339339
$attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,7 +1034,7 @@ protected function _parseResponse($response)
10341034

10351035
if (strlen(trim($response)) > 0) {
10361036
if (strpos(trim($response), '<?xml') === 0) {
1037-
$xml = simplexml_load_string($response);
1037+
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
10381038
if (is_object($xml)) {
10391039
if (in_array($xml->getName(), ['ErrorResponse', 'ShipmentValidateErrorResponse'])
10401040
|| isset($xml->GetQuoteResponse->Note->Condition)
@@ -1775,7 +1775,7 @@ protected function _parseXmlTrackingResponse($trackings, $response)
17751775
$resultArr = [];
17761776

17771777
if (strlen(trim($response)) > 0) {
1778-
$xml = simplexml_load_string($response);
1778+
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
17791779
if (!is_object($xml)) {
17801780
$errorTitle = __('Response is in the wrong format');
17811781
}

app/code/Magento/Eav/Model/Entity/Attribute/Backend/Datetime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function formatDate($date)
7171
}
7272
// unix timestamp given - simply instantiate date object
7373
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
74-
$date = new \DateTime('@' . $date);
74+
$date = (new \DateTime())->setTimestamp($date);
7575
// international format
7676
} elseif (!($date instanceof \DateTime)) {
7777
$date = new \DateTime($date);

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -706,7 +706,8 @@ protected function _parseXmlResponse($response)
706706
$priceArr = [];
707707

708708
if (strlen(trim($response)) > 0) {
709-
if ($xml = $this->_parseXml($response)) {
709+
$xml = $this->parseXml($response, 'Magento\Shipping\Model\Simplexml\Element');
710+
if (is_object($xml)) {
710711
if (is_object($xml->Error) && is_object($xml->Error->Message)) {
711712
$errorTitle = (string)$xml->Error->Message;
712713
} elseif (is_object($xml->SoftError) && is_object($xml->SoftError->Message)) {
@@ -760,27 +761,6 @@ protected function _parseXmlResponse($response)
760761
return $result;
761762
}
762763

763-
/**
764-
* Parse XML string and return XML document object or false
765-
*
766-
* @param string $xmlContent
767-
* @return \Magento\Shipping\Model\Simplexml\Element|bool
768-
* @throws \Exception
769-
*/
770-
protected function _parseXml($xmlContent)
771-
{
772-
try {
773-
try {
774-
return simplexml_load_string($xmlContent);
775-
} catch (\Exception $e) {
776-
throw new \Exception(__('Failed to parse xml document: %1', $xmlContent));
777-
}
778-
} catch (\Exception $e) {
779-
$this->_logger->critical($e);
780-
return false;
781-
}
782-
}
783-
784764
/**
785765
* Get configuration data of carrier
786766
*

app/code/Magento/Reports/Block/Adminhtml/Grid.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function _prepareCollection()
9292

9393
if (!isset($data['report_from'])) {
9494
// getting all reports from 2001 year
95-
$date = new \DateTime('@' . mktime(0, 0, 0, 1, 1, 2001));
95+
$date = (new \DateTime())->setTimestamp(mktime(0, 0, 0, 1, 1, 2001));
9696
$data['report_from'] = $this->_localeDate->formatDateTime(
9797
$date,
9898
\IntlDateFormatter::SHORT,

app/code/Magento/RequireJs/Block/Html/Head/Config.php

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66

77
namespace Magento\RequireJs\Block\Html\Head;
88

9+
use Magento\Framework\RequireJs\Config as RequireJsConfig;
10+
911
/**
1012
* Block responsible for including RequireJs config on the page
1113
*/
1214
class Config extends \Magento\Framework\View\Element\AbstractBlock
1315
{
1416
/**
15-
* @var \Magento\Framework\RequireJs\Config
17+
* @var RequireJsConfig
1618
*/
1719
private $config;
1820

@@ -28,15 +30,15 @@ class Config extends \Magento\Framework\View\Element\AbstractBlock
2830

2931
/**
3032
* @param \Magento\Framework\View\Element\Context $context
31-
* @param \Magento\Framework\RequireJs\Config $config
33+
* @param RequireJsConfig $config
3234
* @param \Magento\RequireJs\Model\FileManager $fileManager
3335
* @param \Magento\Framework\View\Page\Config $pageConfig
3436
* @param \Magento\Framework\View\Asset\ConfigInterface $bundleConfig
3537
* @param array $data
3638
*/
3739
public function __construct(
3840
\Magento\Framework\View\Element\Context $context,
39-
\Magento\Framework\RequireJs\Config $config,
41+
RequireJsConfig $config,
4042
\Magento\RequireJs\Model\FileManager $fileManager,
4143
\Magento\Framework\View\Page\Config $pageConfig,
4244
\Magento\Framework\View\Asset\ConfigInterface $bundleConfig,
@@ -59,28 +61,30 @@ protected function _prepareLayout()
5961
$requireJsConfig = $this->fileManager->createRequireJsConfigAsset();
6062
$assetCollection = $this->pageConfig->getAssetCollection();
6163

62-
if ($this->bundleConfig->isBundlingJsFiles()) {
63-
$after = \Magento\Framework\RequireJs\Config::REQUIRE_JS_FILE_NAME;
64+
$assetCollection->insert(
65+
$requireJsConfig->getFilePath(),
66+
$requireJsConfig,
67+
RequireJsConfig::REQUIRE_JS_FILE_NAME
68+
);
6469

70+
if ($this->bundleConfig->isBundlingJsFiles()) {
6571
$bundleAssets = $this->fileManager->createBundleJsPool();
6672
$staticAsset = $this->fileManager->createStaticJsAsset();
6773

6874
/** @var \Magento\Framework\View\Asset\File $bundleAsset */
6975
if (!empty($bundleAssets) && $staticAsset !== false) {
76+
$bundleAssets = array_reverse($bundleAssets);
7077
foreach ($bundleAssets as $bundleAsset) {
71-
$assetCollection->insert($bundleAsset->getFilePath(), $bundleAsset, $after);
72-
$after = $bundleAsset->getFilePath();
78+
$assetCollection->insert(
79+
$bundleAsset->getFilePath(),
80+
$bundleAsset,
81+
RequireJsConfig::REQUIRE_JS_FILE_NAME
82+
);
7383
}
74-
$assetCollection->insert($staticAsset->getFilePath(), $staticAsset, $after);
84+
$assetCollection->insert($staticAsset->getFilePath(), $staticAsset, RequireJsConfig::CONFIG_FILE_NAME);
7585
}
7686
}
7787

78-
$assetCollection->insert(
79-
$requireJsConfig->getFilePath(),
80-
$requireJsConfig,
81-
\Magento\Framework\RequireJs\Config::REQUIRE_JS_FILE_NAME
82-
);
83-
8488
return parent::_prepareLayout();
8589
}
8690

app/code/Magento/Shipping/Model/Carrier/AbstractCarrierOnline.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,4 +607,17 @@ public function getMethodPrice($cost, $method = '')
607607
$cost
608608
);
609609
}
610+
611+
/**
612+
* Parse XML string and return XML document object or false
613+
*
614+
* @param string $xmlContent
615+
* @param string $customSimplexml
616+
*
617+
* @return \SimpleXMLElement|bool
618+
*/
619+
public function parseXml($xmlContent, $customSimplexml = 'SimpleXMLElement')
620+
{
621+
return simplexml_load_string($xmlContent, $customSimplexml);
622+
}
610623
}

app/code/Magento/Shipping/Test/Unit/Model/Carrier/AbstractCarrierOnlineTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,15 @@ public function testComposePackages()
104104

105105
$this->carrier->proccessAdditionalValidation($request);
106106
}
107+
108+
public function testParseXml()
109+
{
110+
$xmlString = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetResponse><value>42</value>></GetResponse>";
111+
$simpleXmlElement = $this->carrier->parseXml($xmlString);
112+
$this->assertEquals('GetResponse', $simpleXmlElement->getName());
113+
$this->assertEquals(42, (int)$simpleXmlElement->value);
114+
$this->assertInstanceOf('SimpleXMLElement', $simpleXmlElement);
115+
$customSimpleXmlElement = $this->carrier->parseXml($xmlString, 'Magento\Shipping\Model\Simplexml\Element');
116+
$this->assertInstanceOf('Magento\Shipping\Model\Simplexml\Element', $customSimpleXmlElement);
117+
}
107118
}

app/code/Magento/Usps/Model/Carrier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ protected function _parseXmlResponse($response)
512512
$response
513513
);
514514
}
515-
$xml = simplexml_load_string($response);
515+
$xml = $this->parseXml($response);
516516

517517
if (is_object($xml)) {
518518
$allowedMethods = explode(',', $this->getConfigData('allowed_methods'));
@@ -1042,7 +1042,7 @@ protected function _parseXmlTrackingResponse($trackingvalue, $response)
10421042
$resultArr = [];
10431043
if (strlen(trim($response)) > 0) {
10441044
if (strpos(trim($response), '<?xml') === 0) {
1045-
$xml = simplexml_load_string($response);
1045+
$xml = $this->parseXml($response);
10461046
if (is_object($xml)) {
10471047
if (isset($xml->Number) && isset($xml->Description) && (string)$xml->Description != '') {
10481048
$errorTitle = (string)$xml->Description;
@@ -1869,7 +1869,7 @@ protected function _doShipmentRequest(\Magento\Framework\Object $request)
18691869
$client->setParameterGet('XML', $requestXml);
18701870
$response = $client->request()->getBody();
18711871

1872-
$response = simplexml_load_string($response);
1872+
$response = $this->parseXml($response);
18731873
if ($response === false || $response->getName() == 'Error') {
18741874
$debugData['result'] = [
18751875
'error' => $response->Description,

dev/tests/static/testsuite/Magento/Test/Legacy/_files/obsolete_methods.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,7 @@
157157
['_parseDescription', 'Magento\Sales\Model\Order\Pdf\Items\AbstractItems'],
158158
['_parsePackageTheme', 'Magento\Widget\Model\Widget\Instance'],
159159
['_parseXmlTrackingResponse', 'Magento\Fedex\Model\Carrier'],
160+
['_parseXml', 'Magento\Fedex\Model\Carrier'],
160161
['_prepareCondition', 'Magento\CatalogSearch\Model\Advanced'],
161162
['_prepareConfigurableProductData', 'Magento\CatalogImportExport\Model\Export\Product'],
162163
['_prepareConfigurableProductPrice', 'Magento\CatalogImportExport\Model\Export\Product'],

0 commit comments

Comments
 (0)