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