1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?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]
);
}
}
}