Skip to content

Commit

Permalink
Merge pull request #5948 from magento-tsg-csl3/2.4-develop-pr34
Browse files Browse the repository at this point in the history
[TSG-CSL3] For 2.4 (pr34)
  • Loading branch information
viktym authored Aug 5, 2020
2 parents e12a2fd + 52e6554 commit 00f8a8c
Show file tree
Hide file tree
Showing 17 changed files with 719 additions and 231 deletions.
17 changes: 13 additions & 4 deletions app/code/Magento/Checkout/view/frontend/web/js/region-updater.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ define([
regionInput = $(this.options.regionInputId),
postcode = $(this.options.postcodeId),
label = regionList.parent().siblings('label'),
container = regionList.parents('div.field');
container = regionList.parents('div.field'),
regionsEntries,
regionId,
regionData;

this._clearError();
this._checkRegionRequired(country);
Expand All @@ -168,8 +171,14 @@ define([
// Populate state/province dropdown list if available or use input box
if (this.options.regionJson[country]) {
this._removeSelectOptions(regionList);
$.each(this.options.regionJson[country], $.proxy(function (key, value) {
this._renderSelectOption(regionList, key, value);
regionsEntries = _.pairs(this.options.regionJson[country]);
regionsEntries.sort(function (a, b) {
return a[1].name > b[1].name ? 1 : -1;
});
$.each(regionsEntries, $.proxy(function (key, value) {
regionId = value[0];
regionData = value[1];
this._renderSelectOption(regionList, regionId, regionData);
}, this));

if (this.currentRegionOption) {
Expand All @@ -193,7 +202,7 @@ define([
regionList.hide();
container.hide();
} else {
regionList.show();
regionList.removeAttr('disabled').show();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* @api
*/
define([], function () {
define(['underscore'], function (_) {
'use strict';

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ define([], function () {
vatId: addressData['vat_id'],
sameAsBilling: addressData['same_as_billing'],
saveInAddressBook: addressData['save_in_address_book'],
customAttributes: addressData['custom_attributes'],
customAttributes: _.toArray(addressData['custom_attributes']).reverse(),

/**
* @return {*}
Expand Down
48 changes: 30 additions & 18 deletions app/code/Magento/Deploy/Process/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Queue
/**
* Default max execution time
*/
const DEFAULT_MAX_EXEC_TIME = 400;
const DEFAULT_MAX_EXEC_TIME = 900;

/**
* @var array
Expand Down Expand Up @@ -96,6 +96,11 @@ class Queue
*/
private $lastJobStarted = 0;

/**
* @var int
*/
private $logDelay;

/**
* @param AppState $appState
* @param LocaleResolver $localeResolver
Expand Down Expand Up @@ -157,11 +162,12 @@ public function getPackages()
* Process jobs
*
* @return int
* @throws TimeoutException
*/
public function process()
{
$returnStatus = 0;
$logDelay = 10;
$this->logDelay = 10;
$this->start = $this->lastJobStarted = time();
$packages = $this->packages;
while (count($packages) && $this->checkTimeout()) {
Expand All @@ -170,13 +176,7 @@ public function process()
$this->assertAndExecute($name, $packages, $packageJob);
}

// refresh current status in console once in 10 iterations (once in 5 sec)
if ($logDelay >= 10) {
$this->logger->info('.');
$logDelay = 0;
} else {
$logDelay++;
}
$this->refreshStatus();

if ($this->isCanBeParalleled()) {
// in parallel mode sleep before trying to check status and run new jobs
Expand All @@ -193,9 +193,28 @@ public function process()

$this->awaitForAllProcesses();

if (!empty($packages)) {
throw new TimeoutException('Not all packages are deployed.');
}

return $returnStatus;
}

/**
* Refresh current status in console once in 10 iterations (once in 5 sec)
*
* @return void
*/
private function refreshStatus(): void
{
if ($this->logDelay >= 10) {
$this->logger->info('.');
$this->logDelay = 0;
} else {
$this->logDelay++;
}
}

/**
* Check that all depended packages deployed and execute
*
Expand All @@ -204,7 +223,7 @@ public function process()
* @param array $packageJob
* @return void
*/
private function assertAndExecute($name, array & $packages, array $packageJob)
private function assertAndExecute($name, array &$packages, array $packageJob)
{
/** @var Package $package */
$package = $packageJob['package'];
Expand Down Expand Up @@ -256,21 +275,14 @@ private function executePackage(Package $package, string $name, array &$packages
*/
private function awaitForAllProcesses()
{
$logDelay = 10;
while ($this->inProgress && $this->checkTimeout()) {
foreach ($this->inProgress as $name => $package) {
if ($this->isDeployed($package)) {
unset($this->inProgress[$name]);
}
}

// refresh current status in console once in 10 iterations (once in 5 sec)
if ($logDelay >= 10) {
$this->logger->info('.');
$logDelay = 0;
} else {
$logDelay++;
}
$this->refreshStatus();

// sleep before checking parallel jobs status
// phpcs:ignore Magento2.Functions.DiscouragedFunction
Expand Down
15 changes: 15 additions & 0 deletions app/code/Magento/Deploy/Process/TimeoutException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Deploy\Process;

/**
* Exception is thrown if deploy process is finished due to timeout.
*/
class TimeoutException extends \RuntimeException
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Downloadable\Observer;

use Magento\Framework\Event\ObserverInterface;
Expand Down Expand Up @@ -81,12 +83,14 @@ public function __construct(
*/
public function execute(\Magento\Framework\Event\Observer $observer)
{
/** @var \Magento\Sales\Model\Order\Item $orderItem */
$orderItem = $observer->getEvent()->getItem();
if (!$orderItem->getId()) {
//order not saved in the database
return $this;
}
if ($orderItem->getProductType() != \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
$productType = $orderItem->getRealProductType() ?: $orderItem->getProductType();
if ($productType !== \Magento\Downloadable\Model\Product\Type::TYPE_DOWNLOADABLE) {
return $this;
}
$product = $orderItem->getProduct();
Expand All @@ -112,13 +116,13 @@ public function execute(\Magento\Framework\Event\Observer $observer)
if ($linkIds = $orderItem->getProductOptionByCode('links')) {
$linkPurchased = $this->_createPurchasedModel();
$this->_objectCopyService->copyFieldsetToTarget(
\downloadable_sales_copy_order::class,
'downloadable_sales_copy_order',
'to_downloadable',
$orderItem->getOrder(),
$linkPurchased
);
$this->_objectCopyService->copyFieldsetToTarget(
\downloadable_sales_copy_order_item::class,
'downloadable_sales_copy_order_item',
'to_downloadable',
$orderItem,
$linkPurchased
Expand All @@ -131,14 +135,12 @@ public function execute(\Magento\Framework\Event\Observer $observer)
ScopeInterface::SCOPE_STORE
);
$linkPurchased->setLinkSectionTitle($linkSectionTitle)->save();

$linkStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_PENDING;
if ($orderStatusToEnableItem == \Magento\Sales\Model\Order\Item::STATUS_PENDING
|| $orderItem->getOrder()->getState() == \Magento\Sales\Model\Order::STATE_COMPLETE
) {
$linkStatus = \Magento\Downloadable\Model\Link\Purchased\Item::LINK_STATUS_AVAILABLE;
}

foreach ($linkIds as $linkId) {
if (isset($links[$linkId])) {
$linkPurchasedItem = $this->_createPurchasedItemModel()->setPurchasedId(
Expand All @@ -148,7 +150,7 @@ public function execute(\Magento\Framework\Event\Observer $observer)
);

$this->_objectCopyService->copyFieldsetToTarget(
\downloadable_sales_copy_link::class,
'downloadable_sales_copy_link',
'to_purchased',
$links[$linkId],
$linkPurchasedItem
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,9 @@ public function testSaveDownloadableOrderItem()
$itemMock->expects($this->any())
->method('getProductType')
->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);
$itemMock->expects($this->any())
->method('getRealProductType')
->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);

$this->orderMock->expects($this->once())
->method('getStoreId')
Expand Down Expand Up @@ -311,6 +314,9 @@ public function testSaveDownloadableOrderItemSavedPurchasedLink()
$itemMock->expects($this->any())
->method('getProductType')
->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);
$itemMock->expects($this->any())
->method('getRealProductType')
->willReturn(DownloadableProductType::TYPE_DOWNLOADABLE);

$purchasedLink = $this->getMockBuilder(Purchased::class)
->disableOriginalConstructor()
Expand Down
38 changes: 15 additions & 23 deletions app/code/Magento/ImportExport/Model/Report/Csv.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\ImportExport\Model\Report;

Expand Down Expand Up @@ -60,22 +61,16 @@ public function __construct(
}

/**
* @param string $originalFileName
* @param ProcessingErrorAggregatorInterface $errorAggregator
* @param bool $writeOnlyErrorItems
* @return string
* @throws \Magento\Framework\Exception\LocalizedException
* @inheritDoc
*/
public function createReport(
$originalFileName,
ProcessingErrorAggregatorInterface $errorAggregator,
$writeOnlyErrorItems = false
) {
$sourceCsv = $this->createSourceCsvModel($originalFileName);

$outputFileName = $this->generateOutputFileName($originalFileName);
$outputCsv = $this->createOutputCsvModel($outputFileName);
$outputCsv = $this->outputCsvFactory->create();

$sourceCsv = $this->createSourceCsvModel($originalFileName);
$columnsName = $sourceCsv->getColNames();
$columnsName[] = self::REPORT_ERROR_COLUMN_NAME;
$outputCsv->setHeaderCols($columnsName);
Expand All @@ -88,10 +83,16 @@ public function createReport(
}
}

$directory = $this->filesystem->getDirectoryWrite(DirectoryList::VAR_DIR);
$outputFileName = $this->generateOutputFileName($originalFileName);
$directory->writeFile(Import::IMPORT_HISTORY_DIR . $outputFileName, $outputCsv->getContents());

return $outputFileName;
}

/**
* Retrieve error messages
*
* @param int $rowNumber
* @param ProcessingErrorAggregatorInterface $errorAggregator
* @return string
Expand All @@ -112,16 +113,21 @@ public function retrieveErrorMessagesByRowNumber($rowNumber, ProcessingErrorAggr
}

/**
* Generate output filename based on source filename
*
* @param string $sourceFile
* @return string
*/
protected function generateOutputFileName($sourceFile)
{
// phpcs:ignore Magento2.Functions.DiscouragedFunction
$fileName = basename($sourceFile, self::ERROR_REPORT_FILE_EXTENSION);
return $fileName . self::ERROR_REPORT_FILE_SUFFIX . self::ERROR_REPORT_FILE_EXTENSION;
}

/**
* Create source CSV model
*
* @param string $sourceFile
* @return \Magento\ImportExport\Model\Import\Source\Csv
*/
Expand All @@ -135,18 +141,4 @@ protected function createSourceCsvModel($sourceFile)
]
);
}

/**
* @param string $outputFileName
* @return \Magento\ImportExport\Model\Export\Adapter\Csv
*/
protected function createOutputCsvModel($outputFileName)
{
return $this->outputCsvFactory->create(
[
'destination' => Import::IMPORT_HISTORY_DIR . $outputFileName,
'destinationDirectoryCode' => DirectoryList::VAR_DIR,
]
);
}
}
Loading

0 comments on commit 00f8a8c

Please sign in to comment.