Completed
Pull Request — experimental/3.1 (#2566)
by chihiro
205:03 queued 181:20
created

PluginService::update()   B

Complexity

Conditions 5
Paths 43

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 16
CRAP Score 5.7044

Importance

Changes 0
Metric Value
cc 5
eloc 25
nc 43
nop 2
dl 0
loc 38
ccs 16
cts 23
cp 0.6957
crap 5.7044
rs 8.439
c 0
b 0
f 0
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\Service;
26
27
use Doctrine\ORM\EntityManager;
28
use Eccube\Annotation\Inject;
29
use Eccube\Annotation\Service;
30
use Eccube\Application;
31
use Eccube\Common\Constant;
32
use Eccube\Entity\Plugin;
33
use Eccube\Exception\PluginException;
34
use Eccube\Plugin\ConfigManager;
35
use Eccube\Plugin\ConfigManager as PluginConfigManager;
36
use Eccube\Repository\PluginEventHandlerRepository;
37
use Eccube\Repository\PluginRepository;
38
use Eccube\Util\Cache;
39
use Eccube\Util\Str;
40
use Symfony\Component\Filesystem\Filesystem;
41
use Symfony\Component\Yaml\Yaml;
42
43
/**
44
 * @Service
45
 */
46
class PluginService
47
{
48
    /**
49
     * @Inject(PluginEventHandlerRepository::class)
50
     * @var PluginEventHandlerRepository
51
     */
52
    protected $pluginEventHandlerRepository;
53
54
    /**
55
     * @Inject("orm.em")
56
     * @var EntityManager
57
     */
58
    protected $entityManager;
59
60
    /**
61
     * @Inject(PluginRepository::class)
62
     * @var PluginRepository
63
     */
64
    protected $pluginRepository;
65
66
    /**
67
     * @Inject("config")
68
     * @var array
69
     */
70
    protected $appConfig;
71
72
    /**
73
     * @Inject(Application::class)
74
     * @var Application
75
     */
76
    protected $app;
77
78
    /**
79
     * @var EntityProxyService
80
     * @Inject(EntityProxyService::class)
81
     */
82
    protected $entityProxyService;
83
84
    /**
85
     * @Inject(SchemaService::class)
86
     * @var SchemaService
87
     */
88
    protected $schemaService;
89
90
    const CONFIG_YML = 'config.yml';
91
    const EVENT_YML = 'event.yml';
92
93 15
    // ファイル指定してのプラグインインストール
94
    public function install($path, $source = 0)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
95 15
    {
96 15
        $pluginBaseDir = null;
97
        $tmp = null;
98
99
        try {
100 15
            // プラグイン配置前に実施する処理
101 15
            $this->preInstall();
102
103
            $tmp = $this->createTempDir();
104 15
105 15
            $this->unpackPluginArchive($path, $tmp); //一旦テンポラリに展開
106 15
            $this->checkPluginArchiveContent($tmp);
107
108 15
            $config = $this->readYml($tmp.'/'.self::CONFIG_YML);
109 15
            $event = $this->readYml($tmp.'/'.self::EVENT_YML);
110
            $this->deleteFile($tmp); // テンポラリのファイルを削除
111 13
112 13
            $this->checkSamePlugin($config['code']); // 重複していないかチェック
113 13
114
            $pluginBaseDir = $this->calcPluginDir($config['code']);
115 13
            $this->createPluginDir($pluginBaseDir); // 本来の置き場所を作成
116
117 13
            $this->unpackPluginArchive($path, $pluginBaseDir); // 問題なければ本当のplugindirへ
118 13
119
            // プラグイン配置後に実施する処理
120 13
            $this->postInstall($config, $event, $source);
121
        } catch (PluginException $e) {
122 13
            $this->deleteDirs(array($tmp, $pluginBaseDir));
123
            throw $e;
124
        } catch (\Exception $e) { // インストーラがどんなExceptionを上げるかわからないので
125 12
126 12
            $this->deleteDirs(array($tmp, $pluginBaseDir));
127
            throw $e;
128 12
        }
129 4
130 4
        return true;
131 4
    }
132
133
    // インストール事前処理
134
    public function preInstall()
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
135
    {
136 12
        // キャッシュの削除
137 15
        PluginConfigManager::removePluginConfigCache();
138 12
        Cache::clear($this->app, false);
139
    }
140 15
141
    // インストール事後処理
142
    public function postInstall($config, $event, $source)
0 ignored issues
show
introduced by
You must use "/**" style comments for a function comment
Loading history...
143
    {
144
        // Proxyのクラスをロードせずにスキーマを更新するために、
145
        // インストール時には一時的なディレクトリにProxyを生成する
146
        $tmpProxyOutputDir = sys_get_temp_dir() . '/proxy_' . Str::random(12);
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
147
        @mkdir($tmpProxyOutputDir);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
148 15
149 15
        try {
150
            // dbにプラグイン登録
151 15
            $plugin = $this->registerPlugin($config, $event, $source);
152
153
            // インストール時には一時的に利用するProxyを生成してからスキーマを更新する
154
            $generatedFiles = $this->regenerateProxy($plugin, true, $tmpProxyOutputDir);
155 15
            $this->schemaService->updateSchema($generatedFiles, $tmpProxyOutputDir);
156
157
            ConfigManager::writePluginConfigCache();
158
        } finally {
159
            foreach (glob("${tmpProxyOutputDir}/*") as  $f) {
0 ignored issues
show
Coding Style introduced by
There should be 1 space after "as" as per the coding-style, but found 2.
Loading history...
160 4
                unlink($f);
161 4
            }
162 3
            rmdir($tmpProxyOutputDir);
163 4
        }
164
    }
165
166
    public function createTempDir()
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
167
    {
168
        @mkdir($this->appConfig['plugin_temp_realdir']);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
169
        $d = ($this->appConfig['plugin_temp_realdir'].'/'.sha1(Str::random(16)));
170 15
171
        if (!mkdir($d, 0777)) {
172 15
            throw new PluginException($php_errormsg.$d);
173
        }
174
175
        return $d;
176
    }
177
178 15
    public function deleteDirs($arr)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
179 15
    {
180
        foreach ($arr as $dir) {
181
            if (file_exists($dir)) {
182
                $fs = new Filesystem();
183
                $fs->remove($dir);
184
            }
185
        }
186
    }
187
188
    public function unpackPluginArchive($archive, $dir)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
189 1067
    {
190 1067
        $extension = pathinfo($archive, PATHINFO_EXTENSION);
191
        try {
192 1067
            if ($extension == 'zip') {
193
                $zip = new \ZipArchive();
194
                $zip->open($archive);
195
                $zip->extractTo($dir);
196
                $zip->close();
197
            } else {
198 1067
                $phar = new \PharData($archive);
199 2
                $phar->extractTo($dir, null, true);
200
            }
201 1067
        } catch (\Exception $e) {
202
            throw new PluginException('アップロードに失敗しました。圧縮ファイルを確認してください。');
203
        }
204 1067
    }
205
206 1
    public function checkPluginArchiveContent($dir, array $config_cache = array())
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
207
    {
208 1067
        try {
209
            if (!empty($config_cache)) {
210
                $meta = $config_cache;
211 1067
            } else {
212
                $meta = $this->readYml($dir . '/config.yml');
0 ignored issues
show
Coding Style introduced by
Concat operator must not be surrounded by spaces
Loading history...
213
            }
214
        } catch (\Symfony\Component\Yaml\Exception\ParseException $e) {
215 1067
            throw new PluginException($e->getMessage(), $e->getCode(), $e);
216
        }
217
218
        if (!is_array($meta)) {
219
            throw new PluginException('config.yml not found or syntax error');
220 1067
        }
221 View Code Duplication
        if (!isset($meta['code']) || !$this->checkSymbolName($meta['code'])) {
222
            throw new PluginException('config.yml code empty or invalid_character(\W)');
223
        }
224
        if (!isset($meta['name'])) {
225
            // nameは直接クラス名やPATHに使われるわけではないため文字のチェックはなしし
226
            throw new PluginException('config.yml name empty');
227
        }
228 View Code Duplication
        if (isset($meta['event']) && !$this->checkSymbolName($meta['event'])) { // eventだけは必須ではない
229 16
            throw new PluginException('config.yml event empty or invalid_character(\W) ');
230 14
        }
231
        if (!isset($meta['version'])) {
232
            // versionは直接クラス名やPATHに使われるわけではないため文字のチェックはなしし
233 13
            throw new PluginException('config.yml version invalid_character(\W) ');
234
        }
235
        if (isset($meta['orm.path'])) {
236
            if (!is_array($meta['orm.path'])) {
237
                throw new PluginException('config.yml orm.path invalid_character(\W) ');
238 1067
            }
239
        }
240
        if (isset($meta['service'])) {
241
            if (!is_array($meta['service'])) {
242
                throw new PluginException('config.yml service invalid_character(\W) ');
243
            }
244
        }
245
    }
246 13
247 13
    public function readYml($yml)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
248
    {
249
        if (file_exists($yml)) {
250
            return Yaml::parse(file_get_contents($yml));
251
        }
252 13
253 13
        return false;
254 1
    }
255
256
    public function checkSymbolName($string)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
257
    {
258
        return strlen($string) < 256 && preg_match('/^\w+$/', $string);
259
        // plugin_nameやplugin_codeに使える文字のチェック
260 13
        // a-z A-Z 0-9 _
261
        // ディレクトリ名などに使われれるので厳しめ
262
    }
263
264
    public function deleteFile($path)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
265 13
    {
266 13
        $f = new Filesystem();
267
        $f->remove($path);
268
    }
269
270
    public function checkSamePlugin($code)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
271
    {
272
        $repo = $this->pluginRepository->findOneBy(array('code' => $code));
273 13
        if ($repo) {
274 13
            throw new PluginException('plugin already installed.');
275
        }
276 13
    }
277
278 13
    public function calcPluginDir($name)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
279 13
    {
280 13
        return $this->appConfig['plugin_realdir'].'/'.$name;
281 13
    }
282 13
283 13
    public function createPluginDir($d)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
284
    {
285 13
        $b = @mkdir($d);
286 13
        if (!$b) {
287
            throw new PluginException($php_errormsg);
288 13
        }
289 2
    }
290 2
291 2
    public function registerPlugin($meta, $event_yml, $source = 0)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
292
    {
293
        $em = $this->entityManager;
294 2
        $em->getConnection()->beginTransaction();
295 2
        try {
296 2
            $p = new \Eccube\Entity\Plugin();
297 2
            // インストール直後はプラグインは有効にしない
298 2
            $p->setName($meta['name'])
299 2
                ->setEnable(Constant::DISABLED)
300 2
                ->setClassName(isset($meta['event']) ? $meta['event'] : '')
301 2
                ->setVersion($meta['version'])
302
                ->setSource($source)
303
                ->setCode($meta['code']);
304
305
            $em->persist($p);
306 13
            $em->flush();
307
308 13
            if (is_array($event_yml)) {
309
                foreach ($event_yml as $event => $handlers) {
310 12
                    foreach ($handlers as $handler) {
311 12
                        if (!$this->checkSymbolName($handler[0])) {
312 1
                            throw new PluginException('Handler name format error');
313 1
                        }
314 1
                        $peh = new \Eccube\Entity\PluginEventHandler();
315
                        $peh->setPlugin($p)
316
                            ->setEvent($event)
317 12
                            ->setHandler($handler[0])
318
                            ->setHandlerType($handler[1])
319
                            ->setPriority($this->pluginEventHandlerRepository->calcNewPriority($event, $handler[1]));
320
                        $em->persist($peh);
321
                        $em->flush();
322 13
                    }
323 13
                }
324 3
            }
325 3
326 3
            $em->persist($p);
327
328
            $this->callPluginManagerMethod($meta, 'install');
329
330
            $em->flush();
331
            $em->getConnection()->commit();
332
        } catch (\Exception $e) {
333 7
            $em->getConnection()->rollback();
334 7
            throw new PluginException($e->getMessage());
335 7
        }
336 7
337 7
        return $p;
338 7
    }
339 7
340 7
    public function callPluginManagerMethod($meta, $method)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
341
    {
342
        $class = '\\Plugin'.'\\'.$meta['code'].'\\'.'PluginManager';
343 7
        if (class_exists($class)) {
344
            $installer = new $class(); // マネージャクラスに所定のメソッドがある場合だけ実行する
345 7
            if (method_exists($installer, $method)) {
346 7
                $installer->$method($meta, $this->app);
347
            }
348
        }
349
    }
350
351
    public function uninstall(\Eccube\Entity\Plugin $plugin)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
352 7
    {
353 7
        $pluginDir = $this->calcPluginDir($plugin->getCode());
354 2
        ConfigManager::removePluginConfigCache();
355
        Cache::clear($this->app, false);
356 7
        $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'disable');
357 7
        $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), 'uninstall');
