Issues (2366)

Branch: master

Security Analysis    not enabled

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

Command/GeneratorCommand/PluginGenerator.php (9 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
/*
4
 * This file is part of EC-CUBE
5
 *
6
 * Copyright(c) 2000-2015 LOCKON CO.,LTD. All Rights Reserved.
7
 *
8
 * http://www.lockon.co.jp/
9
 *
10
 * This program is free software; you can redistribute it and/or
11
 * modify it under the terms of the GNU General Public License
12
 * as published by the Free Software Foundation; either version 2
13
 * of the License, or (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program; if not, write to the Free Software
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23
 */
24
25
namespace Eccube\Command\GeneratorCommand;
26
27
use Eccube\Common\Constant;
28
use Eccube\Entity\Plugin;
29
use Eccube\Entity\PluginEventHandler;
30
use Symfony\Component\Filesystem\Filesystem;
31
use Symfony\Component\Yaml\Yaml;
32
33
class PluginGenerator extends AbstractPluginGenerator
0 ignored issues
show
Missing class doc comment
Loading history...
34
{
35
36
    /**
37
     *
38
     * @var array
39
     */
40
    private $hookPoints = null;
41
42
    /**
43
     *
44
     * @var array
45
     */
46
    private $events = null;
47
48 View Code Duplication
    protected function getHeader()
49
    {
50
        $this->output->writeln('------------------------------------------------------');
51
        $this->output->writeln('---Plugin Generator');
52
        $this->output->writeln('---[*]You can exit from Console Application, by typing '.self::STOP_PROCESS.' instead of typing another word.');
53
        $this->output->writeln('------------------------------------------------------');
54
        $this->output->writeln('');
55
    }
56
57
    protected function initFieldSet()
58
    {
59
        $this->paramList = array(
60
            'pluginName' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
61
                'no' => 1,
62
                'label' => '[+]Plugin Name: ',
63
                'value' => null,
64
                'name' => '[+]Please enter Plugin Name',
65
                'validation' => array(
66
                    'isRequired' => true,
67
                )
68
            ),
69
            'pluginCode' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
70
                'no' => 2,
71
                'label' => '[+]Plugin Code: ',
72
                'value' => null,
73
                'name' => '[+]Please enter Plugin Code (First letter is uppercase alphabet only. alphabet and numbers are allowed.)',
74
                'validation' => array(
75
                    'isRequired' => true,
76
                    'pattern' => '/^[A-Z][0-9a-zA-Z]*$/',
77
                    'isCode' => $this->getPluginCodes(),
78
                )
79
            ),
80
            'version' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
81
                'no' => 3,
82
                'label' => '[+]Version: ',
83
                'value' => null,
84
                'name' => '[+]Please enter version (correct format is x.y.z)',
85
                'validation' => array(
86
                    'isRequired' => true,
87
                    'pattern' => '/^\d+.\d+.\d+$/',
88
                )
89
            ),
90
            'author' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
91
                'no' => 4,
92
                'label' => '[+]Author: ',
93
                'value' => null,
94
                'name' => '[+]Please enter author name or company',
95
                'validation' => array(
96
                    'isRequired' => true,
97
                )
98
            ),
99
            'supportFlag' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
100
                'no' => 5,
101
                'label' => '[+]Old version support: ',
102
                'value' => null,
103
                'name' => '[+]Do you want to support old versions too? [y/n]',
104
                'show' => array(1 => 'Yes', 0 => 'No'),
105
                'validation' => array(
106
                    'isRequired' => true,
107
                    'choice' => array('y' => 1, 'n' => 0),
108
                )
109
            ),
110
            'events' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
111
                'no' => 6,
112
                'label' => '[+]SiteEvents: ',
113
                'value' => array(),
114
                'name' => '[+]Please enter site events(you can find documentation here http://www.ec-cube.net/plugin/)',
115
                'validation' => array(
116
                    'isRequired' => false,
117
                    'inArray' => 'getEvents',
118
                )
119
            ),
120
            'hookPoints' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
121
                'no' => 7,
122
                'label' => '[+]hookpoint: ',
123
                'value' => array(),
124
                'name' => '[+]Please enter hookpoint, sample:front.cart.up.initialize',
125
                'validation' => array(
126
                    'isRequired' => false,
127
                    'inArray' => $this->getHookPoints(),
128
                )
129
            ),
