Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OperationRepository.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
10 
12 use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
17 
22 {
26  private $operationFactory;
27 
31  private $jsonSerializer;
32 
36  private $entityManager;
37 
41  private $messageEncoder;
42 
46  private $messageValidator;
47 
55  public function __construct(
56  OperationInterfaceFactory $operationFactory,
57  EntityManager $entityManager,
58  MessageValidator $messageValidator,
59  MessageEncoder $messageEncoder,
60  Json $jsonSerializer
61  ) {
62  $this->operationFactory = $operationFactory;
63  $this->jsonSerializer = $jsonSerializer;
64  $this->messageEncoder = $messageEncoder;
65  $this->messageValidator = $messageValidator;
66  $this->entityManager = $entityManager;
67  }
68 
75  public function createByTopic($topicName, $entityParams, $groupId)
76  {
77  $this->messageValidator->validate($topicName, $entityParams);
78  $encodedMessage = $this->messageEncoder->encode($topicName, $entityParams);
79 
80  $serializedData = [
81  'entity_id' => null,
82  'entity_link' => '',
83  'meta_information' => $encodedMessage,
84  ];
85  $data = [
86  'data' => [
88  OperationInterface::TOPIC_NAME => $topicName,
89  OperationInterface::SERIALIZED_DATA => $this->jsonSerializer->serialize($serializedData),
91  ],
92  ];
93 
95  $operation = $this->operationFactory->create($data);
96  return $this->entityManager->save($operation);
97  }
98 }
__construct(OperationInterfaceFactory $operationFactory, EntityManager $entityManager, MessageValidator $messageValidator, MessageEncoder $messageEncoder, Json $jsonSerializer)