Skip to content

Commit e460ed6

Browse files
committed
Add compatibility: blueprint support and preflight handling for 1.7→1.8 upgrades
Enables the 1.7 SelfupgradeCommand to handle preflight reports from the 1.8 package's Install.php. When upgrading from 1.7 to 1.8, the command now: - Calls generatePreflightReport() on the new package's installer - Shows incompatible plugins with disable/continue/abort choices - Handles pending updates, PSR/log and Monolog conflicts interactively - Disables plugins via direct YAML config write (no RecoveryManager on 1.7) Also adds: - GPM Local/Package: computed compatibility property from blueprints - CLI badges: IndexCommand, InfoCommand, UpdateCommand show 1.7/1.8 badges
1 parent 2025a5f commit e460ed6

5 files changed

Lines changed: 389 additions & 3 deletions

File tree

system/src/Grav/Common/GPM/Local/Package.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ public function __construct(Data $package, $package_type = null)
3939
$this->data->set('description_html', $html_description);
4040
$this->data->set('description_plain', strip_tags($html_description));
4141
$this->data->set('symlink', is_link(USER_DIR . $package_type . DS . $this->__get('slug')));
42+
$this->data->set('compatibility', $this->resolveCompatibility($data));
4243
}
4344

4445
/**
@@ -48,4 +49,52 @@ public function isEnabled()
4849
{
4950
return (bool)$this->settings['enabled'];
5051
}
52+
53+
/**
54+
* Resolve the compatibility metadata for this package.
55+
*
56+
* @param Data $data Blueprint data
57+
* @return array{grav: string[], api: string[]}
58+
*/
59+
protected function resolveCompatibility(Data $data): array
60+
{
61+
$raw = $data->get('compatibility');
62+
63+
if (is_array($raw) && isset($raw['grav']) && is_array($raw['grav'])) {
64+
return [
65+
'grav' => array_map('strval', $raw['grav']),
66+
'api' => isset($raw['api']) && is_array($raw['api']) ? array_map('strval', $raw['api']) : [],
67+
];
68+
}
69+
70+
return $this->inferCompatibility($data->get('dependencies') ?? []);
71+
}
72+
73+
/**
74+
* Infer Grav compatibility from the dependencies array.
75+
*
76+
* @param array $dependencies
77+
* @return array{grav: string[], api: string[]}
78+
*/
79+
protected function inferCompatibility(array $dependencies): array
80+
{
81+
foreach ($dependencies as $dep) {
82+
if (!is_array($dep) || ($dep['name'] ?? '') !== 'grav') {
83+
continue;
84+
}
85+
$version = $dep['version'] ?? '';
86+
87+
if (!preg_match('/(\d+\.\d+(?:\.\d+)?)/', $version, $m)) {
88+
continue;
89+
}
90+
91+
if (version_compare($m[1], '1.8', '>=')) {
92+
return ['grav' => ['1.8'], 'api' => []];
93+
}
94+
95+
return ['grav' => ['1.7'], 'api' => []];
96+
}
97+
98+
return ['grav' => ['1.7'], 'api' => []];
99+
}
51100
}

system/src/Grav/Console/Gpm/IndexCommand.php

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ protected function serve(): int
141141
if (!empty($packages)) {
142142
$io->section('Packages table');
143143
$table = new Table($io);
144-
$table->setHeaders(['Count', 'Name', 'Slug', 'Version', 'Installed', 'Enabled']);
144+
$table->setHeaders(['Count', 'Name', 'Slug', 'Version', 'Compat', 'Installed', 'Enabled']);
145145

146146
$index = 0;
147147
foreach ($packages as $slug => $package) {
@@ -150,6 +150,7 @@ protected function serve(): int
150150
'Name' => '<cyan>' . Utils::truncate($package->name, 20, false, ' ', '...') . '</cyan> ',
151151
'Slug' => $slug,
152152
'Version'=> $this->version($package),
153+
'Compat' => $this->compatBadges($package),
153154
'Installed' => $this->installed($package),
154155
'Enabled' => $this->enabled($package),
155156
];
@@ -231,6 +232,38 @@ private function enabled(Package $package): string
231232
return $result;
232233
}
233234

235+
/**
236+
* @param Package $package
237+
* @return string
238+
*/
239+
private function compatBadges(Package $package): string
240+
{
241+
$type = ucfirst(preg_replace('/s$/', '', $package->package_type));
242+
$method = 'is' . $type . 'Installed';
243+
$installed = $this->gpm->{$method}($package->slug);
244+
245+
if ($installed) {
246+
$local = $this->gpm->{'getInstalled' . $type}($package->slug);
247+
$compat = $local->compatibility ?? null;
248+
} else {
249+
$compat = $package->compatibility ?? null;
250+
}
251+
252+
if (!is_array($compat) || empty($compat['grav'])) {
253+
return '<blue>1.7</blue>';
254+
}
255+
256+
$badges = [];
257+
if (in_array('1.7', $compat['grav'], true)) {
258+
$badges[] = '<blue>1.7</blue>';
259+
}
260+
if (in_array('1.8', $compat['grav'], true)) {
261+
$badges[] = '<green>1.8</green>';
262+
}
263+
264+
return implode(' ', $badges);
265+
}
266+
234267
/**
235268
* @param Packages $data
236269
* @return Packages

system/src/Grav/Console/Gpm/InfoCommand.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,36 @@ protected function serve(): int
131131
}
132132
}
133133

134+
// Display compatibility badges
134135
$type = rtrim($foundPackage->package_type, 's');
135-
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($foundPackage->slug);
136136
$installed = $this->gpm->{'is' . $type . 'Installed'}($foundPackage->slug);
137+
if ($installed) {
138+
$local = $this->gpm->{'getInstalled' . $type}($foundPackage->slug);
139+
$compat = $local->compatibility ?? null;
140+
} else {
141+
$compat = $foundPackage->compatibility ?? null;
142+
}
143+
144+
$compatStr = '';
145+
if (is_array($compat) && !empty($compat['grav'])) {
146+
$badges = [];
147+
if (in_array('1.7', $compat['grav'], true)) {
148+
$badges[] = '<blue>1.7</blue>';
149+
}
150+
if (in_array('1.8', $compat['grav'], true)) {
151+
$badges[] = '<green>1.8</green>';
152+
}
153+
$compatStr = implode(' ', $badges);
154+
} else {
155+
$compatStr = '<blue>1.7</blue>';
156+
}
157+
$io->writeln('<green>' . str_pad('Compatibility', 12) . ':</green> ' . $compatStr);
158+
159+
if (is_array($compat) && !empty($compat['api'])) {
160+
$io->writeln('<green>' . str_pad('API', 12) . ':</green> ' . implode(', ', $compat['api']));
161+
}
162+
163+
$updatable = $this->gpm->{'is' . $type . 'Updatable'}($foundPackage->slug);
137164

138165
// display current version if installed and different
139166
if ($installed && $updatable) {

0 commit comments

Comments
 (0)