130
            'useOrmPath' => array(
0 ignored issues
show
Add a comma after each item in a multi-line array
Loading history...
131
                'no' => 8,
132
                'label' => '[+]Use orm.path: ',
133
                'value' => null,
134
                'name' => '[+]Would you like to use orm.path? [y/n]',
135
                'show' => array(1 => 'Yes', 0 => 'No'),
136
                'validation' => array(
137
                    'isRequired' => true,
138
                    'choice' => array('y' => 1, 'n' => 0),
139
                )
140
            ),
141
        );
142
    }
143
144
    /**
145
     * フックポイント一覧の取得
146
     *
147
     * @return array
148
     */
149
    protected function getHookPoints()
150
    {
151
        if ($this->hookPoints === null) {
152
            $Ref = new \ReflectionClass('\Eccube\Event\EccubeEvents');
153
            $this->hookPoints = array_flip($Ref->getConstants());
154
        }
155
156
        return $this->hookPoints;
157
    }
158
159
    /**
160
     * イベント一覧の取得
161
     *
162
     * @return array|mixed
163
     */
164
    protected function getEvents()
165
    {
166
        if (!isset($this->paramList['supportFlag']['value'])) {
167
            return array();
168
        }
169
        if ($this->events === null) {
170
            $this->events = array();
171
            $routeEvents = array();
172
            if ($this->paramList['supportFlag']['value']) {
173
                $this->events = include $this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/eventList.php';
174
                $routeEvents['eccube.event.controller.__route__.before'] = 'Controller__route__Before';
175
                $routeEvents['eccube.event.controller.__route__.after'] = 'Controller__route__After';
176
                $routeEvents['eccube.event.controller.__route__.finish'] = 'Controller__route__Finish';
177
                $routeEvents['eccube.event.render.__route__.before'] = 'Render__route__Before';
178
            }
179
            $this->events += include $this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/eventListNew.php';
180
181
            $routeEvents['eccube.event.route.__route__.request'] = 'Route__route__Request';
182
            $routeEvents['eccube.event.route.__route__.controller'] = 'Route__route__Controller';
183
            $routeEvents['eccube.event.route.__route__.response'] = 'Route__route__Response';
184
            $routeEvents['eccube.event.route.__route__.exception'] = 'Route__route__Exception';
185
            $routeEvents['eccube.event.route.__route__.terminate'] = 'Route__route__Terminate';
186
            $allRoutes = array();
187
188
            $controllers = $this->app['controllers'];
189
            $collection = $controllers->flush();
190
            foreach ($collection as $eventName => $dummy) {
191
                $allRoutes[] = $eventName;
192
            }
193
194
            $routes = $this->app['routes']->all();
195
196
            foreach ($routes as $eventName => $dummy) {
197
                $allRoutes[] = $eventName;
198
            }
199
200
            foreach ($allRoutes as $eventName) {
201
                $eventOnFunc = join(array_map('ucfirst', explode('_', strtolower($eventName))));
202
203
                foreach ($routeEvents as $keys => $node) {
204
                    $this->events[str_replace('__route__', $eventName, $keys)] = str_replace('__route__', $eventOnFunc, $node);
205
                }
206
            }
207
        }
208
209
        return $this->events;
210
    }
211
212
    protected function start()
213
    {
214
        $pluginCode = $this->paramList['pluginCode']['value'];
215
216
        $codes = $this->getPluginCodes();
217
        if (in_array($pluginCode, $codes)) {
218
            $this->exitGenerator('<error>Plugin with this code already exists.</error>');
219
220
            return;
221
        }
222
223
        $this->createFilesAndFolders($pluginCode, $this->paramList);
224
        $this->createDbRecords($pluginCode, $this->paramList);
225
        $this->exitGenerator('Plugin was created successfully');
226
    }
227
228
    private function createFilesAndFolders($code, $paramList)
