diff --git a/app/code/Magento/AsynchronousOperations/Model/MassSchedule.php b/app/code/Magento/AsynchronousOperations/Model/MassSchedule.php index 2d516e82f40..4cd63d8161e 100644 --- a/app/code/Magento/AsynchronousOperations/Model/MassSchedule.php +++ b/app/code/Magento/AsynchronousOperations/Model/MassSchedule.php @@ -8,6 +8,7 @@ namespace Magento\AsynchronousOperations\Model; +use Magento\Framework\App\ObjectManager; use Magento\Framework\DataObject\IdentityGeneratorInterface; use Magento\Framework\Exception\LocalizedException; use Magento\AsynchronousOperations\Api\Data\ItemStatusInterfaceFactory; @@ -54,6 +55,11 @@ class MassSchedule */ private $operationRepository; + /** + * @var TopicDescriptionPool + */ + private $topicDescriptionPool; + /** * Initialize dependencies. * @@ -63,6 +69,7 @@ class MassSchedule * @param BulkManagementInterface $bulkManagement * @param LoggerInterface $logger * @param OperationRepository $operationRepository + * @param TopicDescriptionPool $topicDescriptionPool */ public function __construct( IdentityGeneratorInterface $identityService, @@ -70,7 +77,8 @@ public function __construct( AsyncResponseInterfaceFactory $asyncResponseFactory, BulkManagementInterface $bulkManagement, LoggerInterface $logger, - OperationRepository $operationRepository + OperationRepository $operationRepository, + TopicDescriptionPool $topicDescriptionPool = null ) { $this->identityService = $identityService; $this->itemStatusInterfaceFactory = $itemStatusInterfaceFactory; @@ -78,22 +86,35 @@ public function __construct( $this->bulkManagement = $bulkManagement; $this->logger = $logger; $this->operationRepository = $operationRepository; + $this->topicDescriptionPool = $topicDescriptionPool ?: + ObjectManager::getInstance()->get(TopicDescriptionPool::class); } /** * Schedule new bulk operation based on the list of entities * - * @param $topicName - * @param $entitiesArray - * @param null $groupId - * @param null $userId + * @param string $topicName + * @param array $entitiesArray + * @param int|null $groupId + * @param int|null $userId + * @param string|null $bulkDescription * @return AsyncResponseInterface * @throws BulkException * @throws LocalizedException */ - public function publishMass($topicName, array $entitiesArray, $groupId = null, $userId = null) - { - $bulkDescription = __('Topic %1', $topicName); + public function publishMass( + $topicName, + array $entitiesArray, + $groupId = null, + $userId = null, + $bulkDescription = null + ) { + if ($bulkDescription === null) { + $bulkDescription = __($this->topicDescriptionPool->getDescription($topicName)); + } + if ($bulkDescription === null) { + $bulkDescription = __('Topic %1', $topicName); + } if ($groupId == null) { $groupId = $this->identityService->generateId(); diff --git a/app/code/Magento/AsynchronousOperations/Model/TopicDescriptionPool.php b/app/code/Magento/AsynchronousOperations/Model/TopicDescriptionPool.php new file mode 100644 index 00000000000..60fc51d1753 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Model/TopicDescriptionPool.php @@ -0,0 +1,46 @@ +descriptions = $descriptions; + } + + /** + * Get description for a given topic name + * + * @param string $topicName + * @return string|null + */ + public function getDescription($topicName) + { + if (isset($this->descriptions[$topicName])) { + return $this->descriptions[$topicName]; + } + + return null; + } +} diff --git a/app/code/Magento/AsynchronousOperations/Test/Unit/Model/TopicDescriptionPoolTest.php b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/TopicDescriptionPoolTest.php new file mode 100644 index 00000000000..6a80443e750 --- /dev/null +++ b/app/code/Magento/AsynchronousOperations/Test/Unit/Model/TopicDescriptionPoolTest.php @@ -0,0 +1,52 @@ + 'Test topic 1', + 'async.V1.test.topic2' => 'Test topic 2', + 'async.V1.test.topic3' => 'Test topic 3', + ]; + + protected function setUp() + { + $this->topicDescriptionPool = (new ObjectManager($this))->getObject( + TopicDescriptionPool::class, + [ + 'descriptions' => $this->testTopics + ] + ); + } + + public function testGetDescriptionOnExistingValues() + { + foreach ($this->testTopics as $topic => $description) { + self::assertEquals($description, $this->topicDescriptionPool->getDescription($topic)); + } + } + + public function testGetDescriptionOnNonExistingValue() + { + self::assertNull($this->topicDescriptionPool->getDescription('non.existing.topic')); + } +}