feat: deferred 1a items - menu_rev lock, lit_mcp_guides filter, warnings, schedule guard precision

Task 14 (rulings P17/P18, Q10):
- lit/menu-get returns menu_rev (Rev::ofMenu over id, parent, position,
  title, url, object, object_id); lit/menu-set-items requires it, refuses
  a stale one with rev_mismatch (hint: lit/menu-get) and returns the new
  menu_rev. Errors::revMismatch takes an optional message/hint.
- GuideRepository: filter lit_mcp_guides adds/overrides topics; invalid
  topic names and non-string content are ignored, files stay the default.
- lit/post-trash names front page, posts page and linking menus in the
  confirmation and as warnings; lit/menu-assign-location needs confirm
  to remove an assigned menu and names it; lit/post-schedule warns that
  a private entry becomes public; Divi hints no longer point to
  non-existing lit-divi-* tools.
- PostGuard::missedSchedule: 60 s publish window, zero GMT date falls
  back to get_gmt_from_date(post_date); post-schedule refuses dates
  within that window.
- write_failed after a clean rollback that keeps a revision/backup says
  "Die Aenderung wurde nicht gespeichert (... bleibt erhalten)" via the
  new state parameter (Errors::writeFailed / WriteFailed rolledBackState).
- wp-basis-smoke: menu_rev flow, unassign confirm, trash/menu and
  private-schedule warnings.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
2026-09-26 04:33:15 +02:00
co-authored by Claude Opus 5.5
parent 7035448f7d
commit 251934ce53
32 changed files with 700 additions and 98 deletions
+24 -7
View File
@@ -56,13 +56,14 @@ final class Errors
return self::make('not_found', $message, $hint, 404);
}
public static function revMismatch(): WP_Error
/** $message/$hint replace the post-oriented defaults (e.g. for the menu lock menu_rev). */
public static function revMismatch(?string $message = null, ?string $hint = null): WP_Error
{
return self::make(
'rev_mismatch',
'Der Inhalt wurde seit dem letzten Lesen geändert; nichts wurde geschrieben.',
'Neu lesen (z. B. lit/content-get, direkt: lit-content-get) und die Änderung auf dem aktuellen Stand '
. 'wiederholen.',
$message ?? 'Der Inhalt wurde seit dem letzten Lesen geändert; nichts wurde geschrieben.',
$hint ?? 'Neu lesen (z. B. lit/content-get, direkt: lit-content-get) und die Änderung auf dem aktuellen '
. 'Stand wiederholen.',
409
);
}
@@ -105,12 +106,18 @@ final class Errors
*
* @param array<string, mixed> $details Extra error details (e.g. a backup that stays).
* @param string|null $hint Replaces the default hint (e.g. "re-read before retrying").
* @param string|null $state Replaces "Nichts wurde gespeichert." when the rollback left
* something behind on purpose (a backup or revision).
*/
public static function writeFailed(string $reason, array $details = [], ?string $hint = null): WP_Error
{
public static function writeFailed(
string $reason,
array $details = [],
?string $hint = null,
?string $state = null
): WP_Error {
return self::make(
'write_failed',
trim('Speichern fehlgeschlagen: ' . $reason) . ' Nichts wurde gespeichert.',
trim('Speichern fehlgeschlagen: ' . $reason) . ' ' . ($state ?? 'Nichts wurde gespeichert.'),
$hint ?? 'Eingaben prüfen, ggf. korrigieren und erneut versuchen; tritt der Fehler wieder auf, den '
. 'Administrator informieren (Details im PHP-Error-Log der Website).',
500,
@@ -118,6 +125,16 @@ final class Errors
);
}
/**
* The $state for writeFailed() when a clean rollback deliberately keeps something, e.g.
* "Revision 811" or "Sicherung 88": the change itself is not saved, but "Nichts wurde
* gespeichert" would be untrue.
*/
public static function notSavedKeeping(string $kept): string
{
return sprintf('Die Änderung wurde nicht gespeichert (%s bleibt erhalten).', $kept);
}
/**
* A write failed and could not be rolled back completely – something may have been saved.
* $state and $hint replace the post-oriented defaults for writes that are not about a post
+26
View File
@@ -33,6 +33,32 @@ final class Rev
]));
}
/**
* Rev of a menu ("menu_rev", optimistic lock of lit/menu-set-items): covers, per item in
* menu order, exactly what lit/menu-set-items compares and writes – id, parent, position,
* title, url and linked object. Other item data (classes, target, …) is never rewritten
* by the tool and therefore not part of the lock.
*
* @param list<object> $items wp_get_nav_menu_items() result.
*/
public static function ofMenu(array $items): string
{
$rows = [];
foreach ($items as $item) {
$rows[] = implode("\0", [
(string) (int) ($item->ID ?? 0),
(string) (int) ($item->menu_item_parent ?? 0),
(string) (int) ($item->menu_order ?? 0),
(string) ($item->title ?? ''),
(string) ($item->url ?? ''),
(string) ($item->object ?? ''),
(string) (int) ($item->object_id ?? 0),
]);
}
return self::of('menu' . "\1" . implode("\1", $rows));
}
/**
* Whether $input carries the current rev of $post (optimistic lock of the post tools).
*
+5 -3
View File
@@ -15,7 +15,8 @@ use WP_Error;
* lit_write_failed when everything was rolled back, lit_partial_write otherwise.
* $state/$hint customise the partial-write error for writes that are not about a post (see
* Errors::partialWrite()); $details are added to either error. $rolledBackHint replaces the
* default hint of the write_failed error.
* default hint of the write_failed error, $rolledBackState its "Nichts wurde gespeichert."
* (for rollbacks that deliberately keep a backup or revision).
*/
final class WriteFailed extends RuntimeException
{
@@ -30,7 +31,8 @@ final class WriteFailed extends RuntimeException
public readonly ?string $state = null,
public readonly ?string $hint = null,
public readonly array $details = [],
public readonly ?string $rolledBackHint = null
public readonly ?string $rolledBackHint = null,
public readonly ?string $rolledBackState = null
) {
$internal = $detail !== '' ? $detail : ($previous !== null ? $previous->getMessage() : $reason);
parent::__construct(
@@ -43,7 +45,7 @@ final class WriteFailed extends RuntimeException
public function toError(): WP_Error
{
return $this->rolledBack
? Errors::writeFailed($this->reason, $this->details, $this->rolledBackHint)
? Errors::writeFailed($this->reason, $this->details, $this->rolledBackHint, $this->rolledBackState)
: Errors::partialWrite(
$this->reason,
$this->postId,