229
    {
230
        $fsList = array(
231
            'dir' => array(),
232
            'file' => array(),
233
        );
234
235
        // config.ymlを作成
236
        $config = array();
237
        $config['name'] = $paramList['pluginName']['value'];
238
        $config['code'] = $code;
239
        $config['version'] = $paramList['version']['value'];
240
        if (!empty($paramList['hookPoints']['value']) || !empty($paramList['events']['value'])) {
241
            $config['event'] = $code.'Event';
242
        }
243
        $config['service'] = array($code.'ServiceProvider');
244
        if ($this->paramList['useOrmPath']['value']) {
245
            $config['orm.path'] = array('/Resource/doctrine');
246
        }
247
248
        $codePath = $this->app['config']['root_dir'].'/app/Plugin/'.$code;
249
250
        $file = new Filesystem();
251
        $file->mkdir($codePath);
252
        if (is_dir($codePath)) {
253
            $fsList['dir'][$codePath] = true;
254
        } else {
255
            $fsList['dir'][$codePath] = false;
256
        }
257
258
        $srcPath = $codePath.'/config.yml';
259
        file_put_contents($srcPath, Yaml::dump($config));
260 View Code Duplication
        if (is_file($srcPath)) {
261
            $fsList['file'][$srcPath] = true;
262
        } else {
263
            $fsList['file'][$srcPath] = false;
264
        }
265
266
        $author = $paramList['author']['value'];
267
        $year = date('Y');
268
269
        // PluginManager
270
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/PluginManager.php');
271
        $from = '/\[code\]/';
272
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
273
        $from = '/\[author\]/';
274
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
275
        $from = '/\[year\]/';
276
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
277
278
        $srcPath = $codePath.'/PluginManager.php';
279
        file_put_contents($srcPath, $pluginFileAfter);
280 View Code Duplication
        if (is_file($srcPath)) {
281
            $fsList['file'][$srcPath] = true;
282
        } else {
283
            $fsList['file'][$srcPath] = false;
284
        }
285
286
        // ServiceProvider
287
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/ServiceProvider.php');
288
        $from = '/\[code\]/';
289
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
290
        $from = '/\[lower_code\]/';
291
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
292
        $from = '/\[author\]/';
293
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
294
        $from = '/\[year\]/';
295
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
296
297
        $file->mkdir($codePath.'/ServiceProvider');
298 View Code Duplication
        if (is_dir($codePath.'/ServiceProvider')) {
299
            $fsList['dir'][$codePath.'/ServiceProvider'] = true;
300
        } else {
301
            $fsList['dir'][$codePath.'/ServiceProvider'] = false;
302
        }
303
304
        $srcPath = $codePath.'/ServiceProvider/'.$code.'ServiceProvider.php';
305
        file_put_contents($srcPath, $pluginFileAfter);
306 View Code Duplication
        if (is_file($srcPath)) {
307
            $fsList['file'][$srcPath] = true;
308
        } else {
309
            $fsList['file'][$srcPath] = false;
310
        }
311
312
        // ConfigController
313
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/ConfigController.php');
314
        $from = '/\[code\]/';
315
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
316
        $from = '/\[author\]/';
317
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
318
        $from = '/\[year\]/';
319
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
320
        $from = '/\[code_name\]/';
321
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
322
323
        $file->mkdir($codePath.'/Controller');
324 View Code Duplication
        if (is_dir($codePath.'/Controller')) {
325
            $fsList['dir'][$codePath.'/Controller'] = true;
326
        } else {
327
            $fsList['dir'][$codePath.'/Controller'] = false;
328
        }
329
330
        $srcPath = $codePath.'/Controller/ConfigController.php';
331
        file_put_contents($srcPath, $pluginFileAfter);
332 View Code Duplication
        if (is_file($srcPath)) {
333
            $fsList['file'][$srcPath] = true;
334
        } else {
335
            $fsList['file'][$srcPath] = false;
336
        }
337
338
        // Controller
339
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/Controller.php');
340
        $from = '/\[code\]/';
341
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
342
        $from = '/\[author\]/';
343
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
344
        $from = '/\[year\]/';
345
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
346
        $from = '/\[code_name\]/';
347
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
348
349
        $srcPath = $codePath.'/Controller/'.$code.'Controller.php';
350
        file_put_contents($srcPath, $pluginFileAfter);
351 View Code Duplication
        if (is_file($srcPath)) {
352
            $fsList['file'][$srcPath] = true;
353
        } else {
354
            $fsList['file'][$srcPath] = false;
355
        }
356
357
        // Form
358
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/ConfigType.php');
359
        $from = '/\[code\]/';
360
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
361
        $from = '/\[author\]/';
362
        $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
363
        $from = '/\[year\]/';
364
        $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
365
        $from = '/\[code_name\]/';
366
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileAfter);
367
368
        $file->mkdir($codePath.'/Form/Type');
