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\Result; |
8
|
|
|
use League\CLImate\CLImate; |
9
|
|
|
use Package; |
10
|
|
|
|
11
|
|
|
class LegacyDriver implements Driver |
12
|
|
|
{ |
13
|
|
|
|
14
|
|
|
/** @var \Buttress\Concrete\Client\Connection\Connection */ |
15
|
|
|
private $connection; |
16
|
|
|
|
17
|
|
|
/** @var \Buttress\Concrete\Service\Package\PackageItemFactory */ |
18
|
|
|
private $factory; |
19
|
|
|
|
20
|
|
|
public function __construct(Connection $connection, PackageItemFactory $factory) |
21
|
|
|
{ |
22
|
|
|
$this->connection = $connection; |
23
|
|
|
$this->factory = $factory; |
|
|
|
|
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @param \Buttress\Concrete\Service\Package\PackageItem $package |
28
|
|
|
* @return Package|null |
29
|
|
|
*/ |
30
|
|
|
private function getPackage(PackageItem $package) |
31
|
|
|
{ |
32
|
|
|
$package = Loader::package($package->getHandle()); |
33
|
|
|
return is_object($package) ? $package : null; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Install a package |
38
|
|
|
* |
39
|
|
|
* @param \Buttress\Concrete\Service\Package\PackageItem $item |
40
|
|
|
* @return \Buttress\Concrete\Service\Result |
41
|
|
|
*/ |
42
|
|
|
public function install(PackageItem $item) |
43
|
|
|
{ |
44
|
|
|
if (!$this->connection->isConnected()) { |
45
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
if (!$package = $this->getPackage($item)) { |
49
|
|
|
return new Result(false, 'Invalid package handle.'); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
if ($package->showInstallOptionsScreen()) { |
53
|
|
|
return new Result(false, 'Install options are not currently supported. Please install through the dashboard.'); |
|
|
|
|
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
$tests = $this->test($package); |
57
|
|
|
if (!$tests->success()) { |
58
|
|
|
return $tests; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
try { |
62
|
|
|
$package->install([]); |
63
|
|
|
} catch (Exception $e) { |
|
|
|
|
64
|
|
|
return new Result(false, [$e->getMessage()]); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
return new Result(); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Uninstall a package |
72
|
|
|
* |
73
|
|
|
* @param PackageItem $item |
74
|
|
|
* @return \Buttress\Concrete\Service\Result |
75
|
|
|
*/ |
76
|
|
|
public function uninstall(PackageItem $item) |
77
|
|
|
{ |
78
|
|
|
if (!$this->connection->isConnected()) { |
79
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
if (!$package = $this->getPackage($item)) { |
83
|
|
|
return new Result(false, 'Invalid package handle.'); |
|
|
|
|
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
try { |
87
|
|
|
$package->uninstall(); |
88
|
|
|
} catch (\Exception $e) { |
89
|
|
|
return new Result(false, [$e->getMessage()]); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
return new Result(); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
/** |
96
|
|
|
* Test a package for install |
97
|
|
|
* |
98
|
|
|
* @param PackageItem $package |
99
|
|
|
* @return \Buttress\Concrete\Service\Result |
100
|
|
|
*/ |
101
|
|
|
public function test(PackageItem $package) |
102
|
|
|
{ |
103
|
|
|
if (!$this->connection->isConnected()) { |
104
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
$package = $this->getPackage($package); |
108
|
|
|
$errors = []; |
109
|
|
|
|
110
|
|
|
if (is_array($tests = Package::testForInstall($package, false))) { |
111
|
|
|
$errors = Package::mapError($tests); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
return new Result((bool) $errors, $errors); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* Show information about a package |
119
|
|
|
* |
120
|
|
|
* @param PackageItem $package |
121
|
|
|
* @return \Buttress\Concrete\Service\Result |
122
|
|
|
*/ |
123
|
|
View Code Duplication |
public function show(PackageItem $package, CLImate $cli) |
|
|
|
|
124
|
|
|
{ |
125
|
|
|
if (!$this->connection->isConnected()) { |
126
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
$cli->flank($package->getHandle()); |
130
|
|
|
$cli->out($package->isInstalled() ? 'Installed Version ' : 'Not Installed: '); |
131
|
|
|
$cli->bold()->inline($package->getVersion()); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Get a list of package item objects |
136
|
|
|
* @return PackageItem[] |
137
|
|
|
*/ |
138
|
|
|
public function all() |
139
|
|
|
{ |
140
|
|
|
if (!$this->connection->isConnected()) { |
141
|
|
|
return new Result(false, 'Not connected to concrete5 site.'); |
|
|
|
|
142
|
|
|
} |
143
|
|
|
|
144
|
|
|
$packages = Package::getAvailablePackages(false); |
145
|
|
|
|
146
|
|
|
foreach ($packages as $package) { |
147
|
|
|
yield $this->factory->fromLegacy($package); |
148
|
|
|
} |
149
|
|
|
} |
150
|
|
|
} |
151
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..