Delete.php 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. /**
  3. *
  4. * Copyright © Magento, Inc. All rights reserved.
  5. * See COPYING.txt for license details.
  6. */
  7. namespace Magento\Integration\Controller\Adminhtml\Integration;
  8. use Magento\Framework\App\Action\HttpPostActionInterface;
  9. use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
  10. use Magento\Framework\Exception\IntegrationException;
  11. use Magento\Framework\Controller\ResultFactory;
  12. class Delete extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpPostActionInterface
  13. {
  14. /**
  15. * Delete the integration.
  16. *
  17. * @return \Magento\Backend\Model\View\Result\Redirect
  18. */
  19. public function execute()
  20. {
  21. /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
  22. $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
  23. $integrationId = (int)$this->getRequest()->getParam(self::PARAM_INTEGRATION_ID);
  24. try {
  25. if ($integrationId) {
  26. $integrationData = $this->_integrationService->get($integrationId);
  27. if ($this->_integrationData->isConfigType($integrationData)) {
  28. $this->messageManager->addError(
  29. __(
  30. "Uninstall the extension to remove integration '%1'.",
  31. $this->escaper->escapeHtml($integrationData[Info::DATA_NAME])
  32. )
  33. );
  34. return $resultRedirect->setPath('*/*/');
  35. }
  36. $integrationData = $this->_integrationService->delete($integrationId);
  37. if (!$integrationData[Info::DATA_ID]) {
  38. $this->messageManager->addError(__('This integration no longer exists.'));
  39. } else {
  40. //Integration deleted successfully, now safe to delete the associated consumer data
  41. if (isset($integrationData[Info::DATA_CONSUMER_ID])) {
  42. $this->_oauthService->deleteConsumer($integrationData[Info::DATA_CONSUMER_ID]);
  43. }
  44. $this->_registry->register(self::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
  45. $this->messageManager->addSuccess(
  46. __(
  47. "The integration '%1' has been deleted.",
  48. $this->escaper->escapeHtml($integrationData[Info::DATA_NAME])
  49. )
  50. );
  51. }
  52. } else {
  53. $this->messageManager->addError(__('Integration ID is not specified or is invalid.'));
  54. }
  55. } catch (IntegrationException $e) {
  56. $this->messageManager->addError($e->getMessage());
  57. } catch (\Exception $e) {
  58. $this->_logger->critical($e);
  59. }
  60. return $resultRedirect->setPath('*/*/');
  61. }
  62. }