Skip to content

Commit 1c3837c

Browse files
authored
Merge pull request #6491 from magento-tsg/2.4-develop-pr117
[Arrows] Fixes for 2.4 (pr117) (2.4-develop)
2 parents e03d067 + 7cfb7c6 commit 1c3837c

File tree

25 files changed

+827
-40
lines changed

25 files changed

+827
-40
lines changed

app/code/Magento/Bundle/Pricing/Price/BundleSelectionFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,12 @@ public function create(
5252
$quantity,
5353
array $arguments = []
5454
) {
55+
$quantity = $quantity ? (float)$quantity : 1.;
56+
$selection->setQty($quantity);
57+
5558
$arguments['bundleProduct'] = $bundleProduct;
5659
$arguments['saleableItem'] = $selection;
57-
$arguments['quantity'] = $quantity ? (float)$quantity : 1.;
60+
$arguments['quantity'] = $quantity;
5861

5962
return $this->objectManager->create(self::SELECTION_CLASS_DEFAULT, $arguments);
6063
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public function isValid($value)
114114
]
115115
);
116116
$valid = false;
117+
break;
117118
}
118-
break;
119119
}
120120
}
121121
return $valid;
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Controller\Adminhtml\Address;
9+
10+
use Magento\Customer\Api\AddressMetadataInterface;
11+
use Magento\Framework\Exception\NotFoundException;
12+
use Magento\Framework\App\Filesystem\DirectoryList;
13+
use Magento\Framework\Controller\Result\RawFactory;
14+
use Magento\Framework\Url\DecoderInterface;
15+
use Magento\Framework\Controller\ResultInterface;
16+
use Magento\Framework\Filesystem;
17+
use Magento\Framework\Controller\Result\Raw;
18+
use Magento\MediaStorage\Helper\File\Storage;
19+
use Magento\Framework\App\Response\Http\FileFactory;
20+
use Magento\Framework\Filesystem\Io\File as IoFile;
21+
use Magento\Backend\App\Action\Context;
22+
use Magento\Framework\App\Action\HttpGetActionInterface;
23+
use Magento\Backend\App\Action;
24+
25+
/**
26+
* Class Viewfile serves to show file or image by file/image name provided in request parameters.
27+
*/
28+
class Viewfile extends Action implements HttpGetActionInterface
29+
{
30+
/**
31+
* Authorization level of a basic admin session
32+
*/
33+
const ADMIN_RESOURCE = 'Magento_Customer::manage';
34+
35+
/**
36+
* @var RawFactory
37+
*/
38+
private $resultRawFactory;
39+
40+
/**
41+
* @var DecoderInterface
42+
*/
43+
private $urlDecoder;
44+
45+
/**
46+
* @var Filesystem
47+
*/
48+
private $filesystem;
49+
50+
/**
51+
* @var Storage
52+
*/
53+
private $storage;
54+
55+
/**
56+
* @var FileFactory
57+
*/
58+
private $fileFactory;
59+
60+
/**
61+
* @var IoFile
62+
*/
63+
private $ioFile;
64+
65+
/**
66+
* @param Context $context
67+
* @param FileFactory $fileFactory
68+
* @param RawFactory $resultRawFactory
69+
* @param DecoderInterface $urlDecoder
70+
* @param Filesystem $filesystem
71+
* @param Storage $storage
72+
* @param IoFile $ioFile
73+
*/
74+
public function __construct(
75+
Context $context,
76+
FileFactory $fileFactory,
77+
RawFactory $resultRawFactory,
78+
DecoderInterface $urlDecoder,
79+
Filesystem $filesystem,
80+
Storage $storage,
81+
IoFile $ioFile
82+
) {
83+
parent::__construct($context);
84+
$this->resultRawFactory = $resultRawFactory;
85+
$this->urlDecoder = $urlDecoder;
86+
$this->filesystem = $filesystem;
87+
$this->storage = $storage;
88+
$this->fileFactory = $fileFactory;
89+
$this->ioFile = $ioFile;
90+
}
91+
92+
/**
93+
* Customer address view file action
94+
*
95+
* @return ResultInterface|void
96+
* @throws NotFoundException
97+
*/
98+
public function execute()
99+
{
100+
list($file, $plain) = $this->getFileParams();
101+
102+
$directory = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
103+
$fileName = AddressMetadataInterface::ENTITY_TYPE_ADDRESS . DIRECTORY_SEPARATOR .
104+
ltrim($file, DIRECTORY_SEPARATOR);
105+
$path = $directory->getAbsolutePath($fileName);
106+
if (mb_strpos($path, '..') !== false
107+
|| (!$directory->isFile($fileName) && !$this->storage->processStorageFile($path))
108+
) {
109+
throw new NotFoundException(__('Page not found.'));
110+
}
111+
112+
$pathInfo = $this->ioFile->getPathInfo($path);
113+
if ($plain) {
114+
$extension = $pathInfo['extension'];
115+
switch (strtolower($extension)) {
116+
case 'gif':
117+
$contentType = 'image/gif';
118+
break;
119+
case 'jpg':
120+
$contentType = 'image/jpeg';
121+
break;
122+
case 'png':
123+
$contentType = 'image/png';
124+
break;
125+
default:
126+
$contentType = 'application/octet-stream';
127+
break;
128+
}
129+
$stat = $directory->stat($fileName);
130+
$contentLength = $stat['size'];
131+
$contentModify = $stat['mtime'];
132+
133+
/** @var Raw $resultRaw */
134+
$resultRaw = $this->resultRawFactory->create();
135+
$resultRaw->setHttpResponseCode(200)
136+
->setHeader('Pragma', 'public', true)
137+
->setHeader('Content-type', $contentType, true)
138+
->setHeader('Content-Length', $contentLength)
139+
->setHeader('Last-Modified', date('r', $contentModify));
140+
$resultRaw->setContents($directory->readFile($fileName));
141+
142+
return $resultRaw;
143+
} else {
144+
$name = $pathInfo['basename'];
145+
$this->fileFactory->create(
146+
$name,
147+
['type' => 'filename', 'value' => $fileName],
148+
DirectoryList::MEDIA
149+
);
150+
}
151+
}
152+
153+
/**
154+
* Get parameters from request.
155+
*
156+
* @return array
157+
* @throws NotFoundException
158+
*/
159+
private function getFileParams() : array
160+
{
161+
$file = null;
162+
$plain = false;
163+
if ($this->getRequest()->getParam('file')) {
164+
// download file
165+
$file = $this->urlDecoder->decode(
166+
$this->getRequest()->getParam('file')
167+
);
168+
} elseif ($this->getRequest()->getParam('image')) {
169+
// show plain image
170+
$file = $this->urlDecoder->decode(
171+
$this->getRequest()->getParam('image')
172+
);
173+
$plain = true;
174+
} else {
175+
throw new NotFoundException(__('Page not found.'));
176+
}
177+
178+
return [$file, $plain];
179+
}
180+
}

