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