refactor: PostRow::update and PostGuard::assertNoMissedSchedule (M5)

- PostRow::update(id, columns, failure) / ::save(): the slashed wp_update_post of
  internal row writes, refusals as RuntimeException '<failure>: <why>'. Used by
  ContentUpdate::restoreRow, PostCloner::updateRow, MediaMetaWriter apply/restore.
- PostGuard::assertNoMissedSchedule(postId, message) replaces the re-read + check in
  ContentUpdate::restoreRow, PostCloner and DiviSaver::restore (DiviSaver keeps its
  own kses window; M4).
- PostCloner::restore uses Rollback::attempt.
Log messages unchanged.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-09-26 17:42:33 +02:00
co-authored by Claude Opus 5.5
parent 8e5ba9eac4
commit 4114bdb805
8 changed files with 140 additions and 49 deletions
+5 -16
View File
@@ -4,8 +4,8 @@ declare(strict_types=1);
namespace LIT\MCP\Integrations\Media;
use LIT\MCP\Integrations\WordPress\PostRow;
use RuntimeException;
use WP_Error;
use WP_Post;
/**
@@ -58,15 +58,11 @@ final class MediaMetaWriter
if ($columns !== []) {
// Set before the call: a throwing save_post hook runs after the row was written.
$touched = true;
$result = wp_update_post(wp_slash(array_merge($columns, ['ID' => $id])), true);
if ($result instanceof WP_Error || ! $result) {
$refusal = PostRow::save($id, $columns);
if ($refusal !== null) {
// wp_update_post() reports errors before it writes anything.
$touched = false;
throw new RuntimeException(sprintf(
'Attachment %d not updated: %s',
$id,
$result instanceof WP_Error ? $result->get_error_message() : 'unknown error'
));
throw new RuntimeException(sprintf('Attachment %d not updated: %s', $id, $refusal));
}
}
@@ -84,14 +80,7 @@ final class MediaMetaWriter
{
$id = $snapshot['id'];
if ($snapshot['columns'] !== []) {
$result = wp_update_post(wp_slash(array_merge($snapshot['columns'], ['ID' => $id])), true);
if ($result instanceof WP_Error || ! $result) {
throw new RuntimeException(sprintf(
'Attachment %d not restored: %s',
$id,
$result instanceof WP_Error ? $result->get_error_message() : 'unknown error'
));
}
PostRow::update($id, $snapshot['columns'], sprintf('Attachment %d not restored', $id));
}
if (! $snapshot['alt_changed']) {