app/code/Magento/Customer/Model/Address/AbstractAddress.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,10 +331,11 @@ protected function _implodeArrayValues($value)
331331
return '';
332332
}
333333

334-
$isScalar = false;
334+
$isScalar = true;
335335
foreach ($value as $val) {
336-
if (is_scalar($val)) {
337-
$isScalar = true;
336+
if (!is_scalar($val)) {
337+
$isScalar = false;
338+
break;
338339
}
339340
}
340341
if ($isScalar) {

app/code/Magento/Customer/Model/FileProcessor.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,10 @@ public function getViewUrl($filePath, $type)
158158
$viewUrl = '';
159159

160160
if ($this->entityTypeCode == AddressMetadataInterface::ENTITY_TYPE_ADDRESS) {
161-
$filePath = $this->entityTypeCode . '/' . ltrim($filePath, '/');
162-
$viewUrl = $this->urlBuilder->getBaseUrl(['_type' => UrlInterface::URL_TYPE_MEDIA])
163-
. $this->mediaDirectory->getRelativePath($filePath);
161+
$viewUrl = $this->urlBuilder->getUrl(
162+
'customer/address/viewfile',
163+
[$type => $this->urlEncoder->encode(ltrim($filePath, '/'))]
164+
);
164165
}
165166

166167
if ($this->entityTypeCode == CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER) {

app/code/Magento/Customer/Model/Metadata/Form/File.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ public function __construct(
100100
FileProcessorFactory $fileProcessorFactory = null,
101101
IoFile $ioFile = null
102102
) {
103+
$value = $this->prepareFileValue($value);
103104
parent::__construct($localeDate, $logger, $attribute, $localeResolver, $value, $entityTypeCode, $isAjax);
104105
$this->urlEncoder = $urlEncoder;
105106
$this->_fileValidator = $fileValidator;
@@ -302,11 +303,11 @@ public function validateValue($value)
302303
public function compactValue($value)
303304
{
304305
if ($this->getIsAjaxRequest()) {
305-
return $this;
306+
return '';
306307
}
307308

308309
// Remove outdated file (in the case of file uploader UI component)
309-
if (empty($value) && !empty($this->_value)) {
310+
if (!empty($this->_value) && !empty($value['delete'])) {
310311
$this->fileProcessor->removeUploadedFile($this->_value);
311312
return $value;
312313
}
@@ -420,4 +421,19 @@ protected function getFileProcessor()
420421
{
421422
return $this->fileProcessor;
422423
}
424+
425+
/**
426+
* Prepare File value.
427+
*
428+
* @param array|string $value
429+
* @return array|string
430+
*/
431+
private function prepareFileValue($value)
432+
{
433+
if (is_array($value) && isset($value['value'])) {
434+
$value = $value['value'];
435+
}
436+
437+
return $value;
438+
}
423439
}

app/code/Magento/Customer/Test/Unit/Model/FileProcessorTest.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -162,22 +162,22 @@ public function testGetViewUrlCustomer()
162162
public function testGetViewUrlCustomerAddress()
163163
{
164164
$filePath = 'filename.ext1';
165+
$encodedFilePath = 'encodedfilenameext1';
165166

166-
$baseUrl = 'baseUrl';
167-
$relativeUrl = 'relativeUrl';
167+
$fileUrl = 'fileUrl';
168168

169-
$this->urlBuilder->expects($this->once())
170-
->method('getBaseUrl')
171-
->with(['_type' => UrlInterface::URL_TYPE_MEDIA])
172-
->willReturn($baseUrl);
169+
$this->urlEncoder->expects($this->once())
170+
->method('encode')
171+
->with($filePath)
172+
->willReturn($encodedFilePath);
173173

174-
$this->mediaDirectory->expects($this->once())
175-
->method('getRelativePath')
176-
->with(AddressMetadataInterface::ENTITY_TYPE_ADDRESS . '/' . $filePath)
177-
->willReturn($relativeUrl);
174+
$this->urlBuilder->expects($this->once())
175+
->method('getUrl')
176+
->with('customer/address/viewfile', ['image' => $encodedFilePath])
177+
->willReturn($fileUrl);
178178

179179
$model = $this->getModel(AddressMetadataInterface::ENTITY_TYPE_ADDRESS);
180-
$this->assertEquals($baseUrl . $relativeUrl, $model->getViewUrl($filePath, 'image'));
180+
$this->assertEquals($fileUrl, $model->getViewUrl($filePath, 'image'));
181181
}
182182

183183
public function testRemoveUploadedFile()

app/code/Magento/Customer/Test/Unit/Model/Metadata/Form/FileTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public function testCompactValueIsAjax()
347347
]
348348
);
349349

350-
$this->assertSame($model, $model->compactValue('aValue'));
350+
$this->assertSame('', $model->compactValue('aValue'));
351351
}
352352

353353
public function testCompactValueNoDelete()
@@ -362,12 +362,12 @@ public function testCompactValueNoDelete()
362362
]
363363
);
364364

