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:
@@ -13,8 +13,9 @@ use WP_Error;
|
||||
|
||||
/**
|
||||
* lit/menu-assign-location: assigns a menu to a theme location (menu_id 0 removes
|
||||
* the assignment). Idempotent: assigning the same menu again, or removing an
|
||||
* already-empty location, changes nothing but still succeeds.
|
||||
* the assignment – the menu then disappears from the site, so removing an existing
|
||||
* assignment needs confirm: true). Idempotent: assigning the same menu again, or
|
||||
* removing an already-empty location, changes nothing but still succeeds.
|
||||
*/
|
||||
final class MenuAssignLocationAbility implements Ability
|
||||
{
|
||||
@@ -34,7 +35,8 @@ final class MenuAssignLocationAbility implements Ability
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Weist einer Theme-Position (siehe lit/menu-list) ein Menü zu; menu_id 0 entfernt die Zuweisung. '
|
||||
return 'Weist einer Theme-Position (siehe lit/menu-list) ein Menü zu; menu_id 0 entfernt die Zuweisung '
|
||||
. '(das Menü verschwindet dann von der Website; nur nach Rückfrage beim Nutzer mit confirm: true). '
|
||||
. 'Das vorher zugewiesene Menü steht in previous_menu_id.';
|
||||
}
|
||||
|
||||
@@ -45,6 +47,10 @@ final class MenuAssignLocationAbility implements Ability
|
||||
'properties' => [
|
||||
'location' => ['type' => 'string', 'minLength' => 1],
|
||||
'menu_id' => ['type' => 'integer', 'minimum' => 0],
|
||||
'confirm' => [
|
||||
'type' => 'boolean',
|
||||
'description' => 'Nur nötig bei menu_id 0 (Zuweisung entfernen): true nach Bestätigung.',
|
||||
],
|
||||
],
|
||||
'required' => ['location', 'menu_id'],
|
||||
'additionalProperties' => false,
|
||||
@@ -90,12 +96,23 @@ final class MenuAssignLocationAbility implements Ability
|
||||
}
|
||||
|
||||
$previous = MenuLocations::assigned()[$location] ?? 0;
|
||||
$removed = $menuId === 0 && $previous > 0 ? self::menuLabel($previous) : null;
|
||||
if ($removed !== null && ($input['confirm'] ?? false) !== true) {
|
||||
return Errors::confirmRequired(sprintf(
|
||||
'Menü %s von der Position %s entfernen? Es wird dort dann nicht mehr angezeigt.',
|
||||
$removed,
|
||||
$location
|
||||
));
|
||||
}
|
||||
|
||||
MenuLocations::assign($location, $menuId);
|
||||
|
||||
$action = $menuId > 0 ? 'assigned' : 'unassigned';
|
||||
$summary = $menuId > 0
|
||||
? sprintf('Menü %d der Position %s zugewiesen', $menuId, $location)
|
||||
: sprintf('Zuweisung der Position %s entfernt', $location);
|
||||
$summary = match (true) {
|
||||
$menuId > 0 => sprintf('Menü %d der Position %s zugewiesen', $menuId, $location),
|
||||
$removed !== null => sprintf('Menü %s von der Position %s entfernt', $removed, $location),
|
||||
default => sprintf('Zuweisung der Position %s entfernt', $location),
|
||||
};
|
||||
|
||||
// The assignment is saved – a change log failure from here on is logged and reported as a warning only.
|
||||
$warnings = [];
|
||||
@@ -113,4 +130,14 @@ final class MenuAssignLocationAbility implements Ability
|
||||
->with('previous_menu_id', $previous > 0 ? $previous : null)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/** '"Hauptmenü" (ID 3)', or just the ID when the menu itself no longer exists. */
|
||||
private static function menuLabel(int $menuId): string
|
||||
{
|
||||
$menu = wp_get_nav_menu_object($menuId);
|
||||
|
||||
return is_object($menu)
|
||||
? sprintf('"%s" (ID %d)', $menu->name, $menuId)
|
||||
: sprintf('(ID %d)', $menuId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace LIT\MCP\Integrations\WordPress\Menus;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use WP_Error;
|
||||
|
||||
/**
|
||||
@@ -29,7 +30,8 @@ final class MenuGetAbility implements Ability
|
||||
return 'Liefert ein Menü als Baum (id, title, type post/taxonomy/custom, object/object_id, url, '
|
||||
. 'children). object_id und url sind bei post/taxonomy-Einträgen nur informativ (WordPress leitet '
|
||||
. 'sie aus dem verlinkten Objekt ab); nur bei custom-Einträgen ist url maßgeblich. Der Baum kann '
|
||||
. 'bearbeitet an lit/menu-set-items zurückgegeben werden.';
|
||||
. 'bearbeitet an lit/menu-set-items zurückgegeben werden, zusammen mit menu_rev (Stand des Menüs, '
|
||||
. 'damit parallele Änderungen nicht überschrieben werden).';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
@@ -51,8 +53,12 @@ final class MenuGetAbility implements Ability
|
||||
'name' => ['type' => 'string'],
|
||||
'locations' => ['type' => 'array', 'items' => ['type' => 'string']],
|
||||
'items' => ['type' => 'array', 'items' => MenuTree::nodeSchema()],
|
||||
'menu_rev' => [
|
||||
'type' => 'string',
|
||||
'description' => 'Stand des Menüs; Pflicht für lit/menu-set-items.',
|
||||
],
|
||||
],
|
||||
'required' => ['id', 'name', 'locations', 'items'],
|
||||
'required' => ['id', 'name', 'locations', 'items', 'menu_rev'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -82,12 +88,14 @@ final class MenuGetAbility implements Ability
|
||||
}
|
||||
|
||||
$items = wp_get_nav_menu_items($menuId);
|
||||
$items = is_array($items) ? $items : [];
|
||||
|
||||
return [
|
||||
'id' => (int) $menu->term_id,
|
||||
'name' => (string) $menu->name,
|
||||
'locations' => MenuLocations::of((int) $menu->term_id),
|
||||
'items' => MenuTree::build(is_array($items) ? $items : []),
|
||||
'items' => MenuTree::build($items),
|
||||
'menu_rev' => Rev::ofMenu($items),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace LIT\MCP\Integrations\WordPress\Menus;
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\FollowUp;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
@@ -17,7 +18,9 @@ use WP_Error;
|
||||
* as add/move/remove operations. Both run through one path: operations are applied to
|
||||
* the current tree (MenuOperations), the resulting tree is validated as a whole
|
||||
* (MenuWriter::plan) before anything is written, removals need confirm: true, and the
|
||||
* answer always carries previous_items so a mistake can be rebuilt. Write failures
|
||||
* answer always carries previous_items so a mistake can be rebuilt. menu_rev (from
|
||||
* lit/menu-get, Rev::ofMenu) is the optimistic lock: a menu changed since reading is
|
||||
* refused with rev_mismatch before anything is planned or written. Write failures
|
||||
* surface as WriteFailed (lit_write_failed / lit_partial_write) from MenuWriter::apply.
|
||||
*/
|
||||
final class MenuSetItemsAbility implements Ability
|
||||
@@ -41,7 +44,9 @@ final class MenuSetItemsAbility implements Ability
|
||||
|
||||
public function description(): string
|
||||
{
|
||||
return 'Setzt die Einträge eines Menüs. Entweder items = vollständiger Zielbaum oder operations = Liste aus '
|
||||
return 'Setzt die Einträge eines Menüs. menu_rev aus lit/menu-get ist Pflicht, damit parallele Änderungen '
|
||||
. 'nicht überschrieben werden; die Antwort enthält die neue menu_rev. Entweder items = vollständiger '
|
||||
. 'Zielbaum oder operations = Liste aus '
|
||||
. '{op: add, item, parent_id?, position?}, {op: move, id, parent_id?, position?}, {op: remove, id} '
|
||||
. '(Kinder eines entfernten Eintrags rücken an seine Stelle; position 0-basiert, ohne = ans Ende). '
|
||||
. 'Der Baum aus lit/menu-get kann bearbeitet unverändert zurückgegeben werden: bestehende Einträge '
|
||||
@@ -67,6 +72,10 @@ final class MenuSetItemsAbility implements Ability
|
||||
'type' => 'object',
|
||||
'properties' => [
|
||||
'menu_id' => ['type' => 'integer', 'minimum' => 1],
|
||||
'menu_rev' => [
|
||||
'type' => 'string',
|
||||
'description' => 'menu_rev aus lit/menu-get (bzw. aus der letzten Antwort dieses Tools).',
|
||||
],
|
||||
'items' => [
|
||||
'type' => 'array',
|
||||
'items' => ['type' => 'object'],
|
||||
@@ -98,7 +107,7 @@ final class MenuSetItemsAbility implements Ability
|
||||
'description' => 'Nur nötig, wenn Einträge entfernt werden.',
|
||||
],
|
||||
],
|
||||
'required' => ['menu_id'],
|
||||
'required' => ['menu_id', 'menu_rev'],
|
||||
'additionalProperties' => false,
|
||||
];
|
||||
}
|
||||
@@ -107,7 +116,10 @@ final class MenuSetItemsAbility implements Ability
|
||||
{
|
||||
$tree = ['type' => 'array', 'items' => MenuTree::nodeSchema()];
|
||||
|
||||
return ToolResult::schema(['items' => $tree, 'previous_items' => $tree], ['items', 'previous_items']);
|
||||
return ToolResult::schema(
|
||||
['items' => $tree, 'previous_items' => $tree, 'menu_rev' => ['type' => ['string', 'null']]],
|
||||
['items', 'previous_items', 'menu_rev']
|
||||
);
|
||||
}
|
||||
|
||||
public function annotations(): array
|
||||
@@ -143,6 +155,13 @@ final class MenuSetItemsAbility implements Ability
|
||||
}
|
||||
|
||||
$current = $this->currentItems($menuId);
|
||||
if (($input['menu_rev'] ?? null) !== Rev::ofMenu(array_values($current))) {
|
||||
return Errors::revMismatch(
|
||||
'Das Menü wurde seit dem letzten Lesen geändert; nichts wurde geschrieben.',
|
||||
'Mit lit/menu-get neu lesen und die Änderung auf dem aktuellen Stand (neue menu_rev) wiederholen.'
|
||||
);
|
||||
}
|
||||
|
||||
$previous = MenuTree::build(array_values($current));
|
||||
|
||||
$tree = array_key_exists('items', $input)
|
||||
@@ -201,7 +220,7 @@ final class MenuSetItemsAbility implements Ability
|
||||
$warnings
|
||||
) : null;
|
||||
$after = FollowUp::run(
|
||||
fn () => MenuTree::build(array_values($this->currentItems($menuId))),
|
||||
fn () => array_values($this->currentItems($menuId)),
|
||||
$this->name() . ' re-read',
|
||||
'Das Menü ist gespeichert, der neue Stand konnte aber nicht gelesen werden; mit lit/menu-get abrufen.',
|
||||
$warnings
|
||||
@@ -215,8 +234,9 @@ final class MenuSetItemsAbility implements Ability
|
||||
return $result
|
||||
->warnings($warnings)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->with('items', is_array($after) ? $after : [])
|
||||
->with('items', is_array($after) ? MenuTree::build($after) : [])
|
||||
->with('previous_items', $previous)
|
||||
->with('menu_rev', is_array($after) ? Rev::ofMenu($after) : null)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user