Skip to content

Commit f6ac9e7

Browse files
committed
Merge branch '2.4-develop' into 825-adobestock-remove-directory
2 parents ed0cdb1 + fa00ff7 commit f6ac9e7

File tree

1,705 files changed

+35437
-17052
lines changed

Some content is hidden

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

1,705 files changed

+35437
-17052
lines changed

app/code/Magento/AdvancedSearch/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<field id="search_suggestion_enabled">1</field>
6161
</depends>
6262
</field>
63-
<field id="search_suggestion_count_results_enabled" translate="label" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="1">
63+
<field id="search_suggestion_count_results_enabled" translate="label comment" type="select" sortOrder="92" showInDefault="1" showInWebsite="1" showInStore="1">
6464
<label>Show Results Count for Each Suggestion</label>
6565
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
6666
<comment>When you enable this option your site may slow down.</comment>

app/code/Magento/Analytics/etc/adminhtml/system.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
<frontend_model>Magento\Analytics\Block\Adminhtml\System\Config\CollectionTimeLabel</frontend_model>
3030
<backend_model>Magento\Analytics\Model\Config\Backend\CollectionTime</backend_model>
3131
</field>
32-
<field id="vertical" translate="label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
32+
<field id="vertical" translate="hint label comment" type="select" sortOrder="30" showInDefault="1" showInWebsite="1" showInStore="0">
3333
<hint>Industry Data</hint>
3434
<label>Industry</label>
3535
<comment>In order to personalize your Advanced Reporting experience, please select your industry.</comment>

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,33 @@
66
namespace Magento\AsynchronousOperations\Model;
77

88
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
9+
use Magento\AsynchronousOperations\Model\OperationStatusValidator;
910
use Magento\Framework\DataObject;
1011