358
        $this->disable($plugin);
359
        $this->unregisterPlugin($plugin);
360
        $this->deleteFile($pluginDir);
361
362
        // スキーマを更新する
363
        $this->schemaService->updateSchema([], $this->appConfig['root_dir'].'/app/proxy/entity');
364
365 8
        ConfigManager::writePluginConfigCache();
366
        return true;
0 ignored issues
show
introduced by
Missing blank line before return statement
Loading history...
367
    }
368
369
    public function unregisterPlugin(\Eccube\Entity\Plugin $p)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
370
    {
371
        try {
372
            $em = $this->entityManager;
373
            foreach ($p->getPluginEventHandlers()->toArray() as $peh) {
374
                $em->remove($peh);
375
            }
376
            $em->remove($p);
377 12
            $em->flush();
378 10
        } catch (\Exception $e) {
379
            throw $e;
380 12
        }
381
    }
382 12
383
    public function disable(\Eccube\Entity\Plugin $plugin)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
384 12
    {
385
        return $this->enable($plugin, false);
386
    }
387 12
388 12
    /**
389 12
     * Proxyを再生成します.
390
     * @param Plugin $plugin プラグイン
391 8
     * @param boolean $temporary プラグインが無効状態でも一時的に生成するかどうか
392 8
     * @param string|null $outputDir 出力先
393 8
     * @return array 生成されたファイルのパス
394 8
     */
