*/ private array $warnings; private ?int $logId = null; /** * @param string $saved What is saved, for the warnings, e.g. "die Änderung", "der Entwurf". * @param list $warnings Warnings collected before the write. */ public function __construct( private string $ability, private ChangeLog $log, private int $postId, private string $saved = 'die Änderung', array $warnings = [] ) { $this->warnings = $warnings; } /** * @param array $input * @param string $after The step just done, e.g. "Speichern", "Veröffentlichen". */ public function afterSave(array $input, string $after = 'Speichern'): self { FollowUp::run( fn () => do_action('lit_mcp_after_save', $this->postId, $this->ability, $input), $this->ability . ' lit_mcp_after_save', sprintf( 'Eine Erweiterung ist nach dem %s auf einen Fehler gestoßen; %s ist gespeichert.', $after, $this->saved ), $this->warnings ); return $this; } /** The saved post as stored now; $fallback when it cannot be read. */ public function reread(?WP_Post $fallback = null): ?WP_Post { $post = get_post($this->postId); return $post instanceof WP_Post ? $post : $fallback; } public function log(string $objectType, string $summary, ?int $revisionId = null): self { $logId = FollowUp::run( fn () => $this->log->record($this->ability, $objectType, (string) $this->postId, $summary, $revisionId), $this->ability . ' change log', sprintf('Änderungsprotokoll konnte nicht geschrieben werden; %s ist gespeichert.', $this->saved), $this->warnings ); $this->logId = is_int($logId) ? $logId : null; return $this; } /** Result with the rev of $post, the log id and all warnings; callers add changed, urls, … */ public function result(string $summary, ?WP_Post $post): ToolResult { return ToolResult::ok($summary) ->rev($post instanceof WP_Post ? Rev::ofPost($post) : null) ->logId($this->logId) ->warnings($this->warnings); } }