1112
/**
12-
* Class Operation
13+
* Class Operation encapsulates methods for Operation Model Object
1314
*/
1415
class Operation extends DataObject implements OperationInterface
1516
{
17+
/**
18+
* @var OperationStatusValidator
19+
*/
20+
private $operationStatusValidator;
21+
22+
/**
23+
* Operation constructor.
24+
*
25+
* @param OperationStatusValidator $operationStatusValidator
26+
* @param array $data
27+
*/
28+
public function __construct(
29+
OperationStatusValidator $operationStatusValidator,
30+
array $data = []
31+
) {
32+
$this->operationStatusValidator = $operationStatusValidator;
33+
parent::__construct($data);
34+
}
35+
1636
/**
1737
* @inheritDoc
1838
*/
@@ -106,6 +126,7 @@ public function getStatus()
106126
*/
107127
public function setStatus($status)
108128
{
129+
$this->operationStatusValidator->validate($status);
109130
return $this->setData(self::STATUS, $status);
110131
}
111132

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,24 @@
88

99
namespace Magento\AsynchronousOperations\Model;
1010

11-
use Magento\Framework\Serialize\Serializer\Json;
1211
use Magento\AsynchronousOperations\Api\Data\OperationInterface;
13-
use Magento\Framework\Bulk\OperationManagementInterface;
1412
use Magento\AsynchronousOperations\Model\ConfigInterface as AsyncConfig;
15-
use Magento\Framework\MessageQueue\MessageValidator;
16-
use Magento\Framework\MessageQueue\MessageEncoder;
17-
use Magento\Framework\Exception\NoSuchEntityException;
18-
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
19-
use Psr\Log\LoggerInterface;
20-
use Magento\Framework\Exception\LocalizedException;
21-
use Magento\Framework\Exception\TemporaryStateExceptionInterface;
13+
use Magento\Framework\Bulk\OperationManagementInterface;
14+
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
2215
use Magento\Framework\DB\Adapter\ConnectionException;
2316
use Magento\Framework\DB\Adapter\DeadlockException;
2417
use Magento\Framework\DB\Adapter\LockWaitException;
18+
use Magento\Framework\Exception\LocalizedException;
19+
use Magento\Framework\Exception\NoSuchEntityException;
20+
use Magento\Framework\MessageQueue\ConsumerConfigurationInterface;
21+
use Magento\Framework\MessageQueue\MessageEncoder;
22+
use Magento\Framework\MessageQueue\MessageValidator;
23+
use Magento\Framework\Serialize\Serializer\Json;
2524
use Magento\Framework\Webapi\ServiceOutputProcessor;
26-
use Magento\Framework\Communication\ConfigInterface as CommunicationConfig;
25+
use Psr\Log\LoggerInterface;
2726

2827
/**
29-
* Class OperationProcessor
28+
* Proccess operation
3029
*
3130
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
3231
*/
@@ -80,9 +79,9 @@ class OperationProcessor
8079
* @param ConsumerConfigurationInterface $configuration
8180
* @param Json $jsonHelper
8281
* @param OperationManagementInterface $operationManagement
83-
* @param LoggerInterface $logger
8482
* @param \Magento\Framework\Webapi\ServiceOutputProcessor $serviceOutputProcessor
8583
* @param \Magento\Framework\Communication\ConfigInterface $communicationConfig
84+
* @param LoggerInterface $logger
8685
*/
8786
public function __construct(
8887
MessageValidator $messageValidator,
@@ -137,7 +136,9 @@ public function process(string $encodedMessage)
137136
$result = $this->executeHandler($callback, $entityParams);
138137
$status = $result['status'];
139138
$errorCode = $result['error_code'];
139+
// phpcs:disable Magento2.Performance.ForeachArrayMerge
140140
$messages = array_merge($messages, $result['messages']);
141+
// phpcs:enable Magento2.Performance.ForeachArrayMerge
141142
$outputData = $result['output_data'];
142143
}
143144
}
@@ -174,8 +175,8 @@ public function process(string $encodedMessage)
174175
/**
175176
* Execute topic handler
176177
*
177-
* @param $callback
178-
* @param $entityParams
178+
* @param callable $callback
179+
* @param array $entityParams
179180
* @return array
180181
*/
181182
private function executeHandler($callback, $entityParams)
@@ -187,7 +188,9 @@ private function executeHandler($callback, $entityParams)
187188
'output_data' => null
188189
];
189190
try {
191+
// phpcs:disable Magento2.Functions.DiscouragedFunction
190192
$result['output_data'] = call_user_func_array($callback, $entityParams);
193+
// phpcs:enable Magento2.Functions.DiscouragedFunction
191194
$result['messages'][] = sprintf('Service execution success %s::%s', get_class($callback[0]), $callback[1]);
192195
} catch (\Zend_Db_Adapter_Exception $e) {
193196
$this->logger->critical($e->getMessage());
@@ -206,9 +209,7 @@ private function executeHandler($callback, $entityParams)
206209
}
207210
} catch (NoSuchEntityException $e) {
208211
$this->logger->error($e->getMessage());
209-
$result['status'] = ($e instanceof TemporaryStateExceptionInterface) ?
210-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED :
211-
OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212+
$result['status'] = OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED;
212213
$result['error_code'] = $e->getCode();
213214
$result['messages'][] = $e->getMessage();
214215
} catch (LocalizedException $e) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Model;
7+
8+
/**
9+
* Class OperationStatusPool
10+
*
11+
* Pool of statuses that require validate
12+
*/
13+
class OperationStatusPool
14+
{
15+
/**
16+
* @var array
17+
*/
18+
private $statuses;
19+
20+
/**
21+
* @param array $statuses
22+
*/
23+
public function __construct(array $statuses = [])
24+
{
25+
$this->statuses = $statuses;
26+
}
27+
28+
/**
29+
* Retrieve statuses that require validate
30+
*
31+
* @return array
32+
*/
33+
public function getStatuses()
34+
{
35+
return $this->statuses;
36+
}
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Model;
7+
8+
use Magento\AsynchronousOperations\Model\OperationStatusPool;
9+
use Magento\Framework\Exception\NoSuchEntityException;
10+
use Doctrine\Instantiator\Exception\InvalidArgumentException;
11+
12+
/**
13+
* Class OperationStatusValidator to validate operation status
14+
*/
15+
class OperationStatusValidator
16+
{
17+
/**
18+
* @var OperationStatusPool
19+
*/
20+
private $operationStatusPool;
21+
22+
/**
23+
* OperationStatusValidator constructor.
24+
*
25+
* @param OperationStatusPool $operationStatusPool
26+
*/
27+
public function __construct(OperationStatusPool $operationStatusPool)
28+
{
29+
$this->operationStatusPool = $operationStatusPool;
30+
}
31+
32+
/**
33+
* Validate method
34+
*
35+
* @param int $status
36+
* @throws \InvalidArgumentException
37+
* @return void
38+
*/
39+
public function validate($status)
40+
{
41+
$statuses = $this->operationStatusPool->getStatuses();
42+
43+
if (!in_array($status, $statuses)) {
44+
throw new \InvalidArgumentException('Invalid Operation Status.');
45+
}
46+
}
47+
}
Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\AsynchronousOperations\Test\Unit\Model;
7+
8+
use Magento\AsynchronousOperations\Model\OperationStatusValidator;
9+
use Magento\AsynchronousOperations\Model\Operation;
10+
use Magento\AsynchronousOperations\Model\OperationStatusPool;
11+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
12+
use PHPUnit\Framework\TestCase;
13+
14+
/**
15+
* Class OperationStatusValidatorTest implements logic for testing Operation::setStatus() method
16+
*/
17+
class OperationStatusValidatorTest extends TestCase
18+
{
19+
/**
20+
* @var OperationStatusPool
21+
*/
22+
private $operationStatusPool;
23+
24+
/**
25+
* @var OperationStatusValidator
26+
*/
27+
private $operationStatusValidator;
28+
29+
/**
30+
* @var Operation
31+
*/
32+
private $operation;
33+
34+
protected function setUp()
35+
{
36+
$this->operationStatusPool = $this->getMockBuilder(OperationStatusPool::class)
37+
->disableOriginalConstructor()
38+
->getMock();
39+
40+
$objectManager = new ObjectManager($this);
41+
42+
$this->operationStatusValidator = $objectManager->getObject(
43+
OperationStatusValidator::class,
44+
[
45+
'operationStatusPool' => $this->operationStatusPool
46+
]
47+
);
48+
49+
$this->operation = $objectManager->getObject(
50+
Operation::class,
51+
[
52+
'operationStatusValidator' => $this->operationStatusValidator
53+
]
54+
);
55+
}
56+
57+
/**
58+
* @param string $status
59+
* @param array $statusPool
60+
* @param string $expectedResult
61+
* @dataProvider dataProviderForTestSetStatus
62+
*/
63+
public function testSetStatus(
64+
string $status,
65+
array $statusPool,
66+
string $expectedResult
67+
) {
68+
$this->operationStatusPool
69+
->expects($this->any())
70+
->method('getStatuses')
71+
->willReturn($statusPool);
72+
73+
try {
74+
$this->operation->setStatus($status);
75+
$this->assertEquals($expectedResult, $this->operation->getStatus());
76+
} catch (\Exception $exception) {
77+
$this->assertEquals($expectedResult, $exception->getMessage());
78+
}
79+
}
80+
81+
/**
82+
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
83+
*/
84+
public function dataProviderForTestSetStatus()
85+
{
86+
return [
87+
[
88+
'status' => 0,
89+
'statusPool' => [
90+
'complete' => 1,
91+
'retriablyFailed' => 2,
92+
'notRetriablyFailed' => 3,
93+
'open' => 4,
94+
'rejected' => 5
95+
],
96+
'expectedResult' => 'Invalid Operation Status.'
97+
],
98+
[
99+
'status' => 1,
100+
'statusPool' => [
101+
'complete' => 1,
102+
'retriablyFailed' => 2,
103+
'notRetriablyFailed' => 3,
104+
'open' => 4,
105+
'rejected' => 5
106+
],
107+
'expectedResult' => 1
108+
],
109+
[
110+
'status' => 2,
111+
'statusPool' => [
112+
'complete' => 1,
113+
'retriablyFailed' => 2,
114+
'notRetriablyFailed' => 3,
115+
'open' => 4,
116+
'rejected' => 5
117+
],
118+
'expectedResult' => 2
119+
],
120+
[
121+
'status' => 3,
122+
'statusPool' => [
123+
'complete' => 1,
124+
'retriablyFailed' => 2,
125+
'notRetriablyFailed' => 3,
126+
'open' => 4,
127+
'rejected' => 5
128+
],
129+
'expectedResult' => 3
130+
],
131+
[
132+
'status' => 4,
133+
'statusPool' => [
134+
'complete' => 1,
135+
'retriablyFailed' => 2,
136+
'notRetriablyFailed' => 3,
137+
'open' => 4,
138+
'rejected' => 5
139+
],
140+
'expectedResult' => 4
141+
],
142+
[
143+
'status' => 5,
144+
'statusPool' => [
145+
'complete' => 1,
146+
'retriablyFailed' => 2,
147+
'notRetriablyFailed' => 3,
148+
'open' => 4,
149+
'rejected' => 5
150+
],
151+
'expectedResult' => 5
152+
]
153+
];
154+
}
155+
}

0 commit comments

Comments
 (0)