Skip to content

Commit d46f840

Browse files
committed
Merge remote-tracking branch 'origin/2.4-develop' into 2.4-develop-pr66
2 parents 461f903 + 6d34992 commit d46f840

File tree

199 files changed

+5602
-386
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

199 files changed

+5602
-386
lines changed

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
<p align="center">
2-
<a href="https://magento.com">
3-
<img src="https://static.magento.com/sites/all/themes/magento/logo.svg" width="300px" alt="Magento" />
4-
</a>
5-
</p>
6-
<p align="center">
7-
<br /><br />
2+
<a href="https://magento.com">
3+
<img src="https://static.magento.com/sites/all/themes/magento/logo.svg" width="300px" alt="Magento Commerce" />
4+
</a>
5+
<br />
6+
<br />
87
<a href="https://www.codetriage.com/magento/magento2">
98
<img src="https://www.codetriage.com/magento/magento2/badges/users.svg" alt="Open Source Helpers" />
109
</a>

app/code/Magento/Analytics/Model/ReportWriter.php

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
declare(strict_types=1);
7+
68
namespace Magento\Analytics\Model;
79

810
use Magento\Analytics\ReportXml\DB\ReportValidator;
911
use Magento\Framework\Filesystem\Directory\WriteInterface;
1012

1113
/**
1214
* Writes reports in files in csv format
13-
* @inheritdoc
1415
*/
1516
class ReportWriter implements ReportWriterInterface
1617
{
@@ -54,7 +55,7 @@ public function __construct(
5455
}
5556

5657
/**
57-
* {@inheritdoc}
58+
* @inheritdoc
5859
*/
5960
public function write(WriteInterface $directory, $path)
6061
{
@@ -81,7 +82,7 @@ public function write(WriteInterface $directory, $path)
8182
$headers = array_keys($row);
8283
$stream->writeCsv($headers);
8384
}
84-
$stream->writeCsv($row);
85+
$stream->writeCsv($this->prepareRow($row));
8586
}
8687
$stream->unlock();
8788
$stream->close();
@@ -98,4 +99,18 @@ public function write(WriteInterface $directory, $path)
9899

99100
return true;
100101
}
102+
103+
/**
104+
* Replace wrong symbols in row
105+
*
106+
* @param array $row
107+
* @return array
108+
*/
109+
private function prepareRow(array $row): array
110+
{
111+
$row = preg_replace('/(?<!\\\\)"/', '\\"', $row);
112+
$row = preg_replace('/[\\\\]+/', '\\', $row);
113+
114+
return $row;
115+
}
101116
}

app/code/Magento/Analytics/Test/Unit/Model/ReportWriterTest.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
use Magento\Analytics\Model\ReportWriter;
1313
use Magento\Analytics\ReportXml\DB\ReportValidator;
1414
use Magento\Analytics\ReportXml\ReportProvider;
15-
use Magento\Framework\Filesystem\Directory\WriteInterface;
15+
use Magento\Framework\Filesystem\Directory\WriteInterface as DirectoryWriteInterface;
16+
use Magento\Framework\Filesystem\File\WriteInterface as FileWriteInterface;
1617
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
1718
use PHPUnit\Framework\MockObject\MockObject;
1819
use PHPUnit\Framework\TestCase;
@@ -48,7 +49,7 @@ class ReportWriterTest extends TestCase
4849
private $objectManagerHelper;
4950

5051
/**
51-
* @var WriteInterface|MockObject
52+
* @var DirectoryWriteInterface|MockObject
5253
*/
5354
private $directoryMock;
5455

@@ -82,7 +83,7 @@ protected function setUp(): void
8283
$this->reportValidatorMock = $this->createMock(ReportValidator::class);
8384
$this->providerFactoryMock = $this->createMock(ProviderFactory::class);
8485
$this->reportProviderMock = $this->createMock(ReportProvider::class);
85-
$this->directoryMock = $this->getMockBuilder(WriteInterface::class)
86+
$this->directoryMock = $this->getMockBuilder(DirectoryWriteInterface::class)
8687
->getMockForAbstractClass();
8788
$this->objectManagerHelper = new ObjectManagerHelper($this);
8889

@@ -98,16 +99,15 @@ protected function setUp(): void
9899