395
    private function regenerateProxy(Plugin $plugin, $temporary, $outputDir = null)
396
    {
397
        if (is_null($outputDir)) {
398
            $outputDir = $this->appConfig['root_dir'].'/app/proxy/entity';
399 12
        }
400 12
        @mkdir($outputDir);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
401
402 12
        $enabledPluginCodes = array_map(
403 12
            function($p) { return $p->getCode(); },
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
Coding Style introduced by
Opening brace must be the last content on the line
Loading history...
introduced by
Missing blank line before return statement
Loading history...
404 12
            $this->pluginRepository->findAllEnabled()
405 12
        );
406
407
        $excludes = [];
408
        if ($temporary || $plugin->getEnable() === Constant::ENABLED) {
409
            $enabledPluginCodes[] = $plugin->getCode();
410
        } else {
411 11
            $index = array_search($plugin->getCode(), $enabledPluginCodes);
412
            if ($index >= 0) {
413 11
                array_splice($enabledPluginCodes, $index, 1);
414 11
                $excludes = [$this->appConfig['root_dir']."/app/Plugin/".$plugin->getCode()."/Entity"];
415 11
            }
416 11
        }
417 11
418 11
        $enabledPluginEntityDirs = array_map(function($code) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space after FUNCTION keyword; 0 found
Loading history...
419
            return $this->appConfig['root_dir']."/app/Plugin/${code}/Entity";
420 11
        }, $enabledPluginCodes);
