fix: guard revision-restore follow-ups, mark divi revisions
RevisionRestoreAbility now wraps the after-save action and change-log write in FollowUp::run() and reports failures as warnings instead of letting them turn a saved restore into an error response, matching ContentUpdateAbility; a failed wp_restore_post_revision() is now Errors::writeFailed() (nothing was changed) instead of unsupported(). RevisionsListAbility marks each item divi (reusing PostPresenter::usesDivi()/DIVI_HINT) since a Divi/block revision's excerpt is stripped markup, not prose. 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:
@@ -6,6 +6,7 @@ namespace LIT\MCP\Integrations\WordPress\Revisions;
|
||||
|
||||
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\ChangeLog\ChangeLog;
|
||||
@@ -113,25 +114,36 @@ final class RevisionRestoreAbility implements Ability
|
||||
$backupId = RevisionPoint::capture($postId);
|
||||
$restored = wp_restore_post_revision((int) $revision->ID);
|
||||
if (! $restored) {
|
||||
return Errors::unsupported(
|
||||
'WordPress konnte die Revision nicht wiederherstellen.',
|
||||
'Revision in WordPress unter „Revisionen“ prüfen.'
|
||||
);
|
||||
return Errors::writeFailed('WordPress konnte die Revision nicht wiederherstellen.');
|
||||
}
|
||||
|
||||
do_action('lit_mcp_after_save', $postId, $this->name(), $input);
|
||||
// The restore is saved – failures from here on are logged and reported as warnings only.
|
||||
$warnings = [];
|
||||
FollowUp::run(
|
||||
fn () => do_action('lit_mcp_after_save', $postId, $this->name(), $input),
|
||||
$this->name() . ' lit_mcp_after_save',
|
||||
'Eine Erweiterung ist nach dem Wiederherstellen auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$updated = get_post($postId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $post;
|
||||
$summary = sprintf('"%s" auf Stand vom %s zurückgesetzt', $updated->post_title, $revision->post_date);
|
||||
$postType = (string) $post->post_type;
|
||||
$logId = $this->log->record($this->name(), $postType, (string) $postId, $summary, $backupId);
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), $postType, (string) $postId, $summary, $backupId),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
return ToolResult::ok($summary . sprintf(' (Status unverändert: %s).', $updated->post_status))
|
||||
->changed((string) $postId, $postType, 'restored', (string) $updated->post_title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->revisionId($backupId)
|
||||
->logId($logId)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($updated), (string) get_edit_post_link($postId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace LIT\MCP\Integrations\WordPress\Revisions;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Cursor;
|
||||
use LIT\MCP\Integrations\WordPress\Content\PostPresenter;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use WP_Error;
|
||||
@@ -13,7 +14,12 @@ use WP_Post;
|
||||
|
||||
/**
|
||||
* lit/revisions-list: revisions of an entry, newest first. Autosaves are included
|
||||
* (marked autosave: true) rather than filtered out, so the client can decide.
|
||||
* (marked autosave: true) rather than filtered out, so the client can decide. Each
|
||||
* item is marked divi (reusing PostPresenter::usesDivi() on the revision's own row,
|
||||
* the same detection lit/content-get uses) because a Divi/block-built revision's
|
||||
* post_content is shortcode or block-comment markup, not prose – excerpt is then a
|
||||
* stripped fragment of that markup rather than a real preview; hints repeats
|
||||
* PostPresenter::DIVI_HINT once when any item is flagged.
|
||||
*/
|
||||
final class RevisionsListAbility implements Ability
|
||||
{
|
||||
@@ -34,7 +40,8 @@ final class RevisionsListAbility implements Ability
|
||||
public function description(): string
|
||||
{
|
||||
return 'Listet die gespeicherten Revisionen eines Eintrags (neueste zuerst) mit Datum, Autor und '
|
||||
. 'Textauszug. Wiederherstellen mit lit-revision-restore.';
|
||||
. 'Textauszug. Revisionen von Divi-Inhalten sind mit divi: true markiert; ihr excerpt ist dann '
|
||||
. 'Shortcode-/Block-Markup, kein lesbarer Text. Wiederherstellen mit lit-revision-restore.';
|
||||
}
|
||||
|
||||
public function inputSchema(): array
|
||||
@@ -67,13 +74,15 @@ final class RevisionsListAbility implements Ability
|
||||
'title' => ['type' => 'string'],
|
||||
'autosave' => ['type' => 'boolean'],
|
||||
'excerpt' => ['type' => 'string'],
|
||||
'divi' => ['type' => 'boolean'],
|
||||
],
|
||||
'required' => ['id', 'date', 'author', 'title', 'autosave', 'excerpt'],
|
||||
'required' => ['id', 'date', 'author', 'title', 'autosave', 'excerpt', 'divi'],
|
||||
],
|
||||
],
|
||||
'next_cursor' => ['type' => ['string', 'null']],
|
||||
'hints' => ['type' => 'array', 'items' => ['type' => 'string']],
|
||||
],
|
||||
'required' => ['post_id', 'items', 'next_cursor'],
|
||||
'required' => ['post_id', 'items', 'next_cursor', 'hints'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -109,11 +118,13 @@ final class RevisionsListAbility implements Ability
|
||||
$limit = Cursor::limit($input['limit'] ?? null);
|
||||
$revisions = wp_get_post_revisions((int) $post->ID, ['posts_per_page' => $limit + 1, 'offset' => $offset]);
|
||||
$page = Cursor::page(array_values(is_array($revisions) ? $revisions : []), $limit, $offset);
|
||||
$items = array_map(fn (WP_Post $revision): array => $this->item($revision), $page['items']);
|
||||
|
||||
return [
|
||||
'post_id' => (int) $post->ID,
|
||||
'items' => array_map(fn (WP_Post $revision): array => $this->item($revision), $page['items']),
|
||||
'items' => $items,
|
||||
'next_cursor' => $page['next_cursor'],
|
||||
'hints' => in_array(true, array_column($items, 'divi'), true) ? [PostPresenter::DIVI_HINT] : [],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -132,6 +143,7 @@ final class RevisionsListAbility implements Ability
|
||||
'title' => (string) $revision->post_title,
|
||||
'autosave' => (bool) wp_is_post_autosave($revision),
|
||||
'excerpt' => mb_substr($text, 0, 160),
|
||||
'divi' => PostPresenter::usesDivi($revision),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user