Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TokensDialog.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Framework\App\Action\HttpGetActionInterface as HttpGetActionInterface;
11 
13 {
21  protected function _setActivationSuccessMsg($isReauthorize, $integrationName)
22  {
23  $integrationName = $this->escaper->escapeHtml($integrationName);
24  $successMsg = $isReauthorize ? __(
25  "The integration '%1' has been re-authorized.",
26  $integrationName
27  ) : __(
28  "The integration '%1' has been activated.",
29  $integrationName
30  );
31  $this->messageManager->addSuccess($successMsg);
32  }
33 
39  public function execute()
40  {
41  try {
42  $integrationId = $this->getRequest()->getParam(self::PARAM_INTEGRATION_ID);
43  $integration = $this->_integrationService->get($integrationId);
44  $clearExistingToken = (int)$this->getRequest()->getParam(self::PARAM_REAUTHORIZE, 0);
45  if ($this->_oauthService->createAccessToken($integration->getConsumerId(), $clearExistingToken)) {
46  $integration->setStatus(IntegrationModel::STATUS_ACTIVE)->save();
47  }
48  // Important to call get() once again - that will pull newly generated token
49  $this->_registry->register(
50  self::REGISTRY_KEY_CURRENT_INTEGRATION,
51  $this->_integrationService->get($integrationId)->getData()
52  );
53  } catch (\Magento\Framework\Exception\LocalizedException $e) {
54  $this->messageManager->addError($e->getMessage());
55  $this->_redirect('*/*');
56  return;
57  } catch (\Exception $e) {
58  $this->_logger->critical($e);
59  $this->messageManager->addError(__('Internal error. Check exception log for details.'));
60  $this->_redirect('*/*');
61  return;
62  }
63  $this->_view->loadLayout(false);
64  //This cannot precede loadlayout(false) else the messages will be removed
65  $this->_setActivationSuccessMsg($clearExistingToken, $integration->getName());
66  $this->_view->renderLayout();
67  }
68 }
__()
Definition: __.php:13