operation_searchable.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. use Magento\TestFramework\Helper\Bootstrap;
  8. use Magento\Framework\Bulk\OperationInterface;
  9. /**
  10. * @var $resource Magento\Framework\App\ResourceConnection
  11. */
  12. $resource = Bootstrap::getObjectManager()->get(\Magento\Framework\App\ResourceConnection::class);
  13. $connection = $resource->getConnection();
  14. $bulkTable = $resource->getTableName('magento_bulk');
  15. $operationTable = $resource->getTableName('magento_operation');
  16. $bulks = [
  17. 'started_searchable' => [
  18. 'uuid' => 'bulk-uuid-searchable-6',
  19. 'user_id' => 1,
  20. 'description' => 'Bulk Description',
  21. 'operation_count' => 3,
  22. 'start_time' => '2009-10-10 00:00:00',
  23. ],
  24. ];
  25. // Only processed operations are saved into database (i.e. operations that are not in 'open' state)
  26. $operations = [
  27. [
  28. 'bulk_uuid' => 'bulk-uuid-searchable-6',
  29. 'topic_name' => 'topic-5',
  30. 'serialized_data' => json_encode(['entity_id' => 5]),
  31. 'status' => OperationInterface::STATUS_TYPE_COMPLETE,
  32. 'error_code' => null,
  33. 'result_message' => null,
  34. ],
  35. [
  36. 'bulk_uuid' => 'bulk-uuid-searchable-6',
  37. 'topic_name' => 'topic-5',
  38. 'serialized_data' => json_encode(['entity_id' => 5, 'meta_information' => 'Test']),
  39. 'status' => OperationInterface::STATUS_TYPE_NOT_RETRIABLY_FAILED,
  40. 'error_code' => 1111,
  41. 'result_message' => 'Something went wrong during your request',
  42. ],
  43. [
  44. 'bulk_uuid' => 'bulk-uuid-searchable-6',
  45. 'topic_name' => 'topic-5',
  46. 'serialized_data' => json_encode(['entity_id' => 5]),
  47. 'status' => OperationInterface::STATUS_TYPE_RETRIABLY_FAILED,
  48. 'error_code' => 2222,
  49. 'result_message' => 'Entity with ID=4 does not exist',
  50. ],
  51. ];
  52. $bulkQuery = "INSERT INTO {$bulkTable} (`uuid`, `user_id`, `description`, `operation_count`, `start_time`)"
  53. . " VALUES (:uuid, :user_id, :description, :operation_count, :start_time);";
  54. foreach ($bulks as $bulk) {
  55. $connection->query($bulkQuery, $bulk);
  56. }
  57. $operationQuery = "INSERT INTO {$operationTable}"
  58. . " (`bulk_uuid`, `topic_name`, `serialized_data`, `status`, `error_code`, `result_message`)"
  59. . " VALUES (:bulk_uuid, :topic_name, :serialized_data, :status, :error_code, :result_message);";
  60. foreach ($operations as $operation) {
  61. $connection->query($operationQuery, $operation);
  62. }