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:
@@ -306,7 +306,8 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
$detail,
|
||||
null,
|
||||
null,
|
||||
$details
|
||||
$details,
|
||||
rolledBackState: Errors::notSavedKeeping(sprintf('Sicherung %d im Papierkorb', $backupId))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,8 @@ final class PostScheduleAbility implements Ability
|
||||
public function description(): string
|
||||
{
|
||||
return 'Plant die Veröffentlichung eines Eintrags zu einem Zeitpunkt in der Zukunft (Ortszeit der '
|
||||
. 'Website). Ein bereits veröffentlichter Eintrag ist bis dahin offline. Nur auf ausdrücklichen '
|
||||
. 'Wunsch des Nutzers verwenden.';
|
||||
. 'Website). Ein bereits veröffentlichter Eintrag ist bis dahin offline; ein privater Eintrag wird '
|
||||
. 'zum Zeitpunkt öffentlich. Nur auf ausdrücklichen Wunsch des Nutzers verwenden.';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
@@ -99,10 +99,11 @@ final class PostScheduleAbility implements Ability
|
||||
return Errors::invalidInput('Ungültiges Datum.', ['date' => 'Format JJJJ-MM-TT HH:MM erwartet']);
|
||||
}
|
||||
|
||||
if ($date->getTimestamp() <= time()) {
|
||||
// Within PUBLISH_WINDOW WordPress would publish at once instead of scheduling.
|
||||
if ($date->getTimestamp() <= time() + PostGuard::PUBLISH_WINDOW) {
|
||||
return Errors::invalidInput(
|
||||
'Der Zeitpunkt muss in der Zukunft liegen.',
|
||||
['date' => 'liegt nicht in der Zukunft'],
|
||||
'Der Zeitpunkt muss mindestens eine Minute in der Zukunft liegen.',
|
||||
['date' => 'liegt nicht (mindestens eine Minute) in der Zukunft'],
|
||||
'Zum sofortigen Veröffentlichen lit/post-publish (direkt: lit-post-publish) verwenden.'
|
||||
);
|
||||
}
|
||||
@@ -134,7 +135,15 @@ final class PostScheduleAbility implements Ability
|
||||
}
|
||||
|
||||
// The status change is saved – failures from here on are logged and reported as warnings only.
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Planen');
|
||||
$warnings = $post->post_status === 'private'
|
||||
? [sprintf(
|
||||
'Der Eintrag war privat und wird am %s ÖFFENTLICH veröffentlicht; soll er privat bleiben, die Planung '
|
||||
. 'in WordPress zurücknehmen.',
|
||||
$raw
|
||||
)]
|
||||
: [];
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $warnings))
|
||||
->afterSave($input, 'Planen');
|
||||
$title = (string) $post->post_title;
|
||||
$summary = sprintf('"%s" geplant für %s', $title, $raw)
|
||||
. ($post->post_status === 'publish' ? ' (war veröffentlicht und ist bis dahin offline)' : '');
|
||||
|
||||
@@ -16,7 +16,9 @@ use WP_Error;
|
||||
use WP_Post;
|
||||
|
||||
/**
|
||||
* lit/post-trash: moves an entry to the trash – never a permanent delete. When the
|
||||
* lit/post-trash: moves an entry to the trash – never a permanent delete. Trashing the
|
||||
* static front page, the posts page or an entry linked in a menu is allowed but named in
|
||||
* the confirmation question and as a warning in the result. When the
|
||||
* trash itself is disabled (EMPTY_TRASH_DAYS = 0), wp_trash_post() would delete the
|
||||
* entry permanently (wp-includes/post.php: `if ( ! EMPTY_TRASH_DAYS ) return
|
||||
* wp_delete_post( $post_id, true );`), so this tool refuses instead of calling it.
|
||||
@@ -48,7 +50,8 @@ final class PostTrashAbility implements Ability
|
||||
public function description(): string
|
||||
{
|
||||
return 'Legt einen Eintrag in den Papierkorb (nie endgültig löschen; wiederherstellbar in WordPress). '
|
||||
. 'Erst nach Rückfrage beim Nutzer mit confirm: true aufrufen.';
|
||||
. 'Erst nach Rückfrage beim Nutzer mit confirm: true aufrufen. Ist der Eintrag Startseite, '
|
||||
. 'Beitragsseite oder in Menüs verlinkt, nennen Rückfrage und warnings das.';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
@@ -96,7 +99,12 @@ final class PostTrashAbility implements Ability
|
||||
$postId = (int) $post->ID;
|
||||
$title = (string) $post->post_title;
|
||||
if (($input['confirm'] ?? false) !== true) {
|
||||
return Errors::confirmRequired(sprintf('"%s" (ID %d) in den Papierkorb legen?', $title, $postId));
|
||||
$impact = $post->post_status === 'trash' ? [] : $this->impact($post);
|
||||
|
||||
return Errors::confirmRequired(
|
||||
trim(sprintf('"%s" (ID %d) in den Papierkorb legen? %s', $title, $postId, implode(' ', $impact))),
|
||||
$impact === [] ? [] : ['warnings' => $impact]
|
||||
);
|
||||
}
|
||||
|
||||
if ($post->post_status === 'trash') {
|
||||
@@ -113,6 +121,7 @@ final class PostTrashAbility implements Ability
|
||||
);
|
||||
}
|
||||
|
||||
$impact = $this->impact($post);
|
||||
$trashed = StatusWrite::run(
|
||||
static fn () => wp_trash_post($postId),
|
||||
$this->name(),
|
||||
@@ -128,7 +137,7 @@ final class PostTrashAbility implements Ability
|
||||
}
|
||||
|
||||
// The change is saved – a failure of the change log from here on is a warning only.
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $impact))
|
||||
->log((string) $post->post_type, sprintf('"%s" in den Papierkorb gelegt', $title));
|
||||
|
||||
$summary = sprintf('"%s" liegt im Papierkorb und ist dort wiederherstellbar.', $title);
|
||||
@@ -138,6 +147,63 @@ final class PostTrashAbility implements Ability
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
* What visibly breaks when $post is in the trash: the static front page / posts page
|
||||
* setting points to it, or menus link it (WordPress hides such menu items while the
|
||||
* entry is trashed).
|
||||
*
|
||||
* @return list<string>
|
||||
*/
|
||||
private function impact(WP_Post $post): array
|
||||
{
|
||||
$postId = (int) $post->ID;
|
||||
$title = (string) $post->post_title;
|
||||
$impact = [];
|
||||
if (get_option('show_on_front') === 'page') {
|
||||
if ((int) get_option('page_on_front') === $postId) {
|
||||
$impact[] = sprintf(
|
||||
'"%s" ist als Startseite der Website eingestellt; im Papierkorb ist sie für Besucher nicht '
|
||||
. 'mehr erreichbar – unter Einstellungen → Lesen eine andere Startseite wählen.',
|
||||
$title
|
||||
);
|
||||
}
|
||||
|
||||
if ((int) get_option('page_for_posts') === $postId) {
|
||||
$impact[] = sprintf(
|
||||
'"%s" ist als Beitragsseite der Website eingestellt; im Papierkorb ist die Beitragsübersicht '
|
||||
. 'nicht mehr erreichbar – unter Einstellungen → Lesen eine andere Beitragsseite wählen.',
|
||||
$title
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
$menus = $this->linkingMenus($postId);
|
||||
if ($menus !== []) {
|
||||
$impact[] = sprintf(
|
||||
'"%s" ist in %s %s verlinkt; WordPress blendet diese Menüeinträge aus, solange der Eintrag im '
|
||||
. 'Papierkorb liegt.',
|
||||
$title,
|
||||
count($menus) === 1 ? 'dem Menü' : 'den Menüs',
|
||||
implode(', ', array_map(static fn (string $name): string => '"' . $name . '"', $menus))
|
||||
);
|
||||
}
|
||||
|
||||
return $impact;
|
||||
}
|
||||
|
||||
/** @return list<string> Names of the menus with an item linking $postId. */
|
||||
private function linkingMenus(int $postId): array
|
||||
{
|
||||
$items = wp_get_associated_nav_menu_items($postId, 'post_type');
|
||||
if (! is_array($items) || $items === []) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$names = wp_get_object_terms(array_values($items), 'nav_menu', ['fields' => 'names']);
|
||||
|
||||
return is_array($names) ? array_values(array_unique(array_map('strval', $names))) : [];
|
||||
}
|
||||
|
||||
/** @param array<string, mixed> $input */
|
||||
private function load(array $input): WP_Post|WP_Error
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user