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:
@@ -6,11 +6,10 @@ namespace LIT\MCP\Integrations\WordPress\Content;
|
||||
|
||||
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;
|
||||
use LIT\MCP\Integrations\WordPress\PostChangeResult;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
use Throwable;
|
||||
@@ -136,29 +135,15 @@ final class ContentCreateAbility implements Ability
|
||||
private function result(int $postId, string $postType, array $input, array $warnings): array
|
||||
{
|
||||
// The draft is saved – failures from here on are logged and reported as warnings only.
|
||||
FollowUp::run(
|
||||
fn () => do_action('lit_mcp_after_save', $postId, $this->name(), $input),
|
||||
$this->name() . ' lit_mcp_after_save',
|
||||
'Eine Erweiterung ist nach dem Speichern auf einen Fehler gestoßen; der Entwurf ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$post = get_post($postId);
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId, 'der Entwurf', $warnings))
|
||||
->afterSave($input);
|
||||
$post = $change->reread();
|
||||
$title = $post instanceof WP_Post ? (string) $post->post_title : (string) $input['title'];
|
||||
$summary = sprintf('Entwurf "%s" angelegt', $title);
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), $postType, (string) $postId, $summary),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; der Entwurf ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
$change->log($postType, sprintf('Entwurf "%s" angelegt', $title));
|
||||
|
||||
return ToolResult::ok(sprintf('"%s" als Entwurf angelegt (ID %d).', $title, $postId))
|
||||
return $change->result(sprintf('"%s" als Entwurf angelegt (ID %d).', $title, $postId), $post)
|
||||
->changed((string) $postId, $postType, 'created', $title)
|
||||
->rev($post instanceof WP_Post ? Rev::ofPost($post) : null)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($postId), (string) get_edit_post_link($postId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,11 +6,11 @@ namespace LIT\MCP\Integrations\WordPress\Content;
|
||||
|
||||
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;
|
||||
use LIT\MCP\Integrations\WordPress\PostChangeResult;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\RevisionPoint;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
@@ -178,31 +178,17 @@ final class ContentUpdateAbility implements Ability
|
||||
$postType = (string) $post->post_type;
|
||||
|
||||
// The change is saved – failures from here on are logged and reported as warnings only.
|
||||
FollowUp::run(
|
||||
fn () => do_action('lit_mcp_after_save', $postId, $this->name(), $input),
|
||||
$this->name() . ' lit_mcp_after_save',
|
||||
'Eine Erweiterung ist nach dem Speichern auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$updated = get_post($postId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $post;
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $warnings))
|
||||
->afterSave($input);
|
||||
$updated = $change->reread($post) ?? $post;
|
||||
$changedKeys = array_keys(array_intersect_key($input, array_flip(self::CHANGE_KEYS)));
|
||||
$summary = sprintf('"%s" geändert: %s', $updated->post_title, implode(', ', $changedKeys));
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), $postType, (string) $postId, $summary, $revisionId),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
$change->log($postType, $summary, $revisionId);
|
||||
|
||||
return ToolResult::ok(sprintf('%s (Status unverändert: %s).', $summary, $updated->post_status))
|
||||
return $change->result(sprintf('%s (Status unverändert: %s).', $summary, $updated->post_status), $updated)
|
||||
->changed((string) $postId, $postType, 'updated', (string) $updated->post_title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->revisionId($revisionId)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($updated), (string) get_edit_post_link($postId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\Integrations\WordPress;
|
||||
|
||||
use LIT\MCP\Abilities\FollowUp;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
use WP_Post;
|
||||
|
||||
/**
|
||||
* What every post tool does once its write is saved: fire lit_mcp_after_save, re-read the
|
||||
* post, write the change log and build the ToolResult with the new rev. From here on a
|
||||
* failure must not turn the saved change into an error – listener and log failures are
|
||||
* logged and reported as warnings ("… ist gespeichert").
|
||||
*/
|
||||
final class PostChangeResult
|
||||
{
|
||||
/** @var list<string> */
|
||||
private array $warnings;
|
||||
|
||||
private ?int $logId = null;
|
||||
|
||||
/**
|
||||
* @param string $saved What is saved, for the warnings, e.g. "die Änderung", "der Entwurf".
|
||||
* @param list<string> $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<string, mixed> $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);
|
||||
}
|
||||
}
|
||||
@@ -6,10 +6,10 @@ 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;
|
||||
use LIT\MCP\Integrations\WordPress\PostChangeResult;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\RevisionPoint;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
@@ -124,32 +124,16 @@ final class RevisionRestoreAbility implements Ability
|
||||
}
|
||||
|
||||
// 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;
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Wiederherstellen');
|
||||
$updated = $change->reread($post) ?? $post;
|
||||
$summary = sprintf('"%s" auf Stand vom %s zurückgesetzt', $updated->post_title, $revision->post_date);
|
||||
$postType = (string) $post->post_type;
|
||||
$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
|
||||
);
|
||||
$change->log($postType, $summary, $backupId);
|
||||
|
||||
return ToolResult::ok($summary . sprintf(' (Status unverändert: %s).', $updated->post_status))
|
||||
return $change->result($summary . sprintf(' (Status unverändert: %s).', $updated->post_status), $updated)
|
||||
->changed((string) $postId, $postType, 'restored', (string) $updated->post_title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->revisionId($backupId)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($updated), (string) get_edit_post_link($postId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,9 @@ declare(strict_types=1);
|
||||
namespace LIT\MCP\Integrations\WordPress\Status;
|
||||
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
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;
|
||||
@@ -88,31 +87,17 @@ final class PostDuplicateAbility implements Ability
|
||||
$copyId = $this->cloner->duplicate($original);
|
||||
|
||||
// The copy is saved – failures from here on are logged and reported as warnings only.
|
||||
$warnings = [];
|
||||
FollowUp::run(
|
||||
fn () => do_action('lit_mcp_after_save', $copyId, $this->name(), $input),
|
||||
$this->name() . ' lit_mcp_after_save',
|
||||
'Eine Erweiterung ist nach dem Anlegen der Kopie auf einen Fehler gestoßen; die Kopie ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$copy = get_post($copyId);
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $copyId, 'die Kopie'))
|
||||
->afterSave($input, 'Anlegen der Kopie');
|
||||
$copy = $change->reread();
|
||||
$copyTitle = $copy instanceof WP_Post ? (string) $copy->post_title : '';
|
||||
$postType = (string) $original->post_type;
|
||||
$summary = sprintf('Kopie von "%s" (ID %d) angelegt', $original->post_title, $original->ID);
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), $postType, (string) $copyId, $summary),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; die Kopie ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
$change->log($postType, $summary);
|
||||
|
||||
return ToolResult::ok(sprintf('%s: Entwurf ID %d.', $summary, $copyId))
|
||||
return $change->result(sprintf('%s: Entwurf ID %d.', $summary, $copyId), $copy)
|
||||
->changed((string) $copyId, $postType, 'created', $copyTitle)
|
||||
->rev($copy instanceof WP_Post ? Rev::ofPost($copy) : null)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($copyId), (string) get_edit_post_link($copyId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->with('original_id', (int) $original->ID)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace LIT\MCP\Integrations\WordPress\Status;
|
||||
|
||||
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;
|
||||
@@ -114,31 +114,12 @@ final class PostPublishAbility 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 Veröffentlichen auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Veröffentlichen');
|
||||
$change->log((string) $post->post_type, sprintf('"%s" veröffentlicht', $title));
|
||||
|
||||
$summary = sprintf('"%s" veröffentlicht', $title);
|
||||
$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
|
||||
);
|
||||
|
||||
$updated = get_post($postId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $post;
|
||||
|
||||
return ToolResult::ok(sprintf('"%s" ist jetzt veröffentlicht.', $title))
|
||||
return $change->result(sprintf('"%s" ist jetzt veröffentlicht.', $title), $change->reread($post))
|
||||
->changed((string) $postId, (string) $post->post_type, 'published', $title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_permalink($postId), $editUrl)
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
use LIT\MCP\Integrations\WordPress\PostChangeResult;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\RevisionPoint;
|
||||
use LIT\MCP\Integrations\WordPress\Schema\ContentSchema;
|
||||
@@ -221,24 +222,11 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
$warnings[] = $trashWarning;
|
||||
}
|
||||
|
||||
FollowUp::run(
|
||||
fn () => do_action('lit_mcp_after_save', $originalId, $this->name(), $input),
|
||||
$this->name() . ' lit_mcp_after_save',
|
||||
'Eine Erweiterung ist nach dem Speichern auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $originalId, 'die Änderung', $warnings))
|
||||
->afterSave($input);
|
||||
$title = PostCloner::withoutSuffix((string) $copy->post_title);
|
||||
$summary = sprintf('Kopie ID %d in "%s" (ID %d) übernommen', $copyId, $title, $originalId);
|
||||
$logId = FollowUp::run(
|
||||
fn () => $this->log->record($this->name(), $postType, (string) $originalId, $summary, $revisionId),
|
||||
$this->name() . ' change log',
|
||||
'Änderungsprotokoll konnte nicht geschrieben werden; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$updated = get_post($originalId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $original;
|
||||
$change->log($postType, $summary, $revisionId);
|
||||
$statusNote = sprintf(
|
||||
'; Status bleibt %s, %s, der vorherige Stand liegt als Sicherung ID %d im Papierkorb.',
|
||||
$original->post_status,
|
||||
@@ -246,18 +234,15 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
$backupId
|
||||
);
|
||||
|
||||
$result = ToolResult::ok($summary . $statusNote)
|
||||
$result = $change->result($summary . $statusNote, $change->reread($original))
|
||||
->changed((string) $originalId, $postType, 'replaced', $title);
|
||||
if ($trashed) {
|
||||
$result->changed((string) $copyId, $postType, 'trashed', (string) $copy->post_title);
|
||||
}
|
||||
|
||||
return $result
|
||||
->rev(Rev::ofPost($updated))
|
||||
->revisionId($revisionId)
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_permalink($originalId), (string) get_edit_post_link($originalId, 'raw'))
|
||||
->warnings($warnings)
|
||||
->with('backup_id', $backupId)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,10 +6,10 @@ namespace LIT\MCP\Integrations\WordPress\Status;
|
||||
|
||||
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;
|
||||
@@ -121,23 +121,13 @@ final class PostTrashAbility implements Ability
|
||||
}
|
||||
|
||||
// The change is saved – a failure of the change log from here on is a warning only.
|
||||
$summary = sprintf('"%s" in den Papierkorb gelegt', $title);
|
||||
$warnings = [];
|
||||
$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 = (new PostChangeResult($this->name(), $this->log, $postId))
|
||||
->log((string) $post->post_type, sprintf('"%s" in den Papierkorb gelegt', $title));
|
||||
|
||||
$updated = get_post($postId);
|
||||
$updated = $updated instanceof WP_Post ? $updated : $post;
|
||||
$summary = sprintf('"%s" liegt im Papierkorb und ist dort wiederherstellbar.', $title);
|
||||
|
||||
return ToolResult::ok(sprintf('"%s" liegt im Papierkorb und ist dort wiederherstellbar.', $title))
|
||||
return $change->result($summary, $change->reread($post))
|
||||
->changed((string) $postId, (string) $post->post_type, 'trashed', $title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,14 +6,13 @@ namespace LIT\MCP\Integrations\WordPress\Status;
|
||||
|
||||
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;
|
||||
use WP_Post;
|
||||
|
||||
/**
|
||||
* lit/post-unpublish: withdraws a published, scheduled or private entry back to draft.
|
||||
@@ -98,31 +97,14 @@ final class PostUnpublishAbility 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 Zurückziehen auf einen Fehler gestoßen; die Änderung ist gespeichert.',
|
||||
$warnings
|
||||
);
|
||||
|
||||
$change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Zurückziehen');
|
||||
$summary = sprintf('"%s" zurückgezogen (vorher %s, jetzt Entwurf)', $title, $post->post_status);
|
||||
$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, 'unpublished', $title)
|
||||
->rev(Rev::ofPost($updated))
|
||||
->logId(is_int($logId) ? $logId : null)
|
||||
->urls((string) get_preview_post_link($updated), $editUrl)
|
||||
->warnings($warnings)
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user