365-
$this->fileProcessorMock->expects($this->once())
365+
$this->fileProcessorMock->expects($this->any())
366366
->method('removeUploadedFile')
367367
->with('value')
368368
->willReturnSelf();
369369

370-
$this->assertSame([], $model->compactValue([]));
370+
$this->assertSame('value', $model->compactValue([]));
371371
}
372372

373373
public function testCompactValueDelete()
@@ -377,11 +377,11 @@ public function testCompactValueDelete()
377377
$mediaDirMock = $this->getMockForAbstractClass(
378378
\Magento\Framework\Filesystem\Directory\WriteInterface::class
379379
);
380-
$mediaDirMock->expects($this->once())
380+
$mediaDirMock->expects($this->any())
381381
->method('delete')
382382
->with(self::ENTITY_TYPE . '/' . 'value');
383383

384-
$this->fileSystemMock->expects($this->once())
384+
$this->fileSystemMock->expects($this->any())
385385
->method('getDirectoryWrite')
386386
->with(DirectoryList::MEDIA)
387387
->will($this->returnValue($mediaDirMock));
@@ -394,7 +394,7 @@ public function testCompactValueDelete()
394394
]
395395
);
396396

397-
$this->assertSame('', $model->compactValue(['delete' => true]));
397+
$this->assertIsArray($model->compactValue(['delete' => true]));
398398
}
399399

400400
public function testCompactValueTmpFile()
@@ -589,12 +589,12 @@ public function testCompactValueRemoveUiComponentValue()
589589
]
590590
);
591591

592-
$this->fileProcessorMock->expects($this->once())
592+
$this->fileProcessorMock->expects($this->any())
593593
->method('removeUploadedFile')
594594
->with($value)
595595
->willReturnSelf();
596596

597-
$this->assertEquals([], $model->compactValue([]));
597+
$this->assertEquals($value, $model->compactValue([]));
598598
}
599599

600600
public function testCompactValueNoAction()

app/code/Magento/Indexer/Model/ProcessManager.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,12 @@ private function multiThreadsExecute($userFunctions)
111111
$this->startChildProcess($userFunction);
112112
}
113113
}
114-
// phpcs:ignore Magento2.CodeAnalysis.EmptyBlock,Magento2.Functions.DiscouragedFunction
114+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
115115
while (pcntl_waitpid(0, $status) != -1) {
116116
//Waiting for the completion of child processes
117+
if ($status > 0) {
118+
$this->failInChildProcess = true;
119+
}
117120
}
118121

119122
if ($this->failInChildProcess) {

0 commit comments

Comments
 (0)