Retry.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\AsynchronousOperations\Controller\Adminhtml\Bulk;
  7. use Magento\AsynchronousOperations\Model\BulkManagement;
  8. use Magento\AsynchronousOperations\Model\BulkNotificationManagement;
  9. use Magento\Backend\App\Action\Context;
  10. use Magento\Backend\Model\View\Result\Redirect;
  11. use Magento\Backend\App\Action;
  12. use Magento\AsynchronousOperations\Model\AccessValidator;
  13. use Magento\Framework\Controller\ResultFactory;
  14. /**
  15. * Class Bulk Retry Controller
  16. */
  17. class Retry extends Action
  18. {
  19. /**
  20. * @var BulkManagement
  21. */
  22. private $bulkManagement;
  23. /**
  24. * @var BulkNotificationManagement
  25. */
  26. private $notificationManagement;
  27. /**
  28. * @var \Magento\AsynchronousOperations\Model\AccessValidator
  29. */
  30. private $accessValidator;
  31. /**
  32. * Retry constructor.
  33. * @param Context $context
  34. * @param BulkManagement $bulkManagement
  35. * @param BulkNotificationManagement $notificationManagement
  36. * @param AccessValidator $accessValidator
  37. */
  38. public function __construct(
  39. Context $context,
  40. BulkManagement $bulkManagement,
  41. BulkNotificationManagement $notificationManagement,
  42. AccessValidator $accessValidator
  43. ) {
  44. parent::__construct($context);
  45. $this->bulkManagement = $bulkManagement;
  46. $this->notificationManagement = $notificationManagement;
  47. $this->accessValidator = $accessValidator;
  48. }
  49. /**
  50. * @inheritDoc
  51. */
  52. protected function _isAllowed()
  53. {
  54. return $this->_authorization->isAllowed('Magento_Logging::system_magento_logging_bulk_operations')
  55. && $this->accessValidator->isAllowed($this->getRequest()->getParam('uuid'));
  56. }
  57. /**
  58. * {@inheritdoc}
  59. */
  60. public function execute()
  61. {
  62. $bulkUuid = $this->getRequest()->getParam('uuid');
  63. $isAjax = $this->getRequest()->getParam('isAjax');
  64. $operationsToRetry = (array)$this->getRequest()->getParam('operations_to_retry', []);
  65. $errorCodes = [];
  66. foreach ($operationsToRetry as $operationData) {
  67. if (isset($operationData['error_code'])) {
  68. $errorCodes[] = (int)$operationData['error_code'];
  69. }
  70. }
  71. $affectedOperations = $this->bulkManagement->retryBulk($bulkUuid, $errorCodes);
  72. $this->notificationManagement->ignoreBulks([$bulkUuid]);
  73. if (!$isAjax) {
  74. $this->messageManager->addSuccessMessage(
  75. __('%1 item(s) have been scheduled for update."', $affectedOperations)
  76. );
  77. /** @var Redirect $result */
  78. $result = $this->resultRedirectFactory->create();
  79. $result->setPath('bulk/index');
  80. } else {
  81. /** @var \Magento\Framework\Controller\Result\Json $result */
  82. $result = $this->resultFactory->create(ResultFactory::TYPE_JSON);
  83. $result->setHttpResponseCode(200);
  84. $response = new \Magento\Framework\DataObject();
  85. $response->setError(0);
  86. $result->setData($response);
  87. }
  88. return $result;
  89. }
  90. }