refactor: PostChangeResult for the after-save block of the post tools
after_save hook, re-read, change log and ToolResult (rev, log_id, warnings) were repeated in nine post abilities; they now share one helper. Behaviour and warning texts are unchanged. 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:
@@ -8,10 +8,9 @@ use DateTimeImmutable;
|
||||
use DateTimeZone;
|
||||
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;
|
||||
use LIT\MCP\Integrations\WordPress\PostChangeResult;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use WP_Error;
|
||||
@@ -128,33 +127,16 @@ final class PostScheduleAbility implements Ability
|
||||
}
|
||||
|
||||
// The status change 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 Planen auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))->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)' : '');
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), (string) $post->post_type, (string) $postId, $summary),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
$change->log((string) $post->post_type, $summary);
|
||||
$updated = $change->reread($post) ?? $post;
|
||||
|
||||
$updated = get_post($postId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $post;
|
||||
|
||||
return ToolResult::ok($summary . '.')
|
||||
return $change->result($summary . '.', $updated)
|
||||
->changed((string) $postId, (string) $post->post_type, 'scheduled', $title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($updated), (string) get_edit_post_link($postId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user