|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Buttress\Concrete\Service\Package\Driver; |
|
4
|
|
|
|
|
5
|
|
|
use Buttress\Concrete\Client\Connection\Connection; |
|
6
|
|
|
use Buttress\Concrete\Service\Package\PackageItem; |
|
7
|
|
|
use Buttress\Concrete\Service\Package\PackageItemFactory; |
|
8
|
|
|
use Buttress\Concrete\Service\Result; |
|
9
|
|
|
use Buttress\Concrete\Exception\RuntimeException; |
|
10
|
|
|
use Concrete\Core\Error\ErrorList\ErrorList; |
|
11
|
|
|
use Concrete\Core\Foundation\ClassLoader; |
|
12
|
|
|
use Concrete\Core\Package\BrokenPackage; |
|
13
|
|
|
use Concrete\Core\Package\Package; |
|
14
|
|
|
use Concrete\Core\Package\PackageService; |
|
15
|
|
|
use Concrete\Core\Support\Facade\Database; |
|
16
|
|
|
use Concrete\Core\Support\Facade\DatabaseORM; |
|
17
|
|
|
use Concrete\Core\Support\Facade\Events; |
|
18
|
|
|
use League\CLImate\CLImate; |
|
19
|
|
|
|
|
20
|
|
|
class ModernDriver implements Driver |
|
21
|
|
|
{ |
|
22
|
|
|
|
|
23
|
|
|
/** @var \Buttress\Concrete\Client\Connection\ModernConnection */ |
|
24
|
|
|
private $connection; |
|
25
|
|
|
|
|
26
|
|
|
/** @var \Buttress\Concrete\Service\Package\PackageItemFactory */ |
|
27
|
|
|
private $factory; |
|
28
|
|
|
|
|
29
|
|
|
public function __construct(Connection $connection, PackageItemFactory $factory) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->connection = $connection; |
|
|
|
|
|
|
32
|
|
|
$this->factory = $factory; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* Get a package object from an Item |
|
37
|
|
|
* @return Package|\Concrete\Core\Entity\Package |
|
38
|
|
|
*/ |
|
39
|
|
|
private function getPackage(PackageItem $item) |
|
40
|
|
|
{ |
|
41
|
|
|
return Package::getClass($item->getHandle()); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
/** |
|
45
|
|
|
* Install a package |
|
46
|
|
|
* |
|
47
|
|
|
* @param PackageItem $item |
|
48
|
|
|
* @return \Buttress\Concrete\Service\Result |
|
49
|
|
|
*/ |
|
50
|
|
|
public function install(PackageItem $item) |
|
51
|
|
|
{ |
|
52
|
|
|
if (!$this->connection->isConnected()) { |
|
53
|
|
|
return new Result(false, 'Not connected to a concrete5 site.'); |
|
|
|
|
|
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
if (!$package = $this->getPackage($item)) { |
|
57
|
|
|
return new Result(false, 'Invalid package handle.'); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
if ($package instanceof BrokenPackage) { |
|
|
|
|
|
|
61
|
|
|
return new Result(false, $package->getInstallErrorMessage()); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
if ($package->showInstallOptionsScreen()) { |
|
65
|
|
|
return new Result(false, |
|
66
|
|
|
'Install options are not currently supported. Please install through the dashboard.'); |
|
|
|
|
|
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
$loader = new ClassLoader(); |
|
70
|
|
|
if (method_exists($loader, 'registerPackageCustomAutoloaders')) { |
|
71
|
|
|
$loader->registerPackageCustomAutoloaders($package); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
if (is_object($tests = $this->testForInstall($package))) { |
|
75
|
|
|
return new Result(false, $tests->getList()); |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
try { |
|
79
|
|
|
$app = $this->connection->getApplication(); |
|
80
|
|
|
|
|
81
|
|
|
if ($app->bound(PackageService::class)) { |
|
82
|
|
|
$result = $app->make(PackageService::class)->install($package, []); |
|
83
|
|
|
} else { |
|
84
|
|
|
$result = $package->install([]); |
|
85
|
|
|
} |
|
86
|
|
|
} catch (\Exception $e) { |
|
87
|
|
|
return new Result(false, $e->getMessage()); |
|
|
|
|
|
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
if ($result instanceof ErrorList) { |
|
|
|
|
|
|
91
|
|
|
return new Result(false, $result->getList()); |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
return new Result(); |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* Uninstall a package |
|
99
|
|
|
* |
|
100
|
|
|
* @param PackageItem $item |
|
101
|
|
|
* @return \Buttress\Concrete\Service\Result |
|
102
|
|
|
*/ |
|
103
|
|
|
public function uninstall(PackageItem $item) |
|
104
|
|
|
{ |
|
105
|
|
|
if (!$this->connection->isConnected()) { |
|
106
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
if (!$package = $this->getPackage($item)) { |
|
110
|
|
|
return new Result(false, 'Invalid Package'); |
|
|
|
|
|
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if ($package instanceof Package) { |
|
|
|
|
|
|
114
|
|
|
return new Result(false, 'That package doesn\'t look installed.'); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$controller = $package->getController(); |
|
118
|
|
|
if (is_object($tests = $controller->testForUninstall())) { |
|
119
|
|
|
return new Result(false, $tests->getList()); |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
$loader = new ClassLoader(); |
|
123
|
|
|
$loader->registerPackageCustomAutoloaders($package); |
|
124
|
|
|
|
|
125
|
|
|
$result = $package->uninstall(); |
|
126
|
|
|
if ($result instanceof ErrorList) { |
|
|
|
|
|
|
127
|
|
|
return new Result(false, $result->getList()); |
|
128
|
|
|
} |
|
129
|
|
|
|
|
130
|
|
|
return new Result; |
|
131
|
|
|
} |
|
132
|
|
|
|
|
133
|
|
|
/** |
|
134
|
|
|
* Test a package for install |
|
135
|
|
|
* |
|
136
|
|
|
* @param PackageItem $item |
|
137
|
|
|
* @return \Buttress\Concrete\Service\Result |
|
138
|
|
|
*/ |
|
139
|
|
|
public function test(PackageItem $item) |
|
140
|
|
|
{ |
|
141
|
|
|
if (!$this->connection->isConnected()) { |
|
142
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
|
|
143
|
|
|
} |
|
144
|
|
|
|
|
145
|
|
|
if (!$package = $this->getPackage($item)) { |
|
146
|
|
|
return new Result(false, 'Invalid Package'); |
|
|
|
|
|
|
147
|
|
|
} |
|
148
|
|
|
|
|
149
|
|
|
return $package->getController()->testForInstall(); |
|
150
|
|
|
} |
|
151
|
|
|
|
|
152
|
|
|
/** |
|
153
|
|
|
* Show information about a package |
|
154
|
|
|
* |
|
155
|
|
|
* @param PackageItem $package |
|
156
|
|
|
* @param \League\CLImate\CLImate $cli |
|
157
|
|
|
* @return \Buttress\Concrete\Service\Result |
|
158
|
|
|
*/ |
|
159
|
|
View Code Duplication |
public function show(PackageItem $package, CLImate $cli) |
|
|
|
|
|
|
160
|
|
|
{ |
|
161
|
|
|
if (!$this->connection->isConnected()) { |
|
162
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
|
|
163
|
|
|
} |
|
164
|
|
|
|
|
165
|
|
|
$cli->flank($package->getHandle()); |
|
166
|
|
|
$cli->out($package->isInstalled() ? 'Installed Version ' : 'Not Installed: '); |
|
167
|
|
|
$cli->bold()->inline($package->getVersion()); |
|
168
|
|
|
} |
|
169
|
|
|
|
|
170
|
|
|
/** |
|
171
|
|
|
* Get a list of package item objects |
|
172
|
|
|
* @return PackageItem[] |
|
173
|
|
|
*/ |
|
174
|
|
|
public function all() |
|
175
|
|
|
{ |
|
176
|
|
|
if (!$this->connection->isConnected()) { |
|
177
|
|
|
throw new RuntimeException('Not connected to concrete5 site.'); |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
$installed = Package::getInstalledList(); |
|
181
|
|
|
foreach ($installed as $item) { |
|
182
|
|
|
yield $this->factory->fromModern($item); |
|
183
|
|
|
} |
|
184
|
|
|
|
|
185
|
|
|
$notInstalled = Package::getAvailablePackages(); |
|
186
|
|
|
foreach ($notInstalled as $item) { |
|
187
|
|
|
yield $this->factory->fromModern($item); |
|
188
|
|
|
} |
|
189
|
|
|
} |
|
190
|
|
|
|
|
191
|
|
|
private function testForInstall($package) |
|
192
|
|
|
{ |
|
193
|
|
|
$method = new \ReflectionMethod($package, 'testForInstall'); |
|
194
|
|
|
if ($method->isStatic()) { |
|
195
|
|
|
return \Package::testForInstall($package->getPackageHandle(), true); |
|
196
|
|
|
} else { |
|
197
|
|
|
return $package->testForInstall(true); |
|
198
|
|
|
} |
|
199
|
|
|
} |
|
200
|
|
|
} |
|
201
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.