refactor(compat): Freigabe-Bausteine generisch
ReleaseStore, CheckReportStore, CheckReport, CheckStep und CompatibilityCheck liegen im Kern und arbeiten je Profil (Optionen lit_mcp_<id>_releases|_check_report; Divi behält Namen und Schlüssel divi_version). Divi hängt Katalog-, Format- und Schreibtest über Profile::extraSteps an. Ein roter Prüfbericht für den aktuellen Stand sperrt LockOnFailure-Profile bis zur nächsten grünen Prüfung; Sperrgründe nennen nur Schritt-Labels, Ausnahmen gehen ins Error-Log. Profile bekommt testedVersions, stateKey, extraSteps, manifestCheck und reportVersionKey und wird mit benannten Argumenten gebaut. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
c85131603b
commit
7d6a97a54e
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Compatibility;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/** The result of one admin check (spec §6.3); a release needs a fresh green one. */
|
||||
final class CheckReport
|
||||
{
|
||||
/** @param list<CheckStep> $steps */
|
||||
public function __construct(
|
||||
public readonly string $id,
|
||||
public readonly string $createdAt,
|
||||
public readonly int $userId,
|
||||
public readonly string $version,
|
||||
public readonly string $pluginVersion,
|
||||
public readonly string $stateKey,
|
||||
public readonly array $steps
|
||||
) {
|
||||
}
|
||||
|
||||
public function green(): bool
|
||||
{
|
||||
if ($this->steps === []) {
|
||||
return false;
|
||||
}
|
||||
foreach ($this->steps as $step) {
|
||||
if (! $step->green()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Green and made for exactly this version, plugin version and state (Profile::$stateKey). */
|
||||
public function freshFor(string $version, string $pluginVersion, string $stateKey): bool
|
||||
{
|
||||
return $this->green() && $this->currentFor($version, $pluginVersion, $stateKey);
|
||||
}
|
||||
|
||||
/** Made for exactly this state, green or not. */
|
||||
public function currentFor(string $version, string $pluginVersion, string $stateKey): bool
|
||||
{
|
||||
return $this->version === $version
|
||||
&& $this->pluginVersion === $pluginVersion
|
||||
&& $this->stateKey === $stateKey;
|
||||
}
|
||||
|
||||
public function step(string $key): ?CheckStep
|
||||
{
|
||||
foreach ($this->steps as $step) {
|
||||
if ($step->key === $key) {
|
||||
return $step;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $versionKey Array key of the version; Divi keeps 'divi_version' so stored reports stay as they are.
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(string $versionKey = 'version'): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'created_at' => $this->createdAt,
|
||||
'user_id' => $this->userId,
|
||||
$versionKey => $this->version,
|
||||
'plugin_version' => $this->pluginVersion,
|
||||
'state_key' => $this->stateKey,
|
||||
'steps' => array_map(static fn (CheckStep $step): array => $step->toArray(), $this->steps),
|
||||
];
|
||||
}
|
||||
|
||||
public static function fromArray(mixed $data, string $versionKey = 'version'): ?self
|
||||
{
|
||||
if (! is_array($data)) {
|
||||
return null;
|
||||
}
|
||||
foreach (['id', 'created_at', $versionKey, 'plugin_version', 'state_key'] as $key) {
|
||||
if (! is_string($data[$key] ?? null)) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (! is_int($data['user_id'] ?? null) || ! is_array($data['steps'] ?? null)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$steps = [];
|
||||
foreach ($data['steps'] as $step) {
|
||||
$parsed = CheckStep::fromArray($step);
|
||||
if ($parsed === null) {
|
||||
return null;
|
||||
}
|
||||
$steps[] = $parsed;
|
||||
}
|
||||
|
||||
return new self(
|
||||
$data['id'],
|
||||
$data['created_at'],
|
||||
$data['user_id'],
|
||||
$data[$versionKey],
|
||||
$data['plugin_version'],
|
||||
$data['state_key'],
|
||||
$steps
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user