421
422
        return $this->entityProxyService->generate(
423 10
            array_merge([$this->appConfig['root_dir'].'/app/Acme/Entity'], $enabledPluginEntityDirs),
424
            $excludes,
425 10
            $outputDir
426 10
        );
427 10
    }
428 1
429 1
    public function enable(\Eccube\Entity\Plugin $plugin, $enable = true)
0 ignored issues
show
introduced by
Declare public methods first, then protected ones and finally private ones
Loading history...
introduced by
Missing function doc comment
Loading history...
430 1
    {
431
        $em = $this->entityManager;
432
        try {
433 10
            PluginConfigManager::removePluginConfigCache();
434
            Cache::clear($this->app, false);
435
            $pluginDir = $this->calcPluginDir($plugin->getCode());
436
            $em->getConnection()->beginTransaction();
437
            $plugin->setEnable($enable ? Constant::ENABLED : Constant::DISABLED);
438 1
            $em->persist($plugin);
439 1
440
            $this->callPluginManagerMethod(Yaml::parse(file_get_contents($pluginDir.'/'.self::CONFIG_YML)), $enable ? 'enable' : 'disable');
441 1
442 1
            // Proxyだけ再生成してスキーマは更新しない
443 1
            $this->regenerateProxy($plugin, false);
444
445 1
            $em->flush();
446 1
            $em->getConnection()->commit();
447
            PluginConfigManager::writePluginConfigCache();
448 1
        } catch (\Exception $e) {
449 1
            $em->getConnection()->rollback();
450
            throw $e;
451 1
        }
452
453
        return true;
454
    }
455 1
456 1
    public function update(\Eccube\Entity\Plugin $plugin, $path)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