99100
/**
100101
* @param array $configData
102+
* @param array $fileData
103+
* @param array $expectedFileData
101104
* @return void
102105
*
103106
* @dataProvider configDataProvider
104107
*/
105-
public function testWrite(array $configData)
108+
public function testWrite(array $configData, array $fileData, array $expectedFileData): void
106109
{
107110
$errors = [];
108-
$fileData = [
109-
['number' => 1, 'type' => 'Shoes Usual']
110-
];
111111
$this->configInterfaceMock
112112
->expects($this->once())
113113
->method('get')
@@ -126,7 +126,7 @@ public function testWrite(array $configData)
126126
->with($parameterName ?: null)
127127
->willReturn($fileData);
128128
$errorStreamMock = $this->getMockBuilder(
129-
\Magento\Framework\Filesystem\File\WriteInterface::class
129+
FileWriteInterface::class
130130
)->getMockForAbstractClass();
131131
$errorStreamMock
132132
->expects($this->once())
@@ -136,8 +136,8 @@ public function testWrite(array $configData)
136136
->expects($this->exactly(2))
137137
->method('writeCsv')
138138
->withConsecutive(
139-
[array_keys($fileData[0])],
140-
[$fileData[0]]
139+
[array_keys($expectedFileData[0])],
140+
[$expectedFileData[0]]
141141
);
142142
$errorStreamMock->expects($this->once())->method('unlock');
143143
$errorStreamMock->expects($this->once())->method('close');
@@ -164,12 +164,12 @@ public function testWrite(array $configData)
164164
*
165165
* @dataProvider configDataProvider
166166
*/
167-
public function testWriteErrorFile($configData)
167+
public function testWriteErrorFile(array $configData): void
168168
{
169169
$errors = ['orders', 'SQL Error: test'];
170170
$this->configInterfaceMock->expects($this->once())->method('get')->willReturn([$configData]);
171171
$errorStreamMock = $this->getMockBuilder(
172-
\Magento\Framework\Filesystem\File\WriteInterface::class
172+
FileWriteInterface::class
173173
)->getMockForAbstractClass();
174174
$errorStreamMock->expects($this->once())->method('lock');
175175
$errorStreamMock->expects($this->once())->method('writeCsv')->with($errors);
@@ -184,7 +184,7 @@ public function testWriteErrorFile($configData)
184184
/**
185185
* @return void
186186
*/
187-
public function testWriteEmptyReports()
187+
public function testWriteEmptyReports(): void
188188
{
189189
$this->configInterfaceMock->expects($this->once())->method('get')->willReturn([]);
190190
$this->reportValidatorMock->expects($this->never())->method('validate');
@@ -195,11 +195,11 @@ public function testWriteEmptyReports()
195195
/**
196196
* @return array
197197
*/
198-
public function configDataProvider()
198+
public function configDataProvider(): array
199199
{
200200
return [
201201
'reportProvider' => [
202-
[
202+
'configData' => [
203203
'providers' => [
204204
[
205205
'name' => $this->providerName,
@@ -209,6 +209,12 @@ public function configDataProvider()
209209
],
210210
]
211211
]
212+
],
213+
'fileData' => [
214+
['number' => 1, 'type' => 'Shoes\"" Usual\\\\"']
215+
],
216+
'expectedFileData' => [
217+
['number' => 1, 'type' => 'Shoes\"\" Usual\\"']
212218
]
213219
],
214220
];

app/code/Magento/AsynchronousOperations/Model/MassConsumer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,19 @@ public function process($maxNumberOfMessages = null)
6969
$this->registry->register('isSecureArea', true, true);
7070

7171
$queue = $this->configuration->getQueue();
72+
$maxIdleTime = $this->configuration->getMaxIdleTime();
73+
$sleep = $this->configuration->getSleep();
7274

7375
if (!isset($maxNumberOfMessages)) {
7476
$queue->subscribe($this->getTransactionCallback($queue));
7577
} else {
76-
$this->invoker->invoke($queue, $maxNumberOfMessages, $this->getTransactionCallback($queue));
78+
$this->invoker->invoke(
79+
$queue,
80+
$maxNumberOfMessages,
81+
$this->getTransactionCallback($queue),
82+
$maxIdleTime,
83+
$sleep
84+
);
7785
}
7886

7987
$this->registry->unregister('isSecureArea');
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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\BundleGraphQl\Model\Resolver\Options;
9+
10+
use Magento\Framework\GraphQl\Config\Element\Field;
11+
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
12+
use Magento\Framework\GraphQl\Query\Resolver\ContextInterface;
13+
use Magento\Framework\GraphQl\Query\ResolverInterface;
14+
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;
15+
16+
/**
17+
* Format new option uid in base64 encode for entered bundle options
18+
*/
19+
class BundleItemOptionUid implements ResolverInterface
20+
{
21+
/**
22+
* Option type name
23+
*/
24+
private const OPTION_TYPE = 'bundle';
25+
26+
/**
27+
* Create a option uid for entered option in "<option-type>/<option-id>/<option-value-id>/<quantity>" format
28+
*
29+
* @param Field $field
30+
* @param ContextInterface $context
31+
* @param ResolveInfo $info
32+
* @param array|null $value
33+
* @param array|null $args
34+
*
35+
* @return string
36+
*
37+
* @throws GraphQlInputException
38+
*
39+
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
40+
*/
41+
public function resolve(
42+
Field $field,
43+
$context,
44+
ResolveInfo $info,
45+
array $value = null,
46+
array $args = null
47+
) {
48+
if (!isset($value['option_id']) || empty($value['option_id'])) {
49+
throw new GraphQlInputException(__('"option_id" value should be specified.'));
50+
}
51+
52+
if (!isset($value['selection_id']) || empty($value['selection_id'])) {
53+
throw new GraphQlInputException(__('"selection_id" value should be specified.'));
54+
}
55+
56+
$optionDetails = [
57+
self::OPTION_TYPE,
58+
$value['option_id'],
59+
$value['selection_id'],
60+
(int) $value['selection_qty']
61+
];
62+
63+
$content = implode('/', $optionDetails);
64+
65+
// phpcs:ignore Magento2.Functions.DiscouragedFunction
66+
return base64_encode($content);
67+
}
68+
}

app/code/Magento/BundleGraphQl/etc/schema.graphqls

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type BundleItemOption @doc(description: "BundleItemOption defines characteristic
6666
price_type: PriceTypeEnum @doc(description: "One of FIXED, PERCENT, or DYNAMIC.")
6767
can_change_quantity: Boolean @doc(description: "Indicates whether the customer can change the number of items for this option.")
6868
product: ProductInterface @doc(description: "Contains details about this product option.") @resolver(class: "Magento\\CatalogGraphQl\\Model\\Resolver\\Product")
69+
uid: ID! @doc(description: "A string that encodes option details.") @resolver(class: "Magento\\BundleGraphQl\\Model\\Resolver\\Options\\BundleItemOptionUid") # A Base64 string that encodes option details.
6970
}
7071

7172
type BundleProduct implements ProductInterface, PhysicalProductInterface, CustomizableProductInterface @doc(description: "BundleProduct defines basic features of a bundle product and contains multiple BundleItems.") {

0 commit comments

Comments
 (0)