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\Finder\Finder; |
35
|
|
|
use Symfony\Component\HttpFoundation\Request; |
36
|
|
|
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; |
37
|
|
|
use Symfony\Component\Routing\Exception\RouteNotFoundException; |
38
|
|
|
use Symfony\Component\Validator\Constraints as Assert; |
39
|
|
|
|
40
|
|
|
class PluginController extends AbstractController |
|
|
|
|
41
|
|
|
{ |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string 証明書ファイル |
45
|
|
|
*/ |
46
|
|
|
private $certFileName = 'cacert.pem'; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* インストール済プラグイン画面 |
50
|
|
|
* |
51
|
|
|
* @param Application $app |
52
|
|
|
* @param Request $request |
|
|
|
|
53
|
|
|
*/ |
|
|
|
|
54
|
|
|
public function index(Application $app, Request $request) |
55
|
|
|
{ |
56
|
|
|
|
57
|
|
|
$pluginForms = array(); |
58
|
|
|
$configPages = array(); |
59
|
|
|
|
60
|
|
|
$Plugins = $app['eccube.repository.plugin']->findBy(array(), array('name' => 'ASC')); |
61
|
|
|
|
62
|
|
|
// ファイル設置プラグインの取得. |
63
|
|
|
$unregisterdPlugins = $this->getUnregisteredPlugins($Plugins, $app); |
64
|
|
|
$unregisterdPluginsConfigPages = array(); |
65
|
|
|
foreach ($unregisterdPlugins as $unregisterdPlugin) { |
66
|
|
|
try { |
67
|
|
|
$code = $unregisterdPlugin['code']; |
68
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
69
|
|
|
$unregisterdPluginsConfigPages[$code] = $app->url('plugin_'.$code.'_config'); |
70
|
|
|
} catch (RouteNotFoundException $e) { |
71
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
72
|
|
|
} |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
$officialPlugins = array(); |
76
|
|
|
$unofficialPlugins = array(); |
77
|
|
|
|
78
|
|
|
foreach ($Plugins as $Plugin) { |
|
|
|
|
79
|
|
|
|
80
|
|
|
$form = $app['form.factory'] |
81
|
|
|
->createNamedBuilder('form'.$Plugin->getId(), 'plugin_management', null, array( |
82
|
|
|
'plugin_id' => $Plugin->getId(), |
83
|
|
|
)) |
84
|
|
|
->getForm(); |
85
|
|
|
|
86
|
|
|
$pluginForms[$Plugin->getId()] = $form->createView(); |
87
|
|
|
|
88
|
|
|
try { |
89
|
|
|
// プラグイン用設定画面があれば表示(プラグイン用のサービスプロバイダーに定義されているか) |
90
|
|
|
$configPages[$Plugin->getCode()] = $app->url('plugin_'.$Plugin->getCode().'_config'); |
91
|
|
|
} catch (\Exception $e) { |
92
|
|
|
// プラグインで設定画面のルートが定義されていない場合は無視 |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
if ($Plugin->getSource() == 0) { |
96
|
|
|
// 商品IDが設定されていない場合、非公式プラグイン |
97
|
|
|
$unofficialPlugins[] = $Plugin; |
98
|
|
|
} else { |
99
|
|
|
$officialPlugins[] = $Plugin; |
100
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
} |
103
|
|
|
|
104
|
|
|
// オーナーズストアからダウンロード可能プラグイン情報を取得 |
105
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
106
|
|
|
|
107
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
108
|
|
|
|
109
|
|
|
if (!is_null($authKey)) { |
|
|
|
|
110
|
|
|
|
111
|
|
|
// オーナーズストア通信 |
112
|
|
|
$url = $app['config']['owners_store_url'].'?method=list'; |
113
|
|
|
list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app); |
|
|
|
|
114
|
|
|
|
115
|
|
|
if ($json) { |
|
|
|
|
116
|
|
|
|
117
|
|
|
// 接続成功時 |
118
|
|
|
|
119
|
|
|
$data = json_decode($json, true); |
120
|
|
|
|
121
|
|
|
if (isset($data['success'])) { |
122
|
|
|
$success = $data['success']; |
123
|
|
|
if ($success == '1') { |
|
|
|
|
124
|
|
|
|
125
|
|
|
// 既にインストールされているかどうか確認 |
126
|
|
|
foreach ($data['item'] as $item) { |
127
|
|
|
foreach ($officialPlugins as $plugin) { |
128
|
|
|
if ($plugin->getSource() == $item['product_id']) { |
129
|
|
|
// 商品IDが同一の情報を設定 |
130
|
|
|
$plugin->setNewVersion($item['version']); |
131
|
|
|
$plugin->setLastUpdateDate($item['last_update_date']); |
132
|
|
|
$plugin->setProductUrl($item['product_url']); |
133
|
|
|
|
134
|
|
|
if ($plugin->getVersion() != $item['version']) { |
135
|
|
|
// バージョンが異なる |
136
|
|
|
if (in_array(Constant::VERSION, $item['eccube_version'])) { |
137
|
|
|
// 対象バージョン |
138
|
|
|
$plugin->setUpdateStatus(3); |
139
|
|
|
break; |
140
|
|
|
} |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
} |
146
|
|
|
} |
147
|
|
|
} |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
|
151
|
|
|
return $app->render('Store/plugin.twig', array( |
152
|
|
|
'plugin_forms' => $pluginForms, |
153
|
|
|
'officialPlugins' => $officialPlugins, |
154
|
|
|
'unofficialPlugins' => $unofficialPlugins, |
155
|
|
|
'configPages' => $configPages, |
156
|
|
|
'unregisterdPlugins' => $unregisterdPlugins, |
157
|
|
|
'unregisterdPluginsConfigPages' => $unregisterdPluginsConfigPages, |
158
|
|
|
)); |
159
|
|
|
|
160
|
|
|
} |
161
|
|
|
|
162
|
|
|
/** |
|
|
|
|
163
|
|
|
* インストール済プラグインからのアップデート |
164
|
|
|
* |
165
|
|
|
* @param Application $app |
166
|
|
|
* @param Request $request |
|
|
|
|
167
|
|
|
* @param $id |
|
|
|
|
168
|
|
|
*/ |
|
|
|
|
169
|
|
|
public function update(Application $app, Request $request, $id) |
170
|
|
|
{ |
171
|
|
|
|
172
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
173
|
|
|
|
174
|
|
|
$form = $app['form.factory'] |
175
|
|
|
->createNamedBuilder('form'.$id, 'plugin_management', null, array( |
176
|
|
|
'plugin_id' => null, // placeHolder |
177
|
|
|
)) |
178
|
|
|
->getForm(); |
179
|
|
|
|
180
|
|
|
$message = ''; |
181
|
|
|
|
182
|
|
|
if ('POST' === $request->getMethod()) { |
183
|
|
|
$form->handleRequest($request); |
184
|
|
|
|
185
|
|
|
if ($form->isValid()) { |
|
|
|
|
186
|
|
|
|
187
|
|
|
$tmpDir = null; |
188
|
|
|
try { |
|
|
|
|
189
|
|
|
|
190
|
|
|
$formFile = $form['plugin_archive']->getData(); |
191
|
|
|
|
192
|
|
|
$tmpDir = $app['eccube.service.plugin']->createTempDir(); |
193
|
|
|
$tmpFile = sha1(Str::random(32)).'.'.$formFile->getClientOriginalExtension(); |
194
|
|
|
|
195
|
|
|
$formFile->move($tmpDir, $tmpFile); |
196
|
|
|
$app['eccube.service.plugin']->update($Plugin, $tmpDir.'/'.$tmpFile); |
197
|
|
|
|
198
|
|
|
$fs = new Filesystem(); |
199
|
|
|
$fs->remove($tmpDir); |
200
|
|
|
|
201
|
|
|
$app->addSuccess('admin.plugin.update.complete', 'admin'); |
202
|
|
|
|
203
|
|
|
Cache::clear($app, false); |
|
|
|
|
204
|
|
|
|
205
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
206
|
|
|
|
|
|
|
|
207
|
|
|
} catch (PluginException $e) { |
208
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
209
|
|
|
$fs = new Filesystem(); |
210
|
|
|
$fs->remove($tmpDir); |
211
|
|
|
} |
212
|
|
|
$message = $e->getMessage(); |
213
|
|
|
} |
214
|
|
|
} else { |
215
|
|
|
$errors = $form->getErrors(true); |
216
|
|
|
foreach ($errors as $error) { |
217
|
|
|
$message = $error->getMessage(); |
218
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
} |
221
|
|
|
|
|
|
|
|
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
$app->addError($message, 'admin'); |
225
|
|
|
|
226
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
|
230
|
|
|
/** |
|
|
|
|
231
|
|
|
* 対象のプラグインを有効にします。 |
232
|
|
|
* |
233
|
|
|
* @param Application $app |
234
|
|
|
* @param $id |
|
|
|
|
235
|
|
|
*/ |
|
|
|
|
236
|
|
View Code Duplication |
public function enable(Application $app, $id) |
|
|
|
|
237
|
|
|
{ |
238
|
|
|
$this->isTokenValid($app); |
239
|
|
|
|
240
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
241
|
|
|
|
242
|
|
|
if (!$Plugin) { |
243
|
|
|
throw new NotFoundHttpException(); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
if ($Plugin->getEnable() == Constant::ENABLED) { |
247
|
|
|
$app->addError('admin.plugin.already.enable', 'admin'); |
248
|
|
|
} else { |
249
|
|
|
$app['eccube.service.plugin']->enable($Plugin); |
250
|
|
|
$app->addSuccess('admin.plugin.enable.complete', 'admin'); |
251
|
|
|
} |
252
|
|
|
|
253
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
254
|
|
|
} |
255
|
|
|
|
256
|
|
|
/** |
|
|
|
|
257
|
|
|
* 対象のプラグインを無効にします。 |
258
|
|
|
* |
259
|
|
|
* @param Application $app |
260
|
|
|
* @param $id |
|
|
|
|
261
|
|
|
*/ |
|
|
|
|
262
|
|
View Code Duplication |
public function disable(Application $app, $id) |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$this->isTokenValid($app); |
265
|
|
|
|
266
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
267
|
|
|
|
268
|
|
|
if (!$Plugin) { |
269
|
|
|
throw new NotFoundHttpException(); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
if ($Plugin->getEnable() == Constant::ENABLED) { |
273
|
|
|
$app['eccube.service.plugin']->disable($Plugin); |
274
|
|
|
$app->addSuccess('admin.plugin.disable.complete', 'admin'); |
275
|
|
|
} else { |
276
|
|
|
$app->addError('admin.plugin.already.disable', 'admin'); |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
|
283
|
|
|
/** |
|
|
|
|
284
|
|
|
* 対象のプラグインを削除します。 |
285
|
|
|
* |
286
|
|
|
* @param Application $app |
287
|
|
|
* @param $id |
|
|
|
|
288
|
|
|
*/ |
|
|
|
|
289
|
|
|
public function uninstall(Application $app, $id) |
290
|
|
|
{ |
291
|
|
|
$this->isTokenValid($app); |
292
|
|
|
|
293
|
|
|
$Plugin = $app['eccube.repository.plugin']->find($id); |
294
|
|
|
|
295
|
|
|
if (!$Plugin) { |
296
|
|
|
$app->deleteMessage(); |
297
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
|
|
|
|
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
$app['eccube.service.plugin']->uninstall($Plugin); |
301
|
|
|
|
302
|
|
|
$app->addSuccess('admin.plugin.uninstall.complete', 'admin'); |
303
|
|
|
|
304
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
305
|
|
|
} |
306
|
|
|
|
307
|
|
|
public function handler(Application $app) |
|
|
|
|
308
|
|
|
{ |
309
|
|
|
$handlers = $app['eccube.repository.plugin_event_handler']->getHandlers(); |
310
|
|
|
|
311
|
|
|
// 一次元配列からイベント毎の二次元配列に変換する |
312
|
|
|
$HandlersPerEvent = array(); |
313
|
|
|
foreach ($handlers as $handler) { |
314
|
|
|
$HandlersPerEvent[$handler->getEvent()][$handler->getHandlerType()][] = $handler; |
315
|
|
|
} |
316
|
|
|
|
317
|
|
|
return $app->render('Store/plugin_handler.twig', array( |
|
|
|
|
318
|
|
|
'handlersPerEvent' => $HandlersPerEvent |
319
|
|
|
)); |
320
|
|
|
|
321
|
|
|
} |
322
|
|
|
|
323
|
|
View Code Duplication |
public function handler_up(Application $app, $handlerId) |
|
|
|
|
324
|
|
|
{ |
325
|
|
|
$repo = $app['eccube.repository.plugin_event_handler']; |
326
|
|
|
$repo->upPriority($repo->find($handlerId)); |
327
|
|
|
|
328
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
329
|
|
|
} |
330
|
|
|
|
331
|
|
View Code Duplication |
public function handler_down(Application $app, $handlerId) |
|
|
|
|
332
|
|
|
{ |
333
|
|
|
$repo = $app['eccube.repository.plugin_event_handler']; |
334
|
|
|
$repo->upPriority($repo->find($handlerId), false); |
335
|
|
|
|
336
|
|
|
return $app->redirect($app->url('admin_store_plugin_handler')); |
337
|
|
|
} |
338
|
|
|
|
339
|
|
|
/** |
340
|
|
|
* プラグインファイルアップロード画面 |
341
|
|
|
* |
342
|
|
|
* @param Application $app |
343
|
|
|
* @param Request $request |
|
|
|
|
344
|
|
|
*/ |
|
|
|
|
345
|
|
|
public function install(Application $app, Request $request) |
346
|
|
|
{ |
347
|
|
|
$form = $app['form.factory'] |
348
|
|
|
->createBuilder('plugin_local_install') |
349
|
|
|
->getForm(); |
350
|
|
|
|
351
|
|
|
$errors = array(); |
352
|
|
|
|
353
|
|
|
if ('POST' === $request->getMethod()) { |
354
|
|
|
$form->handleRequest($request); |
355
|
|
|
|
356
|
|
|
if ($form->isValid()) { |
|
|
|
|
357
|
|
|
|
358
|
|
|
$tmpDir = null; |
359
|
|
|
try { |
360
|
|
|
$service = $app['eccube.service.plugin']; |
361
|
|
|
|
362
|
|
|
$formFile = $form['plugin_archive']->getData(); |
363
|
|
|
|
364
|
|
|
$tmpDir = $service->createTempDir(); |
365
|
|
|
$tmpFile = sha1(Str::random(32)).'.'.$formFile->getClientOriginalExtension(); // 拡張子を付けないとpharが動かないので付ける |
366
|
|
|
|
367
|
|
|
$formFile->move($tmpDir, $tmpFile); |
368
|
|
|
|
369
|
|
|
$service->install($tmpDir.'/'.$tmpFile); |
370
|
|
|
|
371
|
|
|
$fs = new Filesystem(); |
372
|
|
|
$fs->remove($tmpDir); |
373
|
|
|
|
374
|
|
|
$app->addSuccess('admin.plugin.install.complete', 'admin'); |
375
|
|
|
|
376
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
377
|
|
|
|
|
|
|
|
378
|
|
|
} catch (PluginException $e) { |
379
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
380
|
|
|
$fs = new Filesystem(); |
381
|
|
|
$fs->remove($tmpDir); |
382
|
|
|
} |
383
|
|
|
$app['monolog']->error("plugin install failed.", array( |
|
|
|
|
384
|
|
|
'original-message' => $e->getMessage() |
385
|
|
|
)); |
386
|
|
|
$errors[] = $e; |
387
|
|
|
} |
388
|
|
|
} |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
return $app->render('Store/plugin_install.twig', array( |
392
|
|
|
'form' => $form->createView(), |
393
|
|
|
'errors' => $errors, |
394
|
|
|
)); |
395
|
|
|
|
396
|
|
|
} |
397
|
|
|
|
398
|
|
|
/** |
399
|
|
|
* オーナーズストアプラグインインストール画面 |
400
|
|
|
* |
401
|
|
|
* @param Application $app |
402
|
|
|
* @param Request $request |
|
|
|
|
403
|
|
|
* @return \Symfony\Component\HttpFoundation\Response |
404
|
|
|
*/ |
405
|
|
|
public function ownersInstall(Application $app, Request $request) |
406
|
|
|
{ |
407
|
|
|
// オーナーズストアからダウンロード可能プラグイン情報を取得 |
408
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
409
|
|
|
|
410
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
411
|
|
|
$authResult = true; |
412
|
|
|
$success = 0; |
413
|
|
|
$items = array(); |
414
|
|
|
$promotionItems = array(); |
415
|
|
|
$message = ''; |
416
|
|
|
if (!is_null($authKey)) { |
|
|
|
|
417
|
|
|
|
418
|
|
|
// オーナーズストア通信 |
419
|
|
|
$url = $app['config']['owners_store_url'].'?method=list'; |
420
|
|
|
list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app); |
421
|
|
|
|
422
|
|
|
if ($json === false) { |
423
|
|
|
// 接続失敗時 |
424
|
|
|
$success = 0; |
425
|
|
|
|
426
|
|
|
$message = $this->getResponseErrorMessage($info); |
427
|
|
|
|
|
|
|
|
428
|
|
|
} else { |
429
|
|
|
// 接続成功時 |
430
|
|
|
|
431
|
|
|
$data = json_decode($json, true); |
432
|
|
|
|
433
|
|
|
if (isset($data['success'])) { |
434
|
|
|
$success = $data['success']; |
435
|
|
|
if ($success == '1') { |
436
|
|
|
$items = array(); |
437
|
|
|
|
438
|
|
|
// 既にインストールされているかどうか確認 |
439
|
|
|
$Plugins = $app['eccube.repository.plugin']->findAll(); |
440
|
|
|
$status = false; |
441
|
|
|
// update_status 1 : 未インストール、2 : インストール済、 3 : 更新あり、4 : 有料購入 |
442
|
|
|
foreach ($data['item'] as $item) { |
443
|
|
|
foreach ($Plugins as $plugin) { |
444
|
|
|
if ($plugin->getSource() == $item['product_id']) { |
445
|
|
|
if ($plugin->getVersion() == $item['version']) { |
446
|
|
|
// バージョンが同じ |
447
|
|
|
$item['update_status'] = 2; |
448
|
|
|
} else { |
449
|
|
|
// バージョンが異なる |
450
|
|
|
$item['update_status'] = 3; |
451
|
|
|
} |
452
|
|
|
$items[] = $item; |
453
|
|
|
$status = true; |
454
|
|
|
break; |
455
|
|
|
} |
456
|
|
|
} |
457
|
|
|
if (!$status) { |
458
|
|
|
// 未インストール |
459
|
|
|
$item['update_status'] = 1; |
460
|
|
|
$items[] = $item; |
461
|
|
|
} |
462
|
|
|
$status = false; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
// EC-CUBEのバージョンチェック |
466
|
|
|
// 参照渡しをして値を追加 |
467
|
|
|
foreach ($items as &$item) { |
468
|
|
|
if (in_array(Constant::VERSION, $item['eccube_version'])) { |
469
|
|
|
// 対象バージョン |
470
|
|
|
$item['version_check'] = 1; |
471
|
|
|
} else { |
472
|
|
|
// 未対象バージョン |
473
|
|
|
$item['version_check'] = 0; |
474
|
|
|
} |
475
|
|
|
if ($item['price'] != '0' && $item['purchased'] == '0') { |
476
|
|
|
// 有料商品で未購入 |
477
|
|
|
$item['update_status'] = 4; |
478
|
|
|
} |
479
|
|
|
} |
480
|
|
|
unset($item); |
481
|
|
|
|
482
|
|
|
// promotionアイテム |
483
|
|
|
$i = 0; |
484
|
|
|
foreach ($items as $item) { |
485
|
|
|
if ($item['promotion'] == 1) { |
486
|
|
|
$promotionItems[] = $item; |
487
|
|
|
unset($items[$i]); |
488
|
|
|
} |
489
|
|
|
$i++; |
490
|
|
|
} |
491
|
|
|
|
|
|
|
|
492
|
|
|
} else { |
493
|
|
|
$message = $data['error_code'].' : '.$data['error_message']; |
494
|
|
|
} |
495
|
|
|
} else { |
496
|
|
|
$success = 0; |
497
|
|
|
$message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
498
|
|
|
} |
499
|
|
|
} |
500
|
|
|
|
|
|
|
|
501
|
|
|
} else { |
502
|
|
|
$authResult = false; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
return $app->render('Store/plugin_owners_install.twig', array( |
506
|
|
|
'authResult' => $authResult, |
507
|
|
|
'success' => $success, |
508
|
|
|
'items' => $items, |
509
|
|
|
'promotionItems' => $promotionItems, |
510
|
|
|
'message' => $message, |
511
|
|
|
)); |
512
|
|
|
|
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
|
|
|
|
516
|
|
|
* オーナーズブラグインインストール、アップデート |
517
|
|
|
* |
518
|
|
|
* @param Application $app |
519
|
|
|
* @param Request $request |
|
|
|
|
520
|
|
|
* @param $action |
|
|
|
|
521
|
|
|
* @param $id |
|
|
|
|
522
|
|
|
* @param $version |
|
|
|
|
523
|
|
|
*/ |
|
|
|
|
524
|
|
|
public function upgrade(Application $app, Request $request, $action, $id, $version) |
525
|
|
|
{ |
526
|
|
|
|
527
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
528
|
|
|
|
529
|
|
|
$authKey = $BaseInfo->getAuthenticationKey(); |
530
|
|
|
$message = ''; |
531
|
|
|
|
532
|
|
|
if (!is_null($authKey)) { |
|
|
|
|
533
|
|
|
|
534
|
|
|
// オーナーズストア通信 |
535
|
|
|
$url = $app['config']['owners_store_url'].'?method=download&product_id='.$id; |
536
|
|
|
list($json, $info) = $this->getRequestApi($request, $authKey, $url, $app); |
537
|
|
|
|
538
|
|
|
if ($json === false) { |
539
|
|
|
// 接続失敗時 |
540
|
|
|
|
541
|
|
|
$message = $this->getResponseErrorMessage($info); |
542
|
|
|
|
|
|
|
|
543
|
|
|
} else { |
544
|
|
|
// 接続成功時 |
545
|
|
|
|
546
|
|
|
$data = json_decode($json, true); |
547
|
|
|
|
548
|
|
|
if (isset($data['success'])) { |
549
|
|
|
$success = $data['success']; |
550
|
|
|
if ($success == '1') { |
551
|
|
|
$tmpDir = null; |
552
|
|
|
try { |
553
|
|
|
$service = $app['eccube.service.plugin']; |
554
|
|
|
|
555
|
|
|
$item = $data['item']; |
556
|
|
|
$file = base64_decode($item['data']); |
557
|
|
|
$extension = pathinfo($item['file_name'], PATHINFO_EXTENSION); |
558
|
|
|
|
559
|
|
|
$tmpDir = $service->createTempDir(); |
560
|
|
|
$tmpFile = sha1(Str::random(32)).'.'.$extension; |
561
|
|
|
|
562
|
|
|
// ファイル作成 |
563
|
|
|
$fs = new Filesystem(); |
564
|
|
|
$fs->dumpFile($tmpDir.'/'.$tmpFile, $file); |
565
|
|
|
|
566
|
|
|
if ($action == 'install') { |
|
|
|
|
567
|
|
|
|
568
|
|
|
$service->install($tmpDir.'/'.$tmpFile, $id); |
569
|
|
|
$app->addSuccess('admin.plugin.install.complete', 'admin'); |
570
|
|
|
|
|
|
|
|
571
|
|
|
} else if ($action == 'update') { |
|
|
|
|
572
|
|
|
|
573
|
|
|
$Plugin = $app['eccube.repository.plugin']->findOneBy(array('source' => $id)); |
574
|
|
|
|
575
|
|
|
$service->update($Plugin, $tmpDir.'/'.$tmpFile); |
576
|
|
|
$app->addSuccess('admin.plugin.update.complete', 'admin'); |
577
|
|
|
|
578
|
|
|
Cache::clear($app, false); |
|
|
|
|
579
|
|
|
|
|
|
|
|
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
$fs = new Filesystem(); |
583
|
|
|
$fs->remove($tmpDir); |
584
|
|
|
|
585
|
|
|
// ダウンロード完了通知処理(正常終了時) |
586
|
|
|
$url = $app['config']['owners_store_url'].'?method=commit&product_id='.$id.'&status=1&version='.$version; |
587
|
|
|
$this->getRequestApi($request, $authKey, $url, $app); |
588
|
|
|
|
589
|
|
|
return $app->redirect($app->url('admin_store_plugin')); |
590
|
|
|
|
|
|
|
|
591
|
|
|
} catch (PluginException $e) { |
592
|
|
|
if (!empty($tmpDir) && file_exists($tmpDir)) { |
593
|
|
|
$fs = new Filesystem(); |
594
|
|
|
$fs->remove($tmpDir); |
595
|
|
|
} |
596
|
|
|
$message = $e->getMessage(); |
597
|
|
|
} |
598
|
|
|
|
|
|
|
|
599
|
|
|
} else { |
600
|
|
|
$message = $data['error_code'].' : '.$data['error_message']; |
601
|
|
|
} |
602
|
|
|
} else { |
603
|
|
|
$message = "EC-CUBEオーナーズストアにエラーが発生しています。"; |
604
|
|
|
} |
605
|
|
|
} |
606
|
|
|
} |
607
|
|
|
|
608
|
|
|
// ダウンロード完了通知処理(エラー発生時) |
609
|
|
|
$url = $app['config']['owners_store_url'].'?method=commit&product_id='.$id.'&status=0&version='.$version.'&message='.urlencode($message); |
610
|
|
|
$this->getRequestApi($request, $authKey, $url, $app); |
611
|
|
|
|
612
|
|
|
$app->addError($message, 'admin'); |
613
|
|
|
|
614
|
|
|
return $app->redirect($app->url('admin_store_plugin_owners_install')); |
615
|
|
|
} |
616
|
|
|
|
617
|
|
|
/** |
618
|
|
|
* 認証キー設定画面 |
619
|
|
|
* |
620
|
|
|
* @param Application $app |
621
|
|
|
* @param Request $request |
|
|
|
|
622
|
|
|
*/ |
|
|
|
|
623
|
|
|
public function authenticationSetting(Application $app, Request $request) |
624
|
|
|
{ |
625
|
|
|
|
626
|
|
|
$form = $app->form()->getForm(); |
627
|
|
|
|
628
|
|
|
$BaseInfo = $app['eccube.repository.base_info']->get(); |
629
|
|
|
|
630
|
|
|
// 認証キーの取得 |
631
|
|
|
$form->add( |
632
|
|
|
'authentication_key', 'text', array( |
633
|
|
|
'label' => '認証キー', |
634
|
|
|
'constraints' => array( |
635
|
|
|
new Assert\Regex(array( |
636
|
|
|
'pattern' => "/^[0-9a-zA-Z]+$/", |
637
|
|
|
)), |
638
|
|
|
), |
639
|
|
|
'data' => $BaseInfo->getAuthenticationKey(), |
640
|
|
|
)); |
|
|
|
|
641
|
|
|
|
642
|
|
|
if ('POST' === $request->getMethod()) { |
|
|
|
|
643
|
|
|
$form->handleRequest($request); |
|
|
|
|
644
|
|
|
|
645
|
|
|
if ($form->isValid()) { |
|
|
|
|
646
|
|
|
$data = $form->getData(); |
|
|
|
|
647
|
|
|
|
648
|
|
|
// 認証キーの登録 |
649
|
|
|
$BaseInfo->setAuthenticationKey($data['authentication_key']); |
|
|
|
|
650
|
|
|
$app['orm.em']->flush($BaseInfo); |
|
|
|
|
651
|
|
|
|
652
|
|
|
$app->addSuccess('admin.plugin.authentication.setting.complete', 'admin'); |
|
|
|
|
653
|
|
|
|
|
|
|
|
654
|
|
|
} |
655
|
|
|
} |
656
|
|
|
|
657
|
|
|
|
658
|
|
|
return $app->render('Store/authentication_setting.twig', array( |
659
|
|
|
'form' => $form->createView(), |
660
|
|
|
)); |
661
|
|
|
|
662
|
|
|
} |
663
|
|
|
|
664
|
|
|
|
665
|
|
|
/** |
666
|
|
|
* 認証キーダウンロード |
667
|
|
|
* |
668
|
|
|
* @param Application $app |
669
|
|
|
* @param Request $request |
|
|
|
|
670
|
|
|
* @return \Symfony\Component\HttpFoundation\RedirectResponse |
671
|
|
|
*/ |
672
|
|
|
public function download(Application $app, Request $request) |
|
|
|
|
673
|
|
|
{ |
674
|
|
|
|
675
|
|
|
$this->isTokenValid($app); |
676
|
|
|
|
677
|
|
|
$url = $app['config']['cacert_pem_url']; |
678
|
|
|
|
679
|
|
|
$curl = curl_init($url); |
680
|
|
|
$fileName = $app['config']['root_dir'].'/app/config/eccube/'.$this->certFileName; |
681
|
|
|
$fp = fopen($fileName, 'w'); |
682
|
|
|
|
683
|
|
|
curl_setopt($curl, CURLOPT_FILE, $fp); |
684
|
|
|
curl_setopt($curl, CURLOPT_HEADER, 0); |
685
|
|
|
|
686
|
|
|
curl_exec($curl); |
687
|
|
|
curl_close($curl); |
688
|
|
|
fclose($fp); |
689
|
|
|
|
690
|
|
|
$f = new Filesystem(); |
691
|
|
|
if ($f->exists($fileName)) { |
692
|
|
|
$app->addSuccess('admin.plugin.download.pem.complete', 'admin'); |
693
|
|
|
} else { |
694
|
|
|
$app->addError('admin.plugin.download.pem.error', 'admin'); |
695
|
|
|
} |
696
|
|
|
|
697
|
|
|
return $app->redirect($app->url('admin_store_authentication_setting')); |
698
|
|
|
|
699
|
|
|
} |
700
|
|
|
|
701
|
|
|
|
702
|
|
|
/** |
703
|
|
|
* APIリクエスト処理 |
704
|
|
|
* |
705
|
|
|
* @param Request $request |
706
|
|
|
* @param $authKey |
707
|
|
|
* @param string $url |
708
|
|
|
* @param Application $app |
709
|
|
|
* @return array |
710
|
|
|
*/ |
711
|
|
|
private function getRequestApi(Request $request, $authKey, $url, $app) |
712
|
|
|
{ |
713
|
|
|
$curl = curl_init($url); |
714
|
|
|
|
715
|
|
|
$options = array( // オプション配列 |
716
|
|
|
//HEADER |
717
|
|
|
CURLOPT_HTTPHEADER => array( |
718
|
|
|
'Authorization: '.base64_encode($authKey), |
719
|
|
|
'x-eccube-store-url: '.base64_encode($request->getSchemeAndHttpHost().$request->getBasePath()), |
720
|
|
|
'x-eccube-store-version: '.base64_encode(Constant::VERSION), |
721
|
|
|
), |
722
|
|
|
CURLOPT_HTTPGET => true, |
723
|
|
|
CURLOPT_SSL_VERIFYPEER => true, |
724
|
|
|
CURLOPT_RETURNTRANSFER => true, |
725
|
|
|
CURLOPT_FAILONERROR => true, |
726
|
|
|
); |
727
|
|
|
|
728
|
|
|
curl_setopt_array($curl, $options); /// オプション値を設定 |
729
|
|
|
|
730
|
|
|
$certFile = $app['config']['root_dir'].'/app/config/eccube/'.$this->certFileName; |
731
|
|
|
if (file_exists($certFile)) { |
732
|
|
|
// php5.6でサーバ上に適切な証明書がなければhttps通信エラーが発生するため、 |
733
|
|
|
// http://curl.haxx.se/ca/cacert.pem を利用して通信する |
734
|
|
|
curl_setopt($curl, CURLOPT_CAINFO, $certFile); |
735
|
|
|
} |
736
|
|
|
|
737
|
|
|
$result = curl_exec($curl); |
738
|
|
|
$info = curl_getinfo($curl); |
739
|
|
|
|
740
|
|
|
$message = curl_error($curl); |
741
|
|
|
$info['message'] = $message; |
742
|
|
|
curl_close($curl); |
743
|
|
|
|
744
|
|
|
$app->log('http get_info', $info); |
745
|
|
|
|
746
|
|
|
return array($result, $info); |
747
|
|
|
} |
748
|
|
|
|
749
|
|
|
/** |
750
|
|
|
* レスポンスのチェック |
751
|
|
|
* |
752
|
|
|
* @param $info |
753
|
|
|
* @return string |
754
|
|
|
*/ |
755
|
|
|
private function getResponseErrorMessage($info) |
756
|
|
|
{ |
757
|
|
|
if (!empty($info)) { |
758
|
|
|
$statusCode = $info['http_code']; |
759
|
|
|
$message = $info['message']; |
760
|
|
|
|
761
|
|
|
$message = $statusCode.' : '.$message; |
762
|
|
|
|
|
|
|
|
763
|
|
|
} else { |
764
|
|
|
$message = "タイムアウトエラーまたはURLの指定に誤りがあります。"; |
765
|
|
|
} |
766
|
|
|
|
767
|
|
|
return $message; |
768
|
|
|
} |
769
|
|
|
|
770
|
|
|
|
771
|
|
|
/** |
772
|
|
|
* フォルダ設置のみのプラグインを取得する. |
773
|
|
|
* |
774
|
|
|
* @param array $plugins |
775
|
|
|
* @param Application $app |
776
|
|
|
* @return array |
777
|
|
|
*/ |
778
|
|
|
protected function getUnregisteredPlugins(array $plugins, \Eccube\Application $app) |
|
|
|
|
779
|
|
|
{ |
780
|
|
|
$finder = new Finder(); |
781
|
|
|
$pluginCodes = array(); |
782
|
|
|
|
783
|
|
|
// DB登録済みプラグインコードのみ取得 |
784
|
|
|
foreach ($plugins as $key => $plugin) { |
785
|
|
|
$pluginCodes[] = $plugin->getCode(); |
786
|
|
|
} |
787
|
|
|
// DB登録済みプラグインコードPluginディレクトリから排他 |
788
|
|
|
$dirs = $finder->in($app['config']['plugin_realdir'])->depth(0)->directories(); |
789
|
|
|
|
790
|
|
|
// プラグイン基本チェック |
791
|
|
|
$unregisteredPlugins = array(); |
792
|
|
|
foreach ($dirs as $dir) { |
793
|
|
|
$pluginCode = $dir->getBasename(); |
794
|
|
|
if (in_array($pluginCode, $pluginCodes, true)) { |
795
|
|
|
continue; |
796
|
|
|
} |
797
|
|
|
try { |
798
|
|
|
$app['eccube.service.plugin']->checkPluginArchiveContent($dir->getRealPath()); |
799
|
|
|
} catch (\Eccube\Exception\PluginException $e) { |
800
|
|
|
//config.yamlに不備があった際は全てスキップ |
801
|
|
|
$app['monolog']->warning($e->getMessage()); |
802
|
|
|
continue; |
803
|
|
|
} |
804
|
|
|
$config = $app['eccube.service.plugin']->readYml($dir->getRealPath().'/config.yml'); |
805
|
|
|
$unregisteredPlugins[$pluginCode]['name'] = isset($config['name']) ? $config['name'] : null; |
806
|
|
|
$unregisteredPlugins[$pluginCode]['event'] = isset($config['event']) ? $config['event'] : null; |
807
|
|
|
$unregisteredPlugins[$pluginCode]['version'] = isset($config['version']) ? $config['version'] : null; |
808
|
|
|
$unregisteredPlugins[$pluginCode]['enable'] = Constant::DISABLED; |
809
|
|
|
$unregisteredPlugins[$pluginCode]['code'] = isset($config['code']) ? $config['code'] : null; |
810
|
|
|
} |
811
|
|
|
|
812
|
|
|
return $unregisteredPlugins; |
813
|
|
|
} |
814
|
|
|
} |
815
|
|
|
|