fix: Standard-Preset löschen – nur ausdrückliche Verweise blockieren, implizite Nutzung im Probelauf

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Jan-Niclas Loosen
2026-10-16 18:10:11 +02:00
co-authored by Claude Opus 5.5
parent 75714429be
commit 3d760113ec
2 changed files with 61 additions and 4 deletions
@@ -17,8 +17,9 @@ defined('ABSPATH') || exit;
/**
* lit/divi-presets-delete (spec §6.4, G5): deletes presets nothing uses any more – no page, library entry or Theme
* Builder layout (GlobalUsages with PresetUsageQuery), and no other preset that nests it. A used preset is refused
* with its usages (in_use); lit/divi-design-detach (Etappe 4b) removes the references first. A default preset loses
* its default. Through the change pipeline with Divi's delete semantics (legacy option cleaned).
* with its usages (in_use); lit/divi-design-detach (Etappe 4b) removes the references first. Only explicit references
* block: a default preset loses its default, and the posts with modules that use it implicitly are listed in the dry
* run (spec §6.4). Through the change pipeline with Divi's delete semantics (legacy option cleaned).
*/
final class DiviPresetsDeleteAbility implements Ability
{
@@ -28,6 +29,8 @@ final class DiviPresetsDeleteAbility implements Ability
. 'Divi-Builder; danach erneut löschen.';
/** @param (Closure(): bool)|null $unfiltered Whether the user may save unfiltered HTML (DesignRights). */
private const DEFAULT_WARNING = 'Module ohne eigenes Preset verwenden danach das Divi-Standardaussehen.';
public function __construct(
private DesignSystemWriter $writer,
private DesignChange $change,
@@ -158,7 +161,9 @@ final class DiviPresetsDeleteAbility implements Ability
}
}
}
$report = $this->usages->reportFor(new PresetUsageQuery($targets), false);
// Spec §6.4: only explicit references block; a default preset's implicit use is listed in the dry run.
$explicit = array_map(static fn (array $target): array => ['default' => false] + $target, $targets);
$report = $this->usages->reportFor(new PresetUsageQuery($explicit), false);
if ($nested !== [] || $report->exists()) {
return Errors::inUse(
'Die Presets werden noch verwendet; nichts wurde gelöscht.',
@@ -173,6 +178,15 @@ final class DiviPresetsDeleteAbility implements Ability
$diff = PresetDiff::between($before, $book);
return new DesignPlan($book->data(), $diff, PresetDiff::summary($diff), null, [], true);
$defaults = array_values(array_filter($targets, static fn (array $target): bool => $target['default']));
return new DesignPlan(
$book->data(),
$diff,
PresetDiff::summary($diff),
$defaults === [] ? null : $this->usages->reportFor(new PresetUsageQuery($defaults)),
$defaults === [] ? [] : [self::DEFAULT_WARNING],
true
);
}
}