457
    {
458 1
        $pluginBaseDir = null;
459 1
        $tmp = null;
460
        try {
461 1
            PluginConfigManager::removePluginConfigCache();
462
            Cache::clear($this->app, false);
463
            $tmp = $this->createTempDir();
464
465
            $this->unpackPluginArchive($path, $tmp); //一旦テンポラリに展開
466
            $this->checkPluginArchiveContent($tmp);
467
468
            $config = $this->readYml($tmp.'/'.self::CONFIG_YML);
469
            $event = $this->readYml($tmp.'/event.yml');
470
471
            if ($plugin->getCode() != $config['code']) {
472 1
                throw new PluginException('new/old plugin code is different.');
473
            }
474
475
            $pluginBaseDir = $this->calcPluginDir($config['code']);
476
            $this->deleteFile($tmp); // テンポラリのファイルを削除
477
478 1
            $this->unpackPluginArchive($path, $pluginBaseDir); // 問題なければ本当のplugindirへ
479 1
            $this->updatePlugin($plugin, $config, $event); // dbにプラグイン登録
480 1
481 1
            PluginConfigManager::writePluginConfigCache();
482
        } catch (PluginException $e) {
483 1
            foreach (array($tmp) as $dir) {
484 1
                if (file_exists($dir)) {
485
                    $fs = new Filesystem();
486
                    $fs->remove($dir);
487 1
                }
488
            }
489 1
            throw $e;
490 1
        }
491 1
492 1
        return true;
493
    }
494
495
    public function updatePlugin(\Eccube\Entity\Plugin $plugin, $meta, $event_yml)
0 ignored issues
show
introduced by
Missing function doc comment
Loading history...
496 1
    {
497 1
        try {
498 1
            $em = $this->entityManager;
499 1
            $em->getConnection()->beginTransaction();
500 1
            $plugin->setVersion($meta['version'])
501
                ->setName($meta['name']);
502 1
503 1
            if (isset($meta['event'])) {
504 1
                $plugin->setClassName($meta['event']);
505 1
            }
506 1
507 1
            $rep = $this->pluginEventHandlerRepository;
508 1
509 1
            if (is_array($event_yml)) {
510 1
                foreach ($event_yml as $event => $handlers) {
511
                    foreach ($handlers as $handler) {
512
                        if (!$this->checkSymbolName($handler[0])) {
513
                            throw new PluginException('Handler name format error');
514
                        }
515
                        // updateで追加されたハンドラかどうか調べる
516 1
                        $peh = $rep->findBy(array(
517 1
                            'plugin_id' => $plugin->getId(),
518
                            'event' => $event,
519
                            'handler' => $handler[0],
520
                            'handler_type' => $handler[1],));
0 ignored issues
show
Coding Style introduced by
This line of the multi-line function call does not seem to be indented correctly. Expected 24 spaces, but found 28.
Loading history...
introduced by
Add a single space after each comma delimiter
Loading history...
521 1
522 1
                        if (!$peh) { // 新規にevent.ymlに定義されたハンドラなのでinsertする
0 ignored issues
show
Bug Best Practice introduced by
The expression $peh of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
523 1
                            $peh = new \Eccube\Entity\PluginEventHandler();
524 1
                            $peh->setPlugin($plugin)
525
                                ->setEvent($event)
526
                                ->setHandler($handler[0])
527 1
                                ->setHandlerType($handler[1])
528 1
                                ->setPriority($rep->calcNewPriority($event, $handler[1]));
529 1
                            $em->persist($peh);
530
                            $em->flush();
531
                        }
532
                    }
533
                }
534
535 1
                # アップデート後のevent.ymlで削除されたハンドラをdtb_plugin_event_handlerから探して削除
0 ignored issues
show
Coding Style introduced by
Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.
Loading history...
536 1
                foreach ($rep->findBy(array('plugin_id' => $plugin->getId())) as $peh) {
537 1
                    if (!isset($event_yml[$peh->getEvent()])) {
538 1
                        $em->remove($peh);
539
                        $em->flush();
540
                    } else {
541
                        $match = false;
542
                        foreach ($event_yml[$peh->getEvent()] as $handler) {
543
                            if ($peh->getHandler() == $handler[0] && $peh->getHandlerType() == $handler[1]) {
544
                                $match = true;
545
                            }
546
                        }
547
                        if (!$match) {
548
                            $em->remove($peh);
549
                            $em->flush();
550
                        }
551
                    }
552
                }
553
            }
554
555
            $em->persist($plugin);
556
            $this->callPluginManagerMethod($meta, 'update');
557
            $em->flush();
558
            $em->getConnection()->commit();
559
        } catch (\Exception $e) {
560
            $em->getConnection()->rollback();
561
            throw $e;
562
        }
563
    }
564
}
565