Retry.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Analytics\Controller\Adminhtml\Subscription;
  7. use Magento\Analytics\Model\Config\Backend\Enabled\SubscriptionHandler;
  8. use Magento\Backend\App\Action;
  9. use Magento\Backend\App\Action\Context;
  10. use Magento\Framework\Controller\Result\Redirect;
  11. use Magento\Framework\Controller\ResultFactory;
  12. use Magento\Framework\Exception\LocalizedException;
  13. /**
  14. * Retry subscription to Magento BI Advanced Reporting.
  15. */
  16. class Retry extends Action
  17. {
  18. /**
  19. * Resource for managing subscription to Magento Analytics.
  20. *
  21. * @var SubscriptionHandler
  22. */
  23. private $subscriptionHandler;
  24. /**
  25. * @inheritdoc
  26. */
  27. const ADMIN_RESOURCE = 'Magento_Analytics::analytics_settings';
  28. /**
  29. * @param Context $context
  30. * @param SubscriptionHandler $subscriptionHandler
  31. */
  32. public function __construct(
  33. Context $context,
  34. SubscriptionHandler $subscriptionHandler
  35. ) {
  36. $this->subscriptionHandler = $subscriptionHandler;
  37. parent::__construct($context);
  38. }
  39. /**
  40. * Retry process of subscription.
  41. *
  42. * @return Redirect
  43. */
  44. public function execute()
  45. {
  46. /** @var Redirect $resultRedirect */
  47. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  48. try {
  49. $resultRedirect->setPath('adminhtml');
  50. $this->subscriptionHandler->processEnabled();
  51. } catch (LocalizedException $e) {
  52. $this->getMessageManager()->addExceptionMessage($e, $e->getMessage());
  53. } catch (\Exception $e) {
  54. $this->getMessageManager()->addExceptionMessage(
  55. $e,
  56. __('Sorry, there has been an error processing your request. Please try again later.')
  57. );
  58. }
  59. return $resultRedirect;
  60. }
  61. }