Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
operation_searchable.php
Go to the documentation of this file.
1 <?php
7 declare(strict_types=1);
8 
11 
15 $resource = Bootstrap::getObjectManager()->get(\Magento\Framework\App\ResourceConnection::class);
16 $connection = $resource->getConnection();
17 $bulkTable = $resource->getTableName('magento_bulk');
18 $operationTable = $resource->getTableName('magento_operation');
19 
20 $bulks = [
21  'started_searchable' => [
22  'uuid' => 'bulk-uuid-searchable-6',
23  'user_id' => 1,
24  'description' => 'Bulk Description',
25  'operation_count' => 3,
26  'start_time' => '2009-10-10 00:00:00',
27  ],
28 ];
29 // Only processed operations are saved into database (i.e. operations that are not in 'open' state)
31  [
32  'bulk_uuid' => 'bulk-uuid-searchable-6',
33  'topic_name' => 'topic-5',
34  'serialized_data' => json_encode(['entity_id' => 5]),
35  'status' => OperationInterface::STATUS_TYPE_COMPLETE,
36  'error_code' => null,
37  'result_message' => null,
38  ],
39  [
40  'bulk_uuid' => 'bulk-uuid-searchable-6',
41  'topic_name' => 'topic-5',
42  'serialized_data' => json_encode(['entity_id' => 5, 'meta_information' => 'Test']),
43  'status' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED,
44  'error_code' => 1111,
45  'result_message' => 'Something went wrong during your request',
46  ],
47  [
48  'bulk_uuid' => 'bulk-uuid-searchable-6',
49  'topic_name' => 'topic-5',
50  'serialized_data' => json_encode(['entity_id' => 5]),
51  'status' => OperationInterface::STATUS_TYPE_RETRIABLY_FAILED,
52  'error_code' => 2222,
53  'result_message' => 'Entity with ID=4 does not exist',
54  ],
55 
56 ];
57 
58 $bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`, `start_time`)"
59  . " VALUES (:uuid, :user_id, :description, :operation_count, :start_time);";
60 foreach ($bulks as $bulk) {
61  $connection->query($bulkQuery, $bulk);
62 }
63 
64 $operationQuery = "INSERT INTO {$operationTable}"
65  . " (`bulk_uuid`, `topic_name`, `serialized_data`, `status`, `error_code`, `result_message`)"
66  . " VALUES (:bulk_uuid, :topic_name, :serialized_data, :status, :error_code, :result_message);";
67 foreach ($operations as $operation) {
68  $connection->query($operationQuery, $operation);
69 }
foreach($bulks as $bulk) $operationQuery