@@ -175,39 +175,33 @@ public function publishMass($topicName, $entitiesArray, $groupId = null)
175
175
176
176
$ operations = [];
177
177
$ requestItems = [];
178
- foreach ($ entitiesArray as $ key => $ entityParams ) {
178
+ foreach ($ entitiesArray as $ entityParams ) {
179
179
/** @var \Magento\WebapiAsync\Api\Data\AsyncResponse\ItemStatusInterface $requestItem */
180
180
$ requestItem = $ this ->itemStatusInterfaceFactory ->create ();
181
181
182
182
try {
183
183
$ this ->messageValidator ->validate ($ topicName , $ entityParams );
184
184
$ data = $ this ->messageEncoder ->encode ($ topicName , $ entityParams );
185
-
186
- $ serializedData = [
187
- 'entity_id ' => null ,
188
- 'entity_link ' => '' ,
189
- 'meta_information ' => $ data ,
190
- ];
191
- $ data = [
192
- 'data ' => [
193
- OperationInterface::BULK_ID => $ groupId ,
194
- OperationInterface::TOPIC_NAME => $ topicName ,
195
- OperationInterface::SERIALIZED_DATA => $ this ->jsonHelper ->serialize ($ serializedData ),
196
- OperationInterface::STATUS => OperationInterface::STATUS_TYPE_OPEN ,
197
- ],
198
- ];
199
-
200
- /** @var \Magento\AsynchronousOperations\Api\Data\OperationInterface $operation */
201
- $ operation = $ this ->operationFactory ->create ($ data );
202
- $ operations [] = $ this ->entityManager ->save ($ operation );
203
-
204
- $ requestItem ->setId ($ key );
205
- $ requestItem ->setStatus (ItemStatusInterface::STATUS_ACCEPTED );
185
+ $ operationStatus = OperationInterface::STATUS_TYPE_OPEN ;
206
186
} catch (\Exception $ exception ) {
207
- $ requestItem ->setId ($ key );
187
+ $ data = $ entityParams ;
188
+ //TODO after merge with BulkApi Status need change cons from OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED to OperationInterface::STATUS_TYPE_REJECTED
189
+ $ operationStatus = OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED ;
190
+ }
191
+
192
+ $ operation = $ this ->saveOperation ($ groupId , $ topicName , $ data , $ operationStatus );
193
+ if (!isset ($ exception )) {
194
+ $ operations [] = $ operation ;
195
+ }
196
+
197
+ $ requestItem ->setId ($ operation ->getId ());
198
+ $ requestItem ->setStatus (ItemStatusInterface::STATUS_ACCEPTED );
199
+
200
+ if (isset ($ exception )) {
208
201
$ requestItem ->setStatus (ItemStatusInterface::STATUS_REJECTED );
209
202
$ requestItem ->setErrorMessage ($ exception );
210
203
$ requestItem ->setErrorCode ($ exception );
204
+ unset($ exception );
211
205
}
212
206
213
207
$ requestItems [] = $ requestItem ;
@@ -227,4 +221,43 @@ public function publishMass($topicName, $entitiesArray, $groupId = null)
227
221
228
222
return $ asyncResponse ;
229
223
}
224
+
225
+ /**
226
+ * @param string $groupId
227
+ * @param string $topicName
228
+ * @param mixed $data
229
+ * @param int $operationStatus
230
+ * @param null $error
231
+ * @param null $errorCode
232
+ * @return \Magento\AsynchronousOperations\Api\Data\OperationInterface
233
+ */
234
+ private function saveOperation (
235
+ $ groupId ,
236
+ $ topicName ,
237
+ $ data ,
238
+ $ operationStatus = OperationInterface::STATUS_TYPE_OPEN ,
239
+ $ error = null ,
240
+ $ errorCode = null
241
+ ) {
242
+ $ serializedData = [
243
+ 'entity_id ' => null ,
244
+ 'entity_link ' => '' ,
245
+ 'meta_information ' => $ data ,
246
+ ];
247
+ $ data = [
248
+ 'data ' => [
249
+ OperationInterface::BULK_ID => $ groupId ,
250
+ OperationInterface::TOPIC_NAME => $ topicName ,
251
+ OperationInterface::SERIALIZED_DATA => $ this ->jsonHelper ->serialize ($ serializedData ),
252
+ OperationInterface::STATUS => $ operationStatus ,
253
+ OperationInterface::RESULT_MESSAGE => $ error ,
254
+ OperationInterface::ERROR_CODE => $ errorCode ,
255
+ ],
256
+ ];
257
+
258
+ /** @var \Magento\AsynchronousOperations\Api\Data\OperationInterface $operation */
259
+ $ operation = $ this ->operationFactory ->create ($ data );
260
+
261
+ return $ this ->entityManager ->save ($ operation );
262
+ }
230
263
}
0 commit comments