refactor: ColorRestorePlanner baut den Diff einmal aus ColorDiff; die Zusammenfassung zählt Entfernungen
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
d092c05311
commit
7608be6558
@@ -11,8 +11,8 @@ defined('ABSPATH') || exit;
|
||||
|
||||
/**
|
||||
* Restores a snapshot of the global colors (ruling V10): the snapshot replaces every stored color
|
||||
* (set_global_colors($data, false), ruling V4) – colors created after the snapshot are removed. ColorDiff knows no
|
||||
* removal, so the planner adds those rows ("removed") itself and warns that pages keep their references.
|
||||
* (set_global_colors($data, false), ruling V4) – colors created after the snapshot are removed. ColorDiff reports them
|
||||
* as "removed" rows (listed last); the planner counts them in the summary and warns that pages keep their references.
|
||||
*/
|
||||
final class ColorRestorePlanner implements RestorePlanner
|
||||
{
|
||||
@@ -48,25 +48,22 @@ final class ColorRestorePlanner implements RestorePlanner
|
||||
{
|
||||
$before = ColorBook::fromDivi($current);
|
||||
$after = ColorBook::fromDivi($snapshot);
|
||||
$kept = array_values(array_filter(
|
||||
ColorDiff::between($before, $after),
|
||||
static fn (array $row): bool => $after->entry($row['id']) !== null
|
||||
));
|
||||
$removed = [];
|
||||
foreach (array_keys(array_diff_key($before->data(), $after->data())) as $id) {
|
||||
$removed[] = ['id' => (string) $id, 'name' => $before->label((string) $id), 'action' => 'removed'];
|
||||
}
|
||||
$diff = ColorDiff::between($before, $after);
|
||||
$removed = array_values(array_filter($diff, static fn (array $row): bool => $row['action'] === 'removed'));
|
||||
$diff = array_merge(
|
||||
array_values(array_filter($diff, static fn (array $row): bool => $row['action'] !== 'removed')),
|
||||
$removed
|
||||
);
|
||||
|
||||
$summary = sprintf('Snapshot %s wiederherstellen – %s', $snapshotId, ColorDiff::summary($kept));
|
||||
$summary = sprintf('Snapshot %s wiederherstellen – %s', $snapshotId, ColorDiff::summary($diff));
|
||||
$warnings = [];
|
||||
if ($removed !== []) {
|
||||
$summary .= sprintf(' Entfernt: %d.', count($removed));
|
||||
$warnings[] = sprintf(
|
||||
self::REMOVED,
|
||||
implode(', ', array_map(static fn (array $row): string => '„' . $row['name'] . '“', $removed))
|
||||
);
|
||||
}
|
||||
|
||||
return new DesignPlan($after->data(), array_merge($kept, $removed), $summary, null, $warnings, true);
|
||||
return new DesignPlan($after->data(), $diff, $summary, null, $warnings, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user