|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of EC-CUBE |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright(c) LOCKON CO.,LTD. All Rights Reserved. |
|
7
|
|
|
* |
|
8
|
|
|
* http://www.lockon.co.jp/ |
|
9
|
|
|
* |
|
10
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
11
|
|
|
* file that was distributed with this source code. |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace Eccube\Service\Composer; |
|
15
|
|
|
|
|
16
|
|
|
use Doctrine\ORM\EntityManagerInterface; |
|
17
|
|
|
use Eccube\Common\EccubeConfig; |
|
18
|
|
|
use Eccube\Entity\BaseInfo; |
|
19
|
|
|
use Eccube\Exception\PluginException; |
|
20
|
|
|
use Eccube\Repository\BaseInfoRepository; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Class ComposerProcessService |
|
24
|
|
|
*/ |
|
25
|
|
|
class ComposerProcessService implements ComposerServiceInterface |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var EccubeConfig config parameter |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $eccubeConfig; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @var EntityManagerInterface |
|
34
|
|
|
*/ |
|
35
|
|
|
protected $entityManager; |
|
36
|
|
|
|
|
37
|
|
|
private $workingDir; |
|
|
|
|
|
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* @var ComposerApiService |
|
41
|
|
|
*/ |
|
42
|
|
|
private $composerApiService; |
|
43
|
|
|
/** |
|
44
|
|
|
* @var BaseInfoRepository |
|
45
|
|
|
*/ |
|
46
|
|
|
private $baseInfoRepository; |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* ComposerProcessService constructor. |
|
50
|
|
|
* |
|
51
|
|
|
* @param EccubeConfig $eccubeConfig |
|
52
|
|
|
* @param EntityManagerInterface $entityManager |
|
53
|
|
|
* @param ComposerApiService $composerApiService |
|
54
|
|
|
*/ |
|
55
|
|
|
public function __construct(EccubeConfig $eccubeConfig, EntityManagerInterface $entityManager, ComposerApiService $composerApiService, BaseInfoRepository $baseInfoRepository) |
|
56
|
|
|
{ |
|
57
|
|
|
$this->eccubeConfig = $eccubeConfig; |
|
58
|
|
|
$this->entityManager = $entityManager; |
|
59
|
|
|
$this->composerApiService = $composerApiService; |
|
60
|
|
|
$this->baseInfoRepository = $baseInfoRepository; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function execRequire($packageName, $output = null) |
|
64
|
|
|
{ |
|
65
|
|
|
return $this->runCommand([ |
|
66
|
|
|
'eccube:composer:require', |
|
67
|
|
|
$packageName, |
|
68
|
|
|
], $output); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
public function execRemove($packageName, $output = null) |
|
72
|
|
|
{ |
|
73
|
|
|
return $this->runCommand([ |
|
74
|
|
|
'eccube:composer:remove', |
|
75
|
|
|
$packageName, |
|
76
|
|
|
], $output); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* Run command |
|
81
|
|
|
* |
|
82
|
|
|
* @throws PluginException |
|
83
|
|
|
* |
|
84
|
|
|
* @param string $command |
|
|
|
|
|
|
85
|
|
|
*/ |
|
86
|
|
|
public function runCommand($commands, $output = null, $init = true) |
|
|
|
|
|
|
87
|
|
|
{ |
|
88
|
|
|
if ($init) { |
|
89
|
|
|
$this->init(); |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
$command = implode(' ', array_merge(['bin/console'], $commands)); |
|
93
|
|
|
try { |
|
94
|
|
|
// Execute command |
|
95
|
|
|
$returnValue = -1; |
|
96
|
|
|
$output = []; |
|
97
|
|
|
exec($command, $output, $returnValue); |
|
98
|
|
|
|
|
99
|
|
|
$outputString = implode(PHP_EOL, $output); |
|
100
|
|
|
if ($returnValue) { |
|
|
|
|
|
|
101
|
|
|
throw new PluginException($outputString); |
|
102
|
|
|
} |
|
103
|
|
|
log_info(PHP_EOL.$outputString.PHP_EOL); |
|
104
|
|
|
|
|
105
|
|
|
return $outputString; |
|
106
|
|
|
} catch (\Exception $exception) { |
|
107
|
|
|
throw new PluginException($exception->getMessage()); |
|
108
|
|
|
} |
|
109
|
|
|
} |
|
110
|
|
|
|
|
111
|
|
|
/** |
|
112
|
|
|
* Set init |
|
113
|
|
|
* |
|
114
|
|
|
* @throws PluginException |
|
115
|
|
|
*/ |
|
116
|
|
|
private function init($BaseInfo = null) |
|
117
|
|
|
{ |
|
118
|
|
|
// /** |
|
119
|
|
|
// * Mysql lock in transaction |
|
120
|
|
|
// * |
|
121
|
|
|
// * @see https://dev.mysql.com/doc/refman/5.7/en/lock-tables.html |
|
122
|
|
|
// * |
|
123
|
|
|
// * @var EntityManagerInterface |
|
124
|
|
|
// */ |
|
125
|
|
|
// $em = $this->entityManager; |
|
126
|
|
|
// if ($em->getConnection()->isTransactionActive()) { |
|
127
|
|
|
// $em->getConnection()->commit(); |
|
128
|
|
|
// $em->getConnection()->beginTransaction(); |
|
129
|
|
|
// } |
|
130
|
|
|
|
|
131
|
|
|
$BaseInfo = $BaseInfo ?: $this->baseInfoRepository->get(); |
|
132
|
|
|
$this->composerApiService->configureRepository($BaseInfo); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
public function execConfig($key, $value = null) |
|
136
|
|
|
{ |
|
137
|
|
|
return $this->composerApiService->execConfig($key, $value); |
|
138
|
|
|
} |
|
139
|
|
|
|
|
140
|
|
|
public function configureRepository(BaseInfo $BaseInfo) |
|
141
|
|
|
{ |
|
142
|
|
|
return $this->composerApiService->configureRepository($BaseInfo); |
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
public function foreachRequires($packageName, $version, $callback, $typeFilter = null, $level = 0) |
|
146
|
|
|
{ |
|
147
|
|
|
return $this->composerApiService->foreachRequires($packageName, $version, $callback, $typeFilter, $level); |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.