Skip to content

Commit 9a7db20

Browse files
committed
ACPT-1429: Stabilize Import Product
1 parent fe6b511 commit 9a7db20

File tree

4 files changed

+29
-50
lines changed

4 files changed

+29
-50
lines changed

app/code/Magento/DownloadableImportExport/Helper/Data.php

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,22 @@ class Data extends \Magento\Framework\App\Helper\AbstractHelper
1818
* @param array $rowData
1919
* @return bool
2020
*/
21-
public function isRowDownloadableEmptyOptions(array $rowData)
21+
public function isRowDownloadableEmptyOptions(array $rowData): bool
2222
{
23-
$links = $rowData[Downloadable::COL_DOWNLOADABLE_LINKS] ?? '';
24-
$samples = $rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES] ?? '';
23+
return $this->isDataEmpty($rowData, Downloadable::COL_DOWNLOADABLE_LINKS)
24+
&& $this->isDataEmpty($rowData, Downloadable::COL_DOWNLOADABLE_SAMPLES);
25+
}
2526

26-
return empty($links) && empty($samples);
27+
/**
28+
* Check whether the data is empty.
29+
*
30+
* @param array $data
31+
* @param string $key
32+
* @return bool
33+
*/
34+
private function isDataEmpty(array $data, string $key): bool
35+
{
36+
return isset($data[$key]) && ($data[$key] == '' || $data[$key] == []);
2737
}
2838

2939
/**
@@ -32,11 +42,10 @@ public function isRowDownloadableEmptyOptions(array $rowData)
3242
* @param array $rowData
3343
* @return bool
3444
*/
35-
public function isRowDownloadableNoValid(array $rowData)
45+
public function isRowDownloadableNoValid(array $rowData): bool
3646
{
37-
$result = isset($rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES]) ||
47+
return isset($rowData[Downloadable::COL_DOWNLOADABLE_SAMPLES]) ||
3848
isset($rowData[Downloadable::COL_DOWNLOADABLE_LINKS]);
39-
return $result;
4049
}
4150

4251
/**

app/code/Magento/ImportExport/Model/Import/AbstractEntity.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6-
declare(strict_types=1);
7-
86
namespace Magento\ImportExport\Model\Import;
97

108
use Magento\Framework\App\Config\ScopeConfigInterface;

app/code/Magento/ImportExport/Model/Import/Source/Json.php

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,13 @@
77

88
namespace Magento\ImportExport\Model\Import\Source;
99

10-
use Magento\Framework\Exception\ValidatorException;
11-
use Magento\Framework\Filesystem\Directory\Read as DirectoryRead;
12-
use Magento\Framework\Filesystem\File\ReadInterface as FileReadInterface;
10+
use Magento\ImportExport\Model\Import\AbstractSource;
1311

1412
/**
1513
* JSON import adapter
1614
*/
17-
class Json extends \Magento\ImportExport\Model\Import\AbstractSource
15+
class Json extends AbstractSource
1816
{
19-
/**
20-
* @var FileReadInterface
21-
*/
22-
private FileReadInterface $_file;
23-
2417
/**
2518
* @var array
2619
*/
@@ -37,40 +30,17 @@ class Json extends \Magento\ImportExport\Model\Import\AbstractSource
3730
private array $colNames = [];
3831

3932
/**
40-
* Open file and decode JSON data
41-
*
42-
* @param string|FileReadInterface $file
43-
* @param DirectoryRead $directory
44-
* @throws ValidatorException
33+
* @param array $items
4534
*/
46-
public function __construct(
47-
$file,
48-
DirectoryRead $directory
49-
) {
50-
if ($file instanceof FileReadInterface) {
51-
$this->_file = $file;
52-
$this->_file->seek(0);
53-
} else {
54-
try {
55-
$filePath = $directory->getRelativePath($file);
56-
$this->_file = $directory->openFile($filePath, 'r');
57-
$this->_file->seek(0);
58-
} catch (\Magento\Framework\Exception\FileSystemException $e) {
59-
throw new \LogicException("Unable to open file: '{$file}'");
60-
}
61-
}
62-
$jsonData = '';
63-
while (!$this->_file->eof()) {
64-
$chunk = $this->_file->read(1024);
65-
$jsonData .= $chunk;
66-
}
67-
$this->items = json_decode($jsonData, true) ?: [];
35+
public function __construct(array $items)
36+
{
6837
// convert all scalar values to strings
6938
$this->items = array_map(function ($item) {
7039
return array_map(function ($value) {
71-
return is_scalar($value) ? (string) $value : $value;
40+
return is_scalar($value) ? (string)$value : $value;
7241
}, $item);
73-
}, $this->items);
42+
}, $items);
43+
7444
if (isset($this->items[0])) {
7545
$this->colNames = array_keys($this->items[0]);
7646
}
@@ -108,10 +78,11 @@ public function rewind()
10878
* @param int $position
10979
* @return void
11080
*/
111-
#[\ReturnTypeWillChange]
11281
public function seek($position)
11382
{
83+
if ($position < 0 || $position >= count($this->items)) {
84+
throw new \OutOfBoundsException("Invalid seek position ($position)");
85+
}
11486
$this->position = $position;
115-
parent::__construct($this->_getNextRow());
11687
}
11788
}

lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,8 @@ public function convertValue($data, $type)
528528
* @throws SerializationException
529529
* @throws InvalidArgumentException
530530
*/
531-
private function processComplexTypes($data, $type) {
531+
private function processComplexTypes($data, $type)
532+
{
532533
$isArrayType = $this->typeProcessor->isArrayType($type);
533534

534535
if (!$isArrayType) {

0 commit comments

Comments
 (0)