1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* This file is part of EC-CUBE |
4
|
|
|
* |
5
|
|
|
* Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved. |
6
|
|
|
* |
7
|
|
|
* http://www.lockon.co.jp/ |
8
|
|
|
* |
9
|
|
|
* This program is free software; you can redistribute it and/or |
10
|
|
|
* modify it under the terms of the GNU General Public License |
11
|
|
|
* as published by the Free Software Foundation; either version 2 |
12
|
|
|
* of the License, or (at your option) any later version. |
13
|
|
|
* |
14
|
|
|
* This program is distributed in the hope that it will be useful, |
15
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
16
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
17
|
|
|
* GNU General Public License for more details. |
18
|
|
|
* |
19
|
|
|
* You should have received a copy of the GNU General Public License |
20
|
|
|
* along with this program; if not, write to the Free Software |
21
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
22
|
|
|
*/ |
23
|
|
|
|
24
|
|
|
|
25
|
|
|
namespace Eccube\Controller\Admin\Store; |
26
|
|
|
|
27
|
|
|
use Eccube\Application; |
28
|
|
|
use Eccube\Common\Constant; |
29
|
|
|
use Eccube\Controller\AbstractController; |
30
|
|
|
use Eccube\Exception\PluginException; |
31
|
|
|
use Eccube\Util\Cache; |
32
|
|
|
use Eccube\Util\Str; |
33
|
|
|
use Symfony\Component\Filesystem\Filesystem; |
34
|
|
|
use Symfony\Component\HttpFoundation\Request; |
35
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
36
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
37
|
|
|
|
38
|
|
|
class PluginController extends AbstractController |
|
|
|
|
39
|
|
|
{ |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* インストール済プラグイン画面 |
43
|
|
|
* |
44
|
|
|
* @param Application $app |
45
|
|
|
* @param Request $request |
|
|
|
|
46
|
|
|
*/ |
|
|
|
|
47
|
|
|
public function index(Application $app, Request $request) |
48
|
|
|
{ |
49
|
|
|
|
50
|
|
|
$pluginForms = array(); |
51
|
|
|
$configPages = array(); |
52
|
|
|
|
53
|
|
|
$Plugins = $app['eccube.repository.plugin']->findBy(array(), array('name' => 'ASC')); |
54
|
|
|
|
55
|
|
|
$officialPlugins = array(); |
56
|
|
|
$unofficialPlugins = array(); |
57
|
|
|
|
58
|
|
|
foreach ($Plugins as $Plugin) { |
59
|
|
|
|
60
|
|
|
$form = $app['form.factory'] |
61
|
|
|
->createNamedBuilder('form' . $Plugin->getId(), 'plugin_management', null, array( |
|
|
|
|
62
|
|
|
'plugin_id' => $Plugin->getId(), |
63
|
|
|
)) |
64
|
|
|
->getForm(); |
65
|
|
|
|
66
|
|
|
$pluginForms[$Plugin->getId()] = $form->createView(); |
67
|
|
|
|
68
|
|
|
try { |
69
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
70
|
|
|
$configPages[$Plugin->getCode()] = $app->url('plugin_' . $Plugin->getCode() . '_config'); |
|
|
|
|
71
|
|
|
} catch (\Exception $e) { |
72
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
if ($Plugin->getSource() == 0) { |
76
|
|
|
// 商品IDが設定されていない場合、非公式プラグイン |
77
|
|
|
$unofficialPlugins[] = $Plugin; |
78
|
|
|
} else { |
79
|
|
|
$officialPlugins[] = $Plugin; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
// オーナーズストアからダウンロード可能プラグイン情報を取得 |
85
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
86
|
|
|
|
87
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
88
|
|
|
|
89
|
|
|
if (!is_null($authKey)) { |
90
|
|
|
|
91
|
|
|
// オーナーズストア通信 |
92
|
|
|
$url = $app['config']['owners_store_url'] . '?method=list'; |
|
|
|
|
93
|
|
|
list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url); |
|
|
|
|
94
|
|
|
|
95
|
|
|
if ($json) { |
96
|
|
|
|
97
|
|
|
// 接続成功時 |
98
|
|
|
|
99
|
|
|
$data = json_decode($json, true); |
100
|
|
|
|
101
|
|
|
if (isset($data['success'])) { |
102
|
|
|
$success = $data['success']; |
103
|
|
|
if ($success == '1') { |
104
|
|
|
|
105
|
|
|
// 既にインストールされているかどうか確認 |
106
|
|
|
foreach ($data['item'] as $item) { |
107
|
|
|
foreach ($officialPlugins as $plugin) { |
108
|
|
|
if ($plugin->getSource() == $item['product_id']) { |
109
|
|
|
// 商品IDが同一の情報を設定 |
110
|
|
|
$plugin->setNewVersion($item['version']); |
111
|
|
|
$plugin->setLastUpdateDate($item['last_update_date']); |
112
|
|
|
$plugin->setProductUrl($item['product_url']); |
113
|
|
|
|
114
|
|
|
if ($plugin->getVersion() != $item['version']) { |
115
|
|
|
// バージョンが異なる |
116
|
|
|
if (in_array(Constant::VERSION, $item['eccube_version'])) { |
117
|
|
|
// 対象バージョン |
118
|
|
|
$plugin->setUpdateStatus(3); |
119
|
|
|
break; |
120
|
|
|
} |
121
|
|
|
} |
122
|
|
|
} |
123
|
|
|
} |
124
|
|
|
} |
125
|
|
|
} |
126
|
|
|
} |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
|
131
|
|
|
return $app->render('Store/plugin.twig', array( |
|
|
|
|
132
|
|
|
'plugin_forms' => $pluginForms, |
133
|
|
|
'officialPlugins' => $officialPlugins, |
134
|
|
|
'unofficialPlugins' => $unofficialPlugins, |
135
|
|
|
'configPages' => $configPages |
136
|
|
|
)); |
137
|
|
|
|
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
|
|
|
|
141
|
|
|
* インストール済プラグインからのアップデート |
142
|
|
|
* |
143
|
|
|
* @param Application $app |
144
|
|
|
* @param Request $request |
|
|
|
|
145
|
|
|
* @param $id |
|
|
|
|
146
|
|
|
*/ |
|
|
|
|
147
|
|
|
public function update(Application $app, Request $request, $id) |
148
|
|
|
{ |
149
|
|
|
|
150
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
151
|
|
|
|
152
|
|
|
$form = $app['form.factory'] |
153
|
|
|
->createNamedBuilder('form' . $id, 'plugin_management', null, array( |
|
|
|
|
154
|
|
|
'plugin_id' => null, // placeHolder |
155
|
|
|
)) |
156
|
|
|
->getForm(); |
157
|
|
|
|
158
|
|
|
$message = ''; |
159
|
|
|
|
160
|
|
|
if ('POST' === $request->getMethod()) { |
161
|
|
|
$form->handleRequest($request); |
162
|
|
|
|
163
|
|
|
if ($form->isValid()) { |
164
|
|
|
|
165
|
|
|
$tmpDir = null; |
166
|
|
|
try { |
167
|
|
|
|
168
|
|
|
$formFile = $form['plugin_archive']->getData(); |
169
|
|
|
|
170
|
|
|
$tmpDir = $app['eccube.service.plugin']->createTempDir(); |
171
|
|
|
$tmpFile = sha1(Str::random(32)) . '.' . $formFile->getClientOriginalExtension(); |
|
|
|
|
172
|
|
|
|
173
|
|
|
$formFile->move($tmpDir, $tmpFile); |
174
|
|
|
$app['eccube.service.plugin']->update($Plugin, $tmpDir . '/' . $tmpFile); |
|
|
|
|
175
|
|
|
|
176
|
|
|
$fs = new Filesystem(); |
177
|
|
|
$fs->remove($tmpDir); |
178
|
|
|
|
179
|
|
|
$app->addSuccess('admin.plugin.update.complete', 'admin'); |
180
|
|
|
|
181
|
|
|
Cache::clear($app, false); |
|
|
|
|
182
|
|
|
|
183
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
184
|
|
|
|
185
|
|
|
} catch (PluginException $e) { |
186
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
187
|
|
|
$fs = new Filesystem(); |
188
|
|
|
$fs->remove($tmpDir); |
189
|
|
|
} |
190
|
|
|
$message = $e->getMessage(); |
191
|
|
|
} |
192
|
|
|
} else { |
193
|
|
|
$errors = $form->getErrors(true); |
194
|
|
|
foreach ($errors as $error) { |
195
|
|
|
$message = $error->getMessage(); |
196
|
|
|
} |
197
|
|
|
|
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
} |
201
|
|
|
|
202
|
|
|
$app->addError($message, 'admin'); |
203
|
|
|
|
204
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
|
208
|
|
|
/** |
|
|
|
|
209
|
|
|
* 対象のプラグインを有効にします。 |
210
|
|
|
* |
211
|
|
|
* @param Application $app |
212
|
|
|
* @param $id |
|
|
|
|
213
|
|
|
*/ |
|
|
|
|
214
|
|
View Code Duplication |
public function enable(Application $app, $id) |
|
|
|
|
215
|
|
|
{ |
216
|
|
|
$this->isTokenValid($app); |
217
|
|
|
|
218
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
219
|
|
|
|
220
|
|
|
if (!$Plugin) { |
221
|
|
|
throw new NotFoundHttpException(); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
if ($Plugin->getEnable() == Constant::ENABLED) { |
225
|
|
|
$app->addError('admin.plugin.already.enable', 'admin'); |
226
|
|
|
} else { |
227
|
|
|
$app['eccube.service.plugin']->enable($Plugin); |
228
|
|
|
$app->addSuccess('admin.plugin.enable.complete', 'admin'); |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
232
|
|
|
} |
233
|
|
|
|
234
|
|
|
/** |
|
|
|
|
235
|
|
|
* 対象のプラグインを無効にします。 |
236
|
|
|
* |
237
|
|
|
* @param Application $app |
238
|
|
|
* @param $id |
|
|
|
|
239
|
|
|
*/ |
|
|
|
|
240
|
|
View Code Duplication |
public function disable(Application $app, $id) |
|
|
|
|
241
|
|
|
{ |
242
|
|
|
$this->isTokenValid($app); |
243
|
|
|
|
244
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
245
|
|
|
|
246
|
|
|
if (!$Plugin) { |
247
|
|
|
throw new NotFoundHttpException(); |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
if ($Plugin->getEnable() == Constant::ENABLED) { |
251
|
|
|
$app['eccube.service.plugin']->disable($Plugin); |
252
|
|
|
$app->addSuccess('admin.plugin.disable.complete', 'admin'); |
253
|
|
|
} else { |
254
|
|
|
$app->addError('admin.plugin.already.disable', 'admin'); |
255
|
|
|
} |
256
|
|
|
|
257
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
|
261
|
|
|
/** |
|
|
|
|
262
|
|
|
* 対象のプラグインを削除します。 |
263
|
|
|
* |
264
|
|
|
* @param Application $app |
265
|
|
|
* @param $id |
|
|
|
|
266
|
|
|
*/ |
|
|
|
|
267
|
|
|
public function uninstall(Application $app, $id) |
268
|
|
|
{ |
269
|
|
|
$this->isTokenValid($app); |
270
|
|
|
|
271
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
272
|
|
|
|
273
|
|
|
if (!$Plugin) { |
274
|
|
|
$app->deleteMessage(); |
275
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
|
|
|
|
276
|
|
|
} |
277
|
|
|
|
278
|
|
|
$app['eccube.service.plugin']->uninstall($Plugin); |
279
|
|
|
|
280
|
|
|
$app->addSuccess('admin.plugin.uninstall.complete', 'admin'); |
281
|
|
|
|
282
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function handler(Application $app) |
|
|
|
|
286
|
|
|
{ |
287
|
|
|
$handlers = $app['eccube.repository.plugin_event_handler']->getHandlers(); |
288
|
|
|
|
289
|
|
|
// 一次元配列からイベント毎の二次元配列に変換する |
290
|
|
|
$HandlersPerEvent = array(); |
291
|
|
|
foreach ($handlers as $handler) { |
292
|
|
|
$HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
return $app->render('Store/plugin_handler.twig', array( |
|
|
|
|
296
|
|
|
'handlersPerEvent' => $HandlersPerEvent |
297
|
|
|
)); |
298
|
|
|
|
299
|
|
|
} |
300
|
|
|
|
301
|
|
View Code Duplication |
public function handler_up(Application $app, $handlerId) |
|
|
|
|
302
|
|
|
{ |
303
|
|
|
$repo = $app['eccube.repository.plugin_event_handler']; |
304
|
|
|
$repo->upPriority($repo->find($handlerId)); |
305
|
|
|
|
306
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
307
|
|
|
} |
308
|
|
|
|
309
|
|
View Code Duplication |
public function handler_down(Application $app, $handlerId) |
|
|
|
|
310
|
|
|
{ |
311
|
|
|
$repo = $app['eccube.repository.plugin_event_handler']; |
312
|
|
|
$repo->upPriority($repo->find($handlerId), false); |
313
|
|
|
|
314
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
/** |
318
|
|
|
* プラグインファイルアップロード画面 |
319
|
|
|
* |
320
|
|
|
* @param Application $app |
321
|
|
|
* @param Request $request |
|
|
|
|
322
|
|
|
*/ |
|
|
|
|
323
|
|
|
public function install(Application $app, Request $request) |
324
|
|
|
{ |
325
|
|
|
$form = $app['form.factory'] |
326
|
|
|
->createBuilder('plugin_local_install') |
327
|
|
|
->getForm(); |
328
|
|
|
|
329
|
|
|
$errors = array(); |
330
|
|
|
|
331
|
|
|
if ('POST' === $request->getMethod()) { |
332
|
|
|
$form->handleRequest($request); |
333
|
|
|
|
334
|
|
|
if ($form->isValid()) { |
335
|
|
|
|
336
|
|
|
$tmpDir = null; |
337
|
|
|
try { |
338
|
|
|
$service = $app['eccube.service.plugin']; |
339
|
|
|
|
340
|
|
|
$formFile = $form['plugin_archive']->getData(); |
341
|
|
|
|
342
|
|
|
$tmpDir = $service->createTempDir(); |
343
|
|
|
$tmpFile = sha1(Str::random(32)) . '.' . $formFile->getClientOriginalExtension(); // 拡張子を付けないとpharが動かないので付ける |
|
|
|
|
344
|
|
|
|
345
|
|
|
$formFile->move($tmpDir, $tmpFile); |
346
|
|
|
|
347
|
|
|
$service->install($tmpDir . '/' . $tmpFile); |
|
|
|
|
348
|
|
|
|
349
|
|
|
$fs = new Filesystem(); |
350
|
|
|
$fs->remove($tmpDir); |
351
|
|
|
|
352
|
|
|
$app->addSuccess('admin.plugin.install.complete', 'admin'); |
353
|
|
|
|
354
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
355
|
|
|
|
356
|
|
|
} catch (PluginException $e) { |
357
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
358
|
|
|
$fs = new Filesystem(); |
359
|
|
|
$fs->remove($tmpDir); |
360
|
|
|
} |
361
|
|
|
$errors[] = $e; |
362
|
|
|
} |
363
|
|
|
} |
364
|
|
|
} |
365
|
|
|
|
366
|
|
|
return $app->render('Store/plugin_install.twig', array( |
367
|
|
|
'form' => $form->createView(), |
368
|
|
|
'errors' => $errors, |
369
|
|
|
)); |
370
|
|
|
|
371
|
|
|
} |
372
|
|
|
|
373
|
|
|
/** |
374
|
|
|
* オーナーズストアプラグインインストール画面 |
375
|
|
|
* |
376
|
|
|
* @param Application $app |
377
|
|
|
* @param Request $request |
|
|
|
|
378
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
379
|
|
|
*/ |
380
|
|
|
public function ownersInstall(Application $app, Request $request) |
381
|
|
|
{ |
382
|
|
|
// オーナーズストアからダウンロード可能プラグイン情報を取得 |
383
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
384
|
|
|
|
385
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
386
|
|
|
$authResult = true; |
387
|
|
|
$success = 0; |
388
|
|
|
$items = array(); |
389
|
|
|
$promotionItems = array(); |
390
|
|
|
$message = ''; |
391
|
|
|
if (!is_null($authKey)) { |
392
|
|
|
|
393
|
|
|
// オーナーズストア通信 |
394
|
|
|
$url = $app['config']['owners_store_url'] . '?method=list'; |
|
|
|
|
395
|
|
|
list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url); |
396
|
|
|
|
397
|
|
|
if ($json === false) { |
398
|
|
|
// 接続失敗時 |
399
|
|
|
$success = 0; |
400
|
|
|
|
401
|
|
|
$message = $this->getResponseErrorMessage($httpHeader); |
402
|
|
|
|
403
|
|
|
} else { |
404
|
|
|
// 接続成功時 |
405
|
|
|
|
406
|
|
|
$data = json_decode($json, true); |
407
|
|
|
|
408
|
|
|
if (isset($data['success'])) { |
409
|
|
|
$success = $data['success']; |
410
|
|
|
if ($success == '1') { |
411
|
|
|
$items = array(); |
412
|
|
|
|
413
|
|
|
// 既にインストールされているかどうか確認 |
414
|
|
|
$Plugins = $app['eccube.repository.plugin']->findAll(); |
415
|
|
|
$status = false; |
416
|
|
|
// update_status 1 : 未インストール、2 : インストール済、 3 : 更新あり、4 : 有料購入 |
417
|
|
|
foreach ($data['item'] as $item) { |
418
|
|
|
foreach ($Plugins as $plugin) { |
419
|
|
|
if ($plugin->getSource() == $item['product_id']) { |
420
|
|
|
if ($plugin->getVersion() == $item['version']) { |
421
|
|
|
// バージョンが同じ |
422
|
|
|
$item['update_status'] = 2; |
423
|
|
|
} else { |
424
|
|
|
// バージョンが異なる |
425
|
|
|
$item['update_status'] = 3; |
426
|
|
|
} |
427
|
|
|
$items[] = $item; |
428
|
|
|
$status = true; |
429
|
|
|
break; |
430
|
|
|
} |
431
|
|
|
} |
432
|
|
|
if (!$status) { |
433
|
|
|
// 未インストール |
434
|
|
|
$item['update_status'] = 1; |
435
|
|
|
$items[] = $item; |
436
|
|
|
} |
437
|
|
|
$status = false; |
438
|
|
|
} |
439
|
|
|
|
440
|
|
|
// EC-CUBEのバージョンチェック |
441
|
|
|
// 参照渡しをして値を追加 |
442
|
|
|
foreach ($items as &$item) { |
443
|
|
|
if (in_array(Constant::VERSION, $item['eccube_version'])) { |
444
|
|
|
// 対象バージョン |
445
|
|
|
$item['version_check'] = 1; |
446
|
|
|
} else { |
447
|
|
|
// 未対象バージョン |
448
|
|
|
$item['version_check'] = 0; |
449
|
|
|
} |
450
|
|
|
if ($item['price'] != '0' && $item['purchased'] == '0') { |
451
|
|
|
// 有料商品で未購入 |
452
|
|
|
$item['update_status'] = 4; |
453
|
|
|
} |
454
|
|
|
} |
455
|
|
|
unset($item); |
456
|
|
|
|
457
|
|
|
// promotionアイテム |
458
|
|
|
$i = 0; |
459
|
|
|
foreach ($items as $item) { |
460
|
|
|
if ($item['promotion'] == 1) { |
461
|
|
|
$promotionItems[] = $item; |
462
|
|
|
unset($items[$i]); |
463
|
|
|
} |
464
|
|
|
$i++; |
465
|
|
|
} |
466
|
|
|
|
467
|
|
|
} else { |
468
|
|
|
$message = $data['error_code'] . ' : ' . $data['error_message']; |
|
|
|
|
469
|
|
|
} |
470
|
|
|
} else { |
471
|
|
|
$success = 0; |
472
|
|
|
$message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
473
|
|
|
} |
474
|
|
|
} |
475
|
|
|
|
476
|
|
|
} else { |
477
|
|
|
$authResult = false; |
478
|
|
|
} |
479
|
|
|
|
480
|
|
|
return $app->render('Store/plugin_owners_install.twig', array( |
481
|
|
|
'authResult' => $authResult, |
482
|
|
|
'success' => $success, |
483
|
|
|
'items' => $items, |
484
|
|
|
'promotionItems' => $promotionItems, |
485
|
|
|
'message' => $message, |
486
|
|
|
)); |
487
|
|
|
|
488
|
|
|
} |
489
|
|
|
|
490
|
|
|
/** |
|
|
|
|
491
|
|
|
* オーナーズブラグインインストール、アップデート |
492
|
|
|
* |
493
|
|
|
* @param Application $app |
494
|
|
|
* @param Request $request |
|
|
|
|
495
|
|
|
* @param $action |
|
|
|
|
496
|
|
|
* @param $id |
|
|
|
|
497
|
|
|
* @param $version |
|
|
|
|
498
|
|
|
*/ |
|
|
|
|
499
|
|
|
public function upgrade(Application $app, Request $request, $action, $id, $version) |
500
|
|
|
{ |
501
|
|
|
|
502
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
503
|
|
|
|
504
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
505
|
|
|
$message = ''; |
506
|
|
|
|
507
|
|
|
if (!is_null($authKey)) { |
508
|
|
|
|
509
|
|
|
// オーナーズストア通信 |
510
|
|
|
$url = $app['config']['owners_store_url'] . '?method=download&product_id=' . $id; |
|
|
|
|
511
|
|
|
list($json, $httpHeader) = $this->getRequestApi($request, $authKey, $url); |
512
|
|
|
|
513
|
|
|
if ($json === false) { |
514
|
|
|
// 接続失敗時 |
515
|
|
|
|
516
|
|
|
$message = $this->getResponseErrorMessage($httpHeader); |
517
|
|
|
|
518
|
|
|
} else { |
519
|
|
|
// 接続成功時 |
520
|
|
|
|
521
|
|
|
$data = json_decode($json, true); |
522
|
|
|
|
523
|
|
|
if (isset($data['success'])) { |
524
|
|
|
$success = $data['success']; |
525
|
|
|
if ($success == '1') { |
526
|
|
|
$tmpDir = null; |
527
|
|
|
try { |
528
|
|
|
$service = $app['eccube.service.plugin']; |
529
|
|
|
|
530
|
|
|
$item = $data['item']; |
531
|
|
|
$file = base64_decode($item['data']); |
532
|
|
|
$extension = pathinfo($item['file_name'], PATHINFO_EXTENSION); |
533
|
|
|
|
534
|
|
|
$tmpDir = $service->createTempDir(); |
535
|
|
|
$tmpFile = sha1(Str::random(32)) . '.' . $extension; |
|
|
|
|
536
|
|
|
|
537
|
|
|
// ファイル作成 |
538
|
|
|
$fs = new Filesystem(); |
539
|
|
|
$fs->dumpFile($tmpDir . '/' . $tmpFile, $file); |
|
|
|
|
540
|
|
|
|
541
|
|
|
if ($action == 'install') { |
542
|
|
|
|
543
|
|
|
$service->install($tmpDir . '/' . $tmpFile, $id); |
|
|
|
|
544
|
|
|
$app->addSuccess('admin.plugin.install.complete', 'admin'); |
545
|
|
|
|
546
|
|
|
} else if ($action == 'update') { |
547
|
|
|
|
548
|
|
|
$Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id)); |
549
|
|
|
|
550
|
|
|
$service->update($Plugin, $tmpDir . '/' . $tmpFile); |
|
|
|
|
551
|
|
|
$app->addSuccess('admin.plugin.update.complete', 'admin'); |
552
|
|
|
|
553
|
|
|
Cache::clear($app, false); |
|
|
|
|
554
|
|
|
|
555
|
|
|
} |
556
|
|
|
|
557
|
|
|
$fs = new Filesystem(); |
558
|
|
|
$fs->remove($tmpDir); |
559
|
|
|
|
560
|
|
|
// ダウンロード完了通知処理(正常終了時) |
561
|
|
|
$url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=1&version=' . $version; |
|
|
|
|
562
|
|
|
$this->getRequestApi($request, $authKey, $url); |
563
|
|
|
|
564
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
565
|
|
|
|
566
|
|
|
} catch (PluginException $e) { |
567
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
568
|
|
|
$fs = new Filesystem(); |
569
|
|
|
$fs->remove($tmpDir); |
570
|
|
|
} |
571
|
|
|
$message = $e->getMessage(); |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
} else { |
575
|
|
|
$message = $data['error_code'] . ' : ' . $data['error_message']; |
|
|
|
|
576
|
|
|
} |
577
|
|
|
} else { |
578
|
|
|
$message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
579
|
|
|
} |
580
|
|
|
} |
581
|
|
|
} |
582
|
|
|
|
583
|
|
|
// ダウンロード完了通知処理(エラー発生時) |
584
|
|
|
$url = $app['config']['owners_store_url'] . '?method=commit&product_id=' . $id . '&status=0&version=' . $version . '&message=' . urlencode($message); |
|
|
|
|
585
|
|
|
$this->getRequestApi($request, $authKey, $url); |
586
|
|
|
|
587
|
|
|
$app->addError($message, 'admin'); |
588
|
|
|
|
589
|
|
|
return $app->redirect($app->url('admin_store_plugin_owners_install')); |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* 認証キー設定画面 |
594
|
|
|
* |
595
|
|
|
* @param Application $app |
596
|
|
|
* @param Request $request |
|
|
|
|
597
|
|
|
*/ |
|
|
|
|
598
|
|
|
public function authenticationSetting(Application $app, Request $request) |
599
|
|
|
{ |
600
|
|
|
|
601
|
|
|
$form = $app->form()->getForm(); |
602
|
|
|
|
603
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
604
|
|
|
|
605
|
|
|
// 認証キーの取得 |
606
|
|
|
$form->add( |
607
|
|
|
'authentication_key', 'text', array( |
608
|
|
|
'label' => '認証キー', |
609
|
|
|
'constraints' => array( |
610
|
|
|
new Assert\Regex(array( |
611
|
|
|
'pattern' => "/^[0-9a-zA-Z]+$/", |
612
|
|
|
)), |
613
|
|
|
), |
614
|
|
|
'data' => $BaseInfo->getAuthenticationKey(), |
615
|
|
|
)); |
|
|
|
|
616
|
|
|
|
617
|
|
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
618
|
|
|
$form->handleRequest($request); |
|
|
|
|
619
|
|
|
|
620
|
|
|
if ($form->isValid()) { |
|
|
|
|
621
|
|
|
$data = $form->getData(); |
|
|
|
|
622
|
|
|
|
623
|
|
|
// 認証キーの登録 |
624
|
|
|
$BaseInfo->setAuthenticationKey($data['authentication_key']); |
|
|
|
|
625
|
|
|
$app['orm.em']->flush($BaseInfo); |
|
|
|
|
626
|
|
|
|
627
|
|
|
$app->addSuccess('admin.plugin.authentication.setting.complete', 'admin'); |
|
|
|
|
628
|
|
|
|
629
|
|
|
} |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
|
633
|
|
|
return $app->render('Store/authentication_setting.twig', array( |
634
|
|
|
'form' => $form->createView(), |
635
|
|
|
)); |
636
|
|
|
|
637
|
|
|
} |
638
|
|
|
|
639
|
|
|
|
640
|
|
|
/** |
641
|
|
|
* APIリクエスト処理 |
642
|
|
|
* |
643
|
|
|
* @param Request $request |
644
|
|
|
* @param $authKey |
645
|
|
|
* @param $url |
646
|
|
|
* @return array |
647
|
|
|
*/ |
648
|
|
|
private function getRequestApi(Request $request, $authKey, $url) |
649
|
|
|
{ |
650
|
|
|
$opts = array( |
|
|
|
|
651
|
|
|
'http' => array( |
|
|
|
|
652
|
|
|
'method' => 'GET', |
653
|
|
|
'ignore_errors' => false, |
654
|
|
|
'timeout' => 60, |
655
|
|
|
'header' => array( |
|
|
|
|
656
|
|
|
'Authorization: ' . base64_encode($authKey), |
|
|
|
|
657
|
|
|
'x-eccube-store-url: ' . base64_encode($request->getSchemeAndHttpHost() . $request->getBasePath()), |
|
|
|
|
658
|
|
|
'x-eccube-store-version: ' . base64_encode(Constant::VERSION) |
|
|
|
|
659
|
|
|
) |
660
|
|
|
) |
661
|
|
|
); |
662
|
|
|
|
663
|
|
|
$context = stream_context_create($opts); |
664
|
|
|
|
665
|
|
|
$json = @file_get_contents($url, false, $context); |
666
|
|
|
|
667
|
|
|
return array($json, $http_response_header); |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* レスポンスヘッダーのチェック |
672
|
|
|
* |
673
|
|
|
* @param $httpHeader |
674
|
|
|
* @return string |
675
|
|
|
*/ |
676
|
|
|
private function getResponseErrorMessage($httpHeader) |
677
|
|
|
{ |
678
|
|
|
if (!empty($httpHeader)) { |
679
|
|
|
list($version, $statusCode, $message) = explode(' ', $httpHeader[0], 3); |
|
|
|
|
680
|
|
|
|
681
|
|
|
switch ($statusCode) { |
682
|
|
|
case '404': |
683
|
|
|
$message = $statusCode . ' : ' . $message; |
|
|
|
|
684
|
|
|
break; |
685
|
|
|
case '500': |
686
|
|
|
$message = $statusCode . ' : ' . $message; |
|
|
|
|
687
|
|
|
break; |
688
|
|
|
default: |
689
|
|
|
$message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
690
|
|
|
break; |
691
|
|
|
} |
692
|
|
|
} else { |
693
|
|
|
$message = "タイムアウトエラーまたはURLの指定に誤りがあります。"; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
return $message; |
697
|
|
|
} |
698
|
|
|
|
699
|
|
|
} |
700
|
|
|
|