Skip to content
This repository was archived by the owner on May 20, 2019. It is now read-only.

Commit ed7ff2f

Browse files
committed
Add topic description feature
1 parent 8fd89cf commit ed7ff2f

File tree

3 files changed

+127
-8
lines changed

3 files changed

+127
-8
lines changed

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
namespace Magento\AsynchronousOperations\Model;
1010

11+
use Magento\Framework\App\ObjectManager;
1112
use Magento\Framework\DataObject\IdentityGeneratorInterface;
1213
use Magento\Framework\Exception\LocalizedException;
1314
use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory;
@@ -54,6 +55,11 @@ class MassSchedule
5455
*/
5556
private $operationRepository;
5657

58+
/**
59+
* @var TopicDescriptionPool
60+
*/
61+
private $topicDescriptionPool;
62+
5763
/**
5864
* Initialize dependencies.
5965
*
@@ -63,37 +69,52 @@ class MassSchedule
6369
* @param BulkManagementInterface $bulkManagement
6470
* @param LoggerInterface $logger
6571
* @param OperationRepository $operationRepository
72+
* @param TopicDescriptionPool $topicDescriptionPool
6673
*/
6774
public function __construct(
6875
IdentityGeneratorInterface $identityService,
6976
ItemStatusInterfaceFactory $itemStatusInterfaceFactory,
7077
AsyncResponseInterfaceFactory $asyncResponseFactory,
7178
BulkManagementInterface $bulkManagement,
7279
LoggerInterface $logger,
73-
OperationRepository $operationRepository
80+
OperationRepository $operationRepository,
81+
TopicDescriptionPool $topicDescriptionPool = null
7482
) {
7583
$this->identityService = $identityService;
7684
$this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory;
7785
$this->asyncResponseFactory = $asyncResponseFactory;
7886
$this->bulkManagement = $bulkManagement;
7987
$this->logger = $logger;
8088
$this->operationRepository = $operationRepository;
89+
$this->topicDescriptionPool = $topicDescriptionPool ?:
90+
ObjectManager::getInstance()->get(TopicDescriptionPool::class);
8191
}
8292

8393
/**
8494
* Schedule new bulk operation based on the list of entities
8595
*
86-
* @param $topicName
87-
* @param $entitiesArray
88-
* @param null $groupId
89-
* @param null $userId
96+
* @param string $topicName
97+
* @param array $entitiesArray
98+
* @param int|null $groupId
99+
* @param int|null $userId
100+
* @param string|null $bulkDescription
90101
* @return AsyncResponseInterface
91102
* @throws BulkException
92103
* @throws LocalizedException
93104
*/
94-
public function publishMass($topicName, array $entitiesArray, $groupId = null, $userId = null)
95-
{
96-
$bulkDescription = __('Topic %1', $topicName);
105+
public function publishMass(
106+
$topicName,
107+
array $entitiesArray,
108+
$groupId = null,
109+
$userId = null,
110+
$bulkDescription = null
111+
) {
112+
if ($bulkDescription === null) {
113+
$bulkDescription = __($this->topicDescriptionPool->getDescription($topicName));
114+
}
115+
if ($bulkDescription === null) {
116+
$bulkDescription = __('Topic %1', $topicName);
117+
}
97118

98119
if ($groupId == null) {
99120
$groupId = $this->identityService->generateId();
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
namespace Magento\AsynchronousOperations\Model;
10+
11+
/**
12+
* Bulk operations description pool
13+
*/
14+
class TopicDescriptionPool
15+
{
16+
/**
17+
* @var array
18+
*/
19+
private $descriptions;
20+
21+
/**
22+
* BulkDescriptionPool constructor
23+
*
24+
* @param array $descriptions
25+
*/
26+
public function __construct(
27+
$descriptions = []
28+
) {
29+
$this->descriptions = $descriptions;
30+
}
31+
32+
/**
33+
* Get description for a given topic name
34+
*
35+
* @param string $topicName
36+
* @return string|null
37+
*/
38+
public function getDescription($topicName)
39+
{
40+
if (isset($this->descriptions[$topicName])) {
41+
return $this->descriptions[$topicName];
42+
}
43+
44+
return null;
45+
}
46+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento\AsynchronousOperations\Test\Unit\Model;
8+
9+
use Magento\AsynchronousOperations\Model\TopicDescriptionPool;
10+
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
11+
12+
/**
13+
* Class StatusMapperTest
14+
*/
15+
class TopicDescriptionPoolTest extends \PHPUnit\Framework\TestCase
16+
{
17+
/**
18+
* @var \Magento\AsynchronousOperations\Model\TopicDescriptionPool
19+
*/
20+
private $topicDescriptionPool;
21+
22+
/**
23+
* @var array
24+
*/
25+
private $testTopics = [
26+
'async.V1.test.topic1' => 'Test topic 1',
27+
'async.V1.test.topic2' => 'Test topic 2',
28+
'async.V1.test.topic3' => 'Test topic 3',
29+
];
30+
31+
protected function setUp()
32+
{
33+
$this->topicDescriptionPool = (new ObjectManager($this))->getObject(
34+
TopicDescriptionPool::class,
35+
[
36+
'descriptions' => $this->testTopics
37+
]
38+
);
39+
}
40+
41+
public function testGetDescriptionOnExistingValues()
42+
{
43+
foreach ($this->testTopics as $topic => $description) {
44+
self::assertEquals($description, $this->topicDescriptionPool->getDescription($topic));
45+
}
46+
}
47+
48+
public function testGetDescriptionOnNonExistingValue()
49+
{
50+
self::assertNull($this->topicDescriptionPool->getDescription('non.existing.topic'));
51+
}
52+
}

0 commit comments

Comments
 (0)