Edit.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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\HttpGetActionInterface as HttpGetActionInterface;
  9. use Magento\Backend\App\Action;
  10. use Magento\Integration\Block\Adminhtml\Integration\Edit\Tab\Info;
  11. use Magento\Framework\Exception\IntegrationException;
  12. class Edit extends \Magento\Integration\Controller\Adminhtml\Integration implements HttpGetActionInterface
  13. {
  14. /**
  15. * Edit integration action.
  16. *
  17. * @return void
  18. */
  19. public function execute()
  20. {
  21. /** Try to recover integration data from session if it was added during previous request which failed. */
  22. $integrationId = (int)$this->getRequest()->getParam(self::PARAM_INTEGRATION_ID);
  23. if ($integrationId) {
  24. try {
  25. $integrationData = $this->_integrationService->get($integrationId)->getData();
  26. $originalName = $this->escaper->escapeHtml($integrationData[Info::DATA_NAME]);
  27. } catch (IntegrationException $e) {
  28. $this->messageManager->addError($this->escaper->escapeHtml($e->getMessage()));
  29. $this->_redirect('*/*/');
  30. return;
  31. } catch (\Exception $e) {
  32. $this->_logger->critical($e);
  33. $this->messageManager->addError(__('Internal error. Check exception log for details.'));
  34. $this->_redirect('*/*');
  35. return;
  36. }
  37. $restoredIntegration = $this->_getSession()->getIntegrationData();
  38. if ($restoredIntegration) {
  39. $integrationData = array_merge($integrationData, $restoredIntegration);
  40. }
  41. } else {
  42. $this->messageManager->addError(__('Integration ID is not specified or is invalid.'));
  43. $this->_redirect('*/*/');
  44. return;
  45. }
  46. $this->_registry->register(self::REGISTRY_KEY_CURRENT_INTEGRATION, $integrationData);
  47. $this->restoreResourceAndSaveToRegistry();
  48. $this->_view->loadLayout();
  49. $this->_getSession()->setIntegrationData([]);
  50. $this->_setActiveMenu('Magento_Integration::system_integrations');
  51. if ($this->_integrationData->isConfigType($integrationData)) {
  52. $title = __('View "%1" Integration', $originalName);
  53. } else {
  54. $title = __('Edit "%1" Integration', $originalName);
  55. }
  56. $this->_addBreadcrumb($title, $title);
  57. $this->_view->getPage()->getConfig()->getTitle()->prepend($title);
  58. $this->_view->renderLayout();
  59. }
  60. }