Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Delete.php
Go to the documentation of this file.
1 <?php
8 
13 
15 {
21  public function execute()
22  {
24  $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
25  $integrationId = (int)$this->getRequest()->getParam(self::PARAM_INTEGRATION_ID);
26  try {
27  if ($integrationId) {
28  $integrationData = $this->_integrationService->get($integrationId);
29  if ($this->_integrationData->isConfigType($integrationData)) {
30  $this->messageManager->addError(
31  __(
32  "Uninstall the extension to remove integration '%1'.",
33  $this->escaper->escapeHtml($integrationData[Info::DATA_NAME])
34  )
35  );
36  return $resultRedirect->setPath('*/*/');
37  }
38  $integrationData = $this->_integrationService->delete($integrationId);
39  if (!$integrationData[Info::DATA_ID]) {
40  $this->messageManager->addError(__('This integration no longer exists.'));
41  } else {
42  //Integration deleted successfully, now safe to delete the associated consumer data
43  if (isset($integrationData[Info::DATA_CONSUMER_ID])) {
44  $this->_oauthService->deleteConsumer($integrationData[Info::DATA_CONSUMER_ID]);
45  }
46  $this->_registry->register(self::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
47  $this->messageManager->addSuccess(
48  __(
49  "The integration '%1' has been deleted.",
50  $this->escaper->escapeHtml($integrationData[Info::DATA_NAME])
51  )
52  );
53  }
54  } else {
55  $this->messageManager->addError(__('Integration ID is not specified or is invalid.'));
56  }
57  } catch (IntegrationException $e) {
58  $this->messageManager->addError($e->getMessage());
59  } catch (\Exception $e) {
60  $this->_logger->critical($e);
61  }
62 
63  return $resultRedirect->setPath('*/*/');
64  }
65 }
__()
Definition: __.php:13