|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* (c) shopware AG <[email protected]> |
|
4
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
5
|
|
|
* file that was distributed with this source code. |
|
6
|
|
|
*/ |
|
7
|
|
|
|
|
8
|
|
|
use Shopware\Bundle\PluginInstallerBundle\Service\InstallerService; |
|
9
|
|
|
use Shopware\Components\CSRFWhitelistAware; |
|
10
|
|
|
use ShopwarePlugins\Connect\Components\Config; |
|
11
|
|
|
use ShopwarePlugins\Connect\Components\Logger; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @category Shopware |
|
15
|
|
|
* @package Shopware\Plugins\SwagConnect |
|
16
|
|
|
* @copyright Copyright (c) 2013, shopware AG (http://www.shopware.de) |
|
17
|
|
|
* @author Heiner Lohaus |
|
18
|
|
|
*/ |
|
19
|
|
|
class Shopware_Controllers_Backend_ConnectGateway extends \Enlight_Controller_Action implements CSRFWhitelistAware |
|
|
|
|
|
|
20
|
|
|
{ |
|
21
|
|
|
/** |
|
22
|
|
|
* @var Config |
|
23
|
|
|
*/ |
|
24
|
|
|
private $configComponent; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Disable authentication and JSon renderer |
|
28
|
|
|
*/ |
|
29
|
|
|
public function init() |
|
30
|
|
|
{ |
|
31
|
|
|
Shopware()->Plugins()->Backend()->Auth()->setNoAuth(); |
|
32
|
|
|
Shopware()->Plugins()->Controller()->ViewRenderer()->setNoRender(); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return Logger |
|
37
|
|
|
*/ |
|
38
|
|
|
public function getLogger() |
|
39
|
|
|
{ |
|
40
|
|
|
$loggingEnabled = $this->getConfigComponent()->getConfig('logRequest'); |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
return new Logger(Shopware()->Db(), $loggingEnabled); |
|
|
|
|
|
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* @return \Shopware\Connect\SDK |
|
47
|
|
|
*/ |
|
48
|
|
|
public function getSDK() |
|
49
|
|
|
{ |
|
50
|
|
|
return Shopware()->Container()->get('ConnectSDK'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
public function getRestApiRequest() |
|
54
|
|
|
{ |
|
55
|
|
|
return Shopware()->Container()->get('swagconnect.rest_api_request'); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @return InstallerService |
|
60
|
|
|
*/ |
|
61
|
|
|
public function getPluginManager() |
|
62
|
|
|
{ |
|
63
|
|
|
return Shopware()->Container()->get('shopware_plugininstaller.plugin_manager'); |
|
64
|
|
|
} |
|
65
|
|
|
|
|
66
|
|
|
/** |
|
67
|
|
|
* @return Config |
|
68
|
|
|
*/ |
|
69
|
|
|
public function getConfigComponent() |
|
70
|
|
|
{ |
|
71
|
|
|
if (!$this->configComponent) { |
|
72
|
|
|
$this->configComponent = new Config(Shopware()->Models()); |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return $this->configComponent; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Main connect interface |
|
80
|
|
|
* |
|
81
|
|
|
* @throws \Exception |
|
82
|
|
|
*/ |
|
83
|
|
|
public function indexAction() |
|
|
|
|
|
|
84
|
|
|
{ |
|
85
|
|
|
$this->Response()->setHeader('Content-Type', 'text/xml; charset=utf-8'); |
|
86
|
|
|
|
|
87
|
|
|
$request = file_get_contents('php://input'); |
|
88
|
|
|
$logger = $this->getLogger(); |
|
89
|
|
|
|
|
90
|
|
|
try { |
|
91
|
|
|
$this->get('events')->notify( |
|
92
|
|
|
'Shopware_Connect_SDK_Handle_Before', |
|
93
|
|
|
[ $request ] |
|
94
|
|
|
); |
|
95
|
|
|
|
|
96
|
|
|
$sdk = $this->getSDK(); |
|
97
|
|
|
$result = $sdk->handle( |
|
98
|
|
|
$request |
|
99
|
|
|
); |
|
100
|
|
|
|
|
101
|
|
|
$this->get('events')->notify( |
|
102
|
|
|
'Shopware_Connect_SDK_Handle_After', |
|
103
|
|
|
[ $request, $result ] |
|
104
|
|
|
); |
|
105
|
|
|
} catch (\Exception $e) { |
|
106
|
|
|
// Always write errors to the log |
|
107
|
|
|
$logger->write(true, $request, $e); |
|
108
|
|
|
$logger->write(true, 'Headers: ' . print_r($_SERVER, true), $e, 'request-headers'); |
|
109
|
|
|
throw $e; |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
$logger->write(false, $request, $result); |
|
113
|
|
|
|
|
114
|
|
|
echo $result; |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function removePluginAction() |
|
118
|
|
|
{ |
|
119
|
|
|
$this->Response()->setHeader('Content-Type', 'application/json; charset=utf-8'); |
|
120
|
|
|
|
|
121
|
|
|
$request = file_get_contents('php://input'); |
|
122
|
|
|
|
|
123
|
|
|
$apiRequest = $this->getRestApiRequest(); |
|
124
|
|
|
$result = $apiRequest->verifyRequest($request); |
|
125
|
|
|
|
|
126
|
|
|
if ($result->isOk()) { |
|
127
|
|
|
/** @var InstallerService $pluginManager */ |
|
128
|
|
|
$pluginManager = $this->getPluginManager(); |
|
129
|
|
|
$plugin = $pluginManager->getPluginByName('SwagConnect'); |
|
130
|
|
|
$pluginManager->uninstallPlugin($plugin); |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
echo $result->getContent(); |
|
134
|
|
|
} |
|
135
|
|
|
|
|
136
|
|
|
/** |
|
137
|
|
|
* {@inheritdoc} |
|
138
|
|
|
*/ |
|
139
|
|
|
public function getWhitelistedCSRFActions() |
|
140
|
|
|
{ |
|
141
|
|
|
return ['index', 'removePlugin']; |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.