369 View Code Duplication
        if (is_dir($codePath.'/Form/Type')) {
370
            $fsList['dir'][$codePath.'/Form/Type'] = true;
371
        } else {
372
            $fsList['dir'][$codePath.'/Form/Type'] = false;
373
        }
374
375
        $srcPath = $codePath.'/Form/Type/'.$code.'ConfigType.php';
376
        file_put_contents($codePath.'/Form/Type/'.$code.'ConfigType.php', $pluginFileAfter);
377 View Code Duplication
        if (is_file($srcPath)) {
378
            $fsList['file'][$srcPath] = true;
379
        } else {
380
            $fsList['file'][$srcPath] = false;
381
        }
382
383
        // Twig
384
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/config.twig');
385
        $from = '/\[code\]/';
386
        $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
387
388
        $file->mkdir($codePath.'/Resource/template/admin');
389 View Code Duplication
        if (is_dir($codePath.'/Resource/template/admin')) {
390
            $fsList['dir'][$codePath.'/Resource/template/admin'] = true;
391
        } else {
392
            $fsList['dir'][$codePath.'/Resource/template/admin'] = false;
393
        }
394
395
        $srcPath = $codePath.'/Resource/template/admin/config.twig';
396
        file_put_contents($srcPath, $pluginFileAfter);
397 View Code Duplication
        if (is_file($srcPath)) {
398
            $fsList['file'][$srcPath] = true;
399
        } else {
400
            $fsList['file'][$srcPath] = false;
401
        }
402
403
        // index.twig
404
        $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/index.twig');
405
        $from = '/\[code\]/';
406
        $pluginFileAfter = preg_replace($from, mb_strtolower($code), $pluginFileBefore);
407
408
        $file->mkdir($codePath.'/Resource/template/admin');
409 View Code Duplication
        if (is_dir($codePath.'/Resource/template/admin')) {
410
            $fsList['dir'][$codePath.'/Resource/template/admin'] = true;
411
        } else {
412
            $fsList['dir'][$codePath.'/Resource/template/admin'] = false;
413
        }
414
415
        $srcPath = $codePath.'/Resource/template/index.twig';
416
        file_put_contents($srcPath, $pluginFileAfter);
417 View Code Duplication
        if (is_file($srcPath)) {
418
            $fsList['file'][$srcPath] = true;
419
        } else {
420
            $fsList['file'][$srcPath] = false;
421
        }
422
423
        $onFunctions = array();
424
        $eventKeys = array();
425
        $onEvents = array();
426
427
        // イベント
428
        $events = $paramList['events']['value'];
429
        if (count($events) > 0) {
430
            foreach ($events as $eventKey => $eventConst) {
431
                $onEvents[$eventKey] = array(array('on'.$eventConst.', NORMAL'));
432
                $onFunctions[$eventKey] = 'on'.$eventConst;
433
                $eventKeys[] = $eventKey;
434
            }
435
        }
436
437
        // フックポイント
438
        $hookPoints = $paramList['hookPoints']['value'];
439
        if (count($hookPoints)) {
440
            foreach ($hookPoints as $hookKey => $hookConst) {
441
                $onName = 'on'.join(array_map('ucfirst', explode('_', strtolower($hookConst))));
442
                $onEvents[$hookKey] = array(array($onName.', NORMAL'));
443
                $onFunctions[$hookKey] = $onName;
444
            }
445
        }
