123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Integration\Controller\Adminhtml;
- use Magento\Backend\App\Action;
- use Magento\Integration\Api\OauthServiceInterface as IntegrationOauthService;
- /**
- * Controller for integrations management.
- *
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- */
- abstract class Integration extends Action
- {
- /**
- * Authorization level of a basic admin session
- *
- * @see _isAllowed()
- */
- const ADMIN_RESOURCE = 'Magento_Integration::integrations';
- /** Param Key for extracting integration id from Request */
- const PARAM_INTEGRATION_ID = 'id';
- /** Reauthorize flag is used to distinguish activation from reauthorization */
- const PARAM_REAUTHORIZE = 'reauthorize';
- const REGISTRY_KEY_CURRENT_INTEGRATION = 'current_integration';
- /** Saved API form data session key */
- const REGISTRY_KEY_CURRENT_RESOURCE = 'current_resource';
- /**
- * @var \Magento\Framework\Registry
- */
- protected $_registry;
- /**
- * @var \Psr\Log\LoggerInterface
- */
- protected $_logger;
- /**
- * @var \Magento\Integration\Api\IntegrationServiceInterface
- */
- protected $_integrationService;
- /**
- * @var \Magento\Integration\Api\OauthServiceInterface
- */
- protected $_oauthService;
- /**
- * @var \Magento\Framework\Json\Helper\Data
- */
- protected $jsonHelper;
- /**
- * @var \Magento\Integration\Helper\Data
- */
- protected $_integrationData;
- /**
- * @var \Magento\Integration\Model\ResourceModel\Integration\Collection
- */
- protected $_integrationCollection;
- /**
- * @var \Magento\Framework\Escaper
- */
- protected $escaper;
- /**
- * @param \Magento\Backend\App\Action\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Psr\Log\LoggerInterface $logger
- * @param \Magento\Integration\Api\IntegrationServiceInterface $integrationService
- * @param \Magento\Integration\Api\OauthServiceInterface $oauthService
- * @param \Magento\Framework\Json\Helper\Data $jsonHelper
- * @param \Magento\Integration\Helper\Data $integrationData
- * @param \Magento\Framework\Escaper $escaper
- * @param \Magento\Integration\Model\ResourceModel\Integration\Collection $integrationCollection
- */
- public function __construct(
- \Magento\Backend\App\Action\Context $context,
- \Magento\Framework\Registry $registry,
- \Psr\Log\LoggerInterface $logger,
- \Magento\Integration\Api\IntegrationServiceInterface $integrationService,
- \Magento\Integration\Api\OauthServiceInterface $oauthService,
- \Magento\Framework\Json\Helper\Data $jsonHelper,
- \Magento\Integration\Helper\Data $integrationData,
- \Magento\Framework\Escaper $escaper,
- \Magento\Integration\Model\ResourceModel\Integration\Collection $integrationCollection
- ) {
- parent::__construct($context);
- $this->_registry = $registry;
- $this->_logger = $logger;
- $this->_integrationService = $integrationService;
- $this->_oauthService = $oauthService;
- $this->jsonHelper = $jsonHelper;
- $this->_integrationData = $integrationData;
- $this->escaper = $escaper;
- $this->_integrationCollection = $integrationCollection;
- parent::__construct($context);
- }
- /**
- * Don't actually redirect if we've got AJAX request - return redirect URL instead.
- *
- * @param string $path
- * @param array $arguments
- * @return $this|\Magento\Backend\App\AbstractAction
- */
- protected function _redirect($path, $arguments = [])
- {
- if ($this->getRequest()->isXmlHttpRequest()) {
- $this->getResponse()->representJson(
- $this->jsonHelper->jsonEncode(['_redirect' => $this->getUrl($path, $arguments)])
- );
- return $this;
- } else {
- return parent::_redirect($path, $arguments);
- }
- }
- /**
- * Restore saved form resources
- *
- * @return void
- */
- protected function restoreResourceAndSaveToRegistry()
- {
- $restoredFormData = $this->_getSession()->getIntegrationData();
- if ($restoredFormData) {
- $resource = isset($restoredFormData['resource']) ? $restoredFormData['resource'] : [];
- $this->_registry->register(
- self::REGISTRY_KEY_CURRENT_RESOURCE,
- ['all_resources' => $restoredFormData['all_resources'], 'resource' => $resource]
- );
- }
- }
- }
|