OperationManagement.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Model;
  7. use Magento\AsynchronousOperations\Api\Data\OperationInterfaceFactory;
  8. use Magento\Framework\EntityManager\EntityManager;
  9. /**
  10. * Class OperationManagement
  11. */
  12. class OperationManagement implements \Magento\Framework\Bulk\OperationManagementInterface
  13. {
  14. /**
  15. * @var EntityManager
  16. */
  17. private $entityManager;
  18. /**
  19. * @var OperationInterfaceFactory
  20. */
  21. private $operationFactory;
  22. /**
  23. * @var \Psr\Log\LoggerInterface
  24. */
  25. private $logger;
  26. /**
  27. * OperationManagement constructor.
  28. *
  29. * @param EntityManager $entityManager
  30. * @param OperationInterfaceFactory $operationFactory
  31. * @param \Psr\Log\LoggerInterface $logger
  32. */
  33. public function __construct(
  34. EntityManager $entityManager,
  35. OperationInterfaceFactory $operationFactory,
  36. \Psr\Log\LoggerInterface $logger
  37. ) {
  38. $this->entityManager = $entityManager;
  39. $this->operationFactory = $operationFactory;
  40. $this->logger = $logger;
  41. }
  42. /**
  43. * @inheritDoc
  44. */
  45. public function changeOperationStatus(
  46. $operationId,
  47. $status,
  48. $errorCode = null,
  49. $message = null,
  50. $data = null,
  51. $resultData = null
  52. ) {
  53. try {
  54. $operationEntity = $this->operationFactory->create();
  55. $this->entityManager->load($operationEntity, $operationId);
  56. $operationEntity->setErrorCode($errorCode);
  57. $operationEntity->setStatus($status);
  58. $operationEntity->setResultMessage($message);
  59. $operationEntity->setSerializedData($data);
  60. $operationEntity->setResultSerializedData($resultData);
  61. $this->entityManager->save($operationEntity);
  62. } catch (\Exception $exception) {
  63. $this->logger->critical($exception->getMessage());
  64. return false;
  65. }
  66. return true;
  67. }
  68. }