446
447
        if (count($onEvents)) {
448
            $srcPath = $codePath.'/event.yml';
449
            file_put_contents($srcPath, str_replace('\'', '', Yaml::dump($onEvents)));
450 View Code Duplication
            if (is_file($srcPath)) {
451
                $fsList['file'][$srcPath] = true;
452
            } else {
453
                $fsList['file'][$srcPath] = false;
454
            }
455
456
            $pluginFileBefore = file_get_contents($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/Event.php');
457
458
            // Event
459
            $from = '/\[code\]/';
460
            $pluginFileAfter = preg_replace($from, $code, $pluginFileBefore);
461
            $from = '/\[author\]/';
462
            $pluginFileAfter = preg_replace($from, $author, $pluginFileAfter);
463
            $from = '/\[year\]/';
464
            $pluginFileAfter = preg_replace($from, $year, $pluginFileAfter);
465
466
            $functions = '';
467
            $args = include $this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/eventArguments.php';
468
            foreach ($onFunctions as $key => $name) {
469
                if (in_array($key, $eventKeys)) {
470
                    // 共通イベントは引数の型を利用するイベントにより変更
471
                    $ext = pathinfo($key, PATHINFO_EXTENSION);
472
                    if (array_key_exists($ext, $args)) {
473
                        $functions .= "    /**\n     * @param {$args[$ext]} \$event\n     */\n    public function {$name}({$args[$ext]} \$event)\n    {\n    }\n\n";
474
                    } else {
475
                        // 旧イベントの場合、引数は「eccube.event.render」のみ可能
476
                        if (preg_match("/^eccube.event.render\./", $key)) {
477
                            $functions .= "    /**\n     * @param {$args['eccube.event.render']} \$event\n     */\n    public function {$name}({$args['eccube.event.render']} \$event)\n    {\n    }\n\n";
478
                        } else {
479
                            $functions .= "    /**\n     *\n     */\n    public function {$name}()\n    {\n    }\n\n";
480
                        }
481
                    }
482
                } else {
483
                    // HookPointイベントの引数はEventArgs共通
484
                    $functions .= "    /**\n     * @param EventArgs \$event\n     */\n    public function {$name}(EventArgs \$event)\n    {\n    }\n\n";
485
                }
486
            }
487
            $from = '/\[hookpoint_function\]/';
488
            $pluginFileAfter = preg_replace($from, $functions, $pluginFileAfter);
489
            $srcPath = $codePath.'/'.$code.'Event.php';
490
            file_put_contents($srcPath, $pluginFileAfter);
491 View Code Duplication
            if (is_file($srcPath)) {
492
                $fsList['file'][$srcPath] = true;
493
            } else {
494
                $fsList['file'][$srcPath] = false;
495
            }
496
        }
497
498
        // LICENSE
499
        $srcPath = $codePath.'/LICENSE';
500
        $file->copy($this->app['config']['root_dir'].'/src/Eccube/Command/GeneratorCommand/generatortemplate/LICENSE', $srcPath);
501 View Code Duplication
        if (is_file($srcPath)) {
502
            $fsList['file'][$srcPath] = true;
503
        } else {
504
            $fsList['file'][$srcPath] = false;
505
        }
506
507
        $this->completeMessage($fsList);
508
509
    }
510
511
    private function createDbRecords($code, $paramList)
512
    {
513
        // DB登録
514
        $Plugin = new Plugin();
515
        $Plugin->setName($paramList['pluginName']['value']);
516
        $Plugin->setCode($code);
517
        $Plugin->setClassName('');
518
        $Plugin->setVersion($paramList['version']['value']);
519
        $Plugin->setEnable(Constant::DISABLED);
520
        $Plugin->setSource(0);
521
        $Plugin->setDelFlg(Constant::DISABLED);
522
523
        $this->app['orm.em']->persist($Plugin);
524
        $this->app['orm.em']->flush($Plugin);
525
526
        $this->output->writeln('');
527
        $this->output->writeln('[+]Database');
528
        if ($Plugin->getId()) {
529
            $this->output->writeln('<info> Plugin information was added to table [DB.Plugin] (id='.$Plugin->getId().')</info>');
530
        } else {
531
            $this->output->writeln('<error> there was a problem inserting plugin information to table [DB.Plugin] (id='.$Plugin->getId().')</error>');
532
        }
533
534
        $hookPoints = $paramList['hookPoints']['value'];
535
        if (empty($hookPoints)) {
536
            return;
537
        }
538
539
        $eventCount = 0;
540
        foreach ($hookPoints as $hookKey => $hookConst) {
541
            $PluginEventHandler = new PluginEventHandler();
542
            $functionName = 'on'.join(array_map('ucfirst', explode('_', strtolower($hookConst))));
543
            $PluginEventHandler->setPlugin($Plugin)
544
                ->setEvent($hookKey)
545
                ->setPriority($this->app['eccube.repository.plugin_event_handler']->calcNewPriority($hookKey, $functionName))
546
                ->setHandler($functionName)
547
                ->setHandlerType('NORMAL')
548
                ->setDelFlg(Constant::DISABLED);
549
            $this->app['orm.em']->persist($PluginEventHandler);
550
            $eventCount++;
551
        }
552
        $this->app['orm.em']->flush();
553
        if ($eventCount) {
554
            $this->output->writeln('');
555
            $this->output->writeln('<info> Plugin information was added to table [DB.PluginEventHandler] (inserts number='.$eventCount.') </info>');
556
        }
557
    }
558
}
559