operationFactory = $operationFactory; $this->jsonSerializer = $jsonSerializer; $this->messageValidator = $messageValidator; $this->entityManager = $entityManager; $this->inputParamsResolver = $inputParamsResolver; $this->storeManager = $storeManager?: ObjectManager::getInstance()->get(StoreManagerInterface::class); } /** * @inheritDoc */ public function create($topicName, $entityParams, $groupId, $operationId): OperationInterface { $this->messageValidator->validate($topicName, $entityParams); $requestData = $this->inputParamsResolver->getInputData(); if ($operationId === null || !isset($requestData[$operationId])) { throw new \InvalidArgumentException( 'Parameter "$operationId" must not be NULL and must exist in input data' ); } $encodedMessage = $this->jsonSerializer->serialize($requestData[$operationId]); $serializedData = [ 'entity_id' => null, 'entity_link' => '', 'meta_information' => $encodedMessage, ]; try { $storeId = $this->storeManager->getStore()->getId(); $serializedData['store_id'] = $storeId; // phpcs:ignore Magento2.CodeAnalysis.EmptyBlock.DetectedCatch } catch (NoSuchEntityException $e) { // skip setting store id in the serialized data if store doesn't exist } $data = [ 'data' => [ OperationInterface::ID => $operationId, OperationInterface::BULK_ID => $groupId, OperationInterface::TOPIC_NAME => $topicName, OperationInterface::SERIALIZED_DATA => $this->jsonSerializer->serialize($serializedData), OperationInterface::STATUS => OperationInterface::STATUS_TYPE_OPEN, ], ]; /** @var OperationInterface $operation */ $operation = $this->operationFactory->create($data); return $operation; } }