refactor: lit/divi-design-restore plant über RestorePlanner; PresetRestorePlanner übernimmt den bisherigen Code unverändert
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
62f8465e60
commit
5af188d656
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\Divi\Design;
|
||||
|
||||
use Closure;
|
||||
use LIT\MCP\Integrations\Divi\Release\DiviFeature;
|
||||
use WP_Error;
|
||||
|
||||
defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Restores a snapshot of the presets (Etappe 4a): the snapshot replaces the whole inventory (presets missing in it are
|
||||
* removed); without unfiltered_html it is refused while the snapshot or the current inventory holds HTML/CSS that
|
||||
* Divi would strip (final review I-2).
|
||||
*/
|
||||
final class PresetRestorePlanner implements RestorePlanner
|
||||
{
|
||||
private const MARKUP = 'Der Snapshot oder der aktuelle Bestand enthält Presets mit HTML/CSS, das beim Speichern '
|
||||
. 'ohne das Recht unfiltered_html verloren ginge; nichts wurde gespeichert.';
|
||||
|
||||
/** @param (Closure(): bool)|null $unfiltered Whether the user may save unfiltered HTML (DesignRights). */
|
||||
public function __construct(private DesignSystemWriter $writer, private ?Closure $unfiltered = null)
|
||||
{
|
||||
$this->unfiltered ??= DesignRights::unfilteredHtml();
|
||||
}
|
||||
|
||||
public function area(): string
|
||||
{
|
||||
return 'presets';
|
||||
}
|
||||
|
||||
public function designArea(): DesignArea
|
||||
{
|
||||
return new PresetArea($this->writer);
|
||||
}
|
||||
|
||||
public function rights(): ?WP_Error
|
||||
{
|
||||
return DesignRights::presets($this->writer);
|
||||
}
|
||||
|
||||
/** Writes the presets (PresetWrite), reading them first (DesignRead). */
|
||||
public function features(): array
|
||||
{
|
||||
return [DiviFeature::DesignRead, DiviFeature::PresetWrite];
|
||||
}
|
||||
|
||||
public function plan(array $current, array $snapshot, string $snapshotId): DesignPlan|WP_Error
|
||||
{
|
||||
$before = PresetBook::fromDivi($current);
|
||||
$after = PresetBook::fromDivi($snapshot);
|
||||
$refusal = DesignRights::markup(
|
||||
$this->unfiltered,
|
||||
array_merge($before->markupOutside([]), $after->markupOutside([])),
|
||||
self::MARKUP
|
||||
);
|
||||
if ($refusal !== null) {
|
||||
return $refusal;
|
||||
}
|
||||
$diff = PresetDiff::between($before, $after);
|
||||
|
||||
return new DesignPlan(
|
||||
$after->data(),
|
||||
$diff,
|
||||
sprintf('Snapshot %s wiederherstellen – %s', $snapshotId, PresetDiff::summary($diff)),
|
||||
null,
|
||||
['Seiten, die Presets verwenden, die es im Snapshot nicht gibt, behalten den Verweis; das Modul fällt '
|
||||
. 'dann auf das Standard-Preset zurück.'],
|
||||
true
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user