refactor: WriteFailed named constructors, Rollback runner, Errors read-back helpers (H6)
- WriteFailed::rolledBack()/partial() replace the 11-parameter constructor (now private); the hint/state of either error are plain $hint/$state. - Rollback::attempt(...steps) runs every undo step and collects failure messages; used by ContentCreate::discard, ContentUpdate::rollBack, MediaUpdate::rollBack and DiviSaver::restore. - Errors::clientMessage/codeOf/fieldsOf replace DiviReplaceTextAbility::reason, the JSON digging in MediaUpdateAbility::failure and ContentCreateAbility::fields. - Errors docblock documents the exception/WP_Error split. - ContentCreateAbility::discard takes the client reason as a parameter (both callers still pass REASON_EXTRAS; changing the Divi text needs a ruling). Error payloads unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -186,7 +186,7 @@ final class DiviReplaceTextAbility implements Ability
|
||||
$divi = $this->loader->load($postId, true);
|
||||
$problem = $divi instanceof WP_Error ? $divi : $this->loader->writable($divi);
|
||||
if ($problem instanceof WP_Error) {
|
||||
$skipped[] = ['post_id' => $postId, 'reason' => self::reason($problem)];
|
||||
$skipped[] = ['post_id' => $postId, 'reason' => Errors::clientMessage($problem)];
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ final class DiviReplaceTextAbility implements Ability
|
||||
} catch (WriteFailed $e) {
|
||||
self::log($postId, $e);
|
||||
|
||||
return ['post_id' => $postId, 'ok' => false, 'error' => self::reason($e->toError())];
|
||||
return ['post_id' => $postId, 'ok' => false, 'error' => Errors::clientMessage($e->toError())];
|
||||
} catch (Throwable $e) {
|
||||
self::log($postId, $e);
|
||||
|
||||
@@ -343,7 +343,7 @@ final class DiviReplaceTextAbility implements Ability
|
||||
$postId = $input['post_id'];
|
||||
$page = $this->writer->page($input);
|
||||
if ($page instanceof WP_Error) {
|
||||
return ['post_id' => $postId, 'ok' => false, 'error' => self::reason($page)];
|
||||
return ['post_id' => $postId, 'ok' => false, 'error' => Errors::clientMessage($page)];
|
||||
}
|
||||
|
||||
$post = $page->post;
|
||||
@@ -475,14 +475,6 @@ final class DiviReplaceTextAbility implements Ability
|
||||
: 'Knoten nicht lesbar (Attribute kein JSON-Objekt) – im Divi-Builder bearbeiten';
|
||||
}
|
||||
|
||||
/** The client message of an error (its JSON "message"), without the JSON around it. */
|
||||
private static function reason(WP_Error $error): string
|
||||
{
|
||||
$data = json_decode($error->get_error_message(), true);
|
||||
|
||||
return is_array($data) && is_string($data['message'] ?? null) ? $data['message'] : $error->get_error_message();
|
||||
}
|
||||
|
||||
private static function log(int $postId, Throwable $e): void
|
||||
{
|
||||
Log::failure(sprintf('lit/divi-replace-text on post %d', $postId), $e);
|
||||
|
||||
@@ -6,6 +6,7 @@ namespace LIT\MCP\Integrations\Divi\Pages;
|
||||
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\FollowUp;
|
||||
use LIT\MCP\Abilities\Rollback;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\Integrations\WordPress\PostGuard;
|
||||
use LIT\MCP\Integrations\WordPress\RevisionPoint;
|
||||
@@ -78,14 +79,12 @@ class DiviSaver
|
||||
|
||||
if ($result instanceof WP_Error || $result === 0) {
|
||||
$message = $result instanceof WP_Error ? $result->get_error_message() : 'returned 0';
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
self::REASON,
|
||||
true,
|
||||
$postId,
|
||||
$revisionId,
|
||||
null,
|
||||
sprintf('wp_update_post(%d) refused: %s', $postId, $message),
|
||||
rolledBackState: self::keeping($revisionId)
|
||||
detail: sprintf('wp_update_post(%d) refused: %s', $postId, $message),
|
||||
state: self::keeping($revisionId),
|
||||
postId: $postId,
|
||||
revisionId: $revisionId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -172,7 +171,7 @@ class DiviSaver
|
||||
private function restore(int $postId, string $before, ?int $revisionId, Throwable $cause): never
|
||||
{
|
||||
$detail = sprintf('Saving Divi content of post %d failed: %s', $postId, $cause->getMessage());
|
||||
try {
|
||||
$failures = Rollback::attempt(function () use ($postId, $before): void {
|
||||
$current = get_post($postId);
|
||||
if ($current instanceof WP_Post && PostGuard::missedSchedule($current)) {
|
||||
throw new RuntimeException('restoring would publish a missed schedule');
|
||||
@@ -185,19 +184,19 @@ class DiviSaver
|
||||
if ($restored instanceof WP_Error || $restored === 0) {
|
||||
throw new RuntimeException('previous content could not be written back');
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$detail .= '; rollback: ' . $e->getMessage();
|
||||
throw new WriteFailed(self::REASON, false, $postId, $revisionId, $cause, $detail);
|
||||
});
|
||||
if ($failures !== []) {
|
||||
$detail .= '; rollback: ' . $failures[0];
|
||||
throw WriteFailed::partial(self::REASON, $cause, $detail, $postId, $revisionId);
|
||||
}
|
||||
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
self::REASON,
|
||||
true,
|
||||
$postId,
|
||||
$revisionId,
|
||||
$cause,
|
||||
$detail,
|
||||
rolledBackState: self::keeping($revisionId)
|
||||
state: self::keeping($revisionId),
|
||||
postId: $postId,
|
||||
revisionId: $revisionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -261,20 +261,17 @@ class MediaImporter
|
||||
}
|
||||
|
||||
if ($deleted) {
|
||||
throw new WriteFailed($reason, true, null, null, null, $detail);
|
||||
throw WriteFailed::rolledBack($reason, detail: $detail);
|
||||
}
|
||||
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
$reason,
|
||||
false,
|
||||
$attachmentId,
|
||||
null,
|
||||
null,
|
||||
$detail . '; attachment could not be deleted',
|
||||
sprintf('Medium %d wurde trotzdem angelegt, aber ohne Alt-Text.', $attachmentId),
|
||||
'Den Aufruf nicht wiederholen (sonst liegt die Datei doppelt vor). Medium mit lit/media-get prüfen, den '
|
||||
. 'Alt-Text in der Mediathek nachtragen und dem Nutzer Bescheid geben.',
|
||||
['attachment_id' => $attachmentId]
|
||||
detail: $detail . '; attachment could not be deleted',
|
||||
postId: $attachmentId,
|
||||
state: sprintf('Medium %d wurde trotzdem angelegt, aber ohne Alt-Text.', $attachmentId),
|
||||
hint: 'Den Aufruf nicht wiederholen (sonst liegt die Datei doppelt vor). Medium mit lit/media-get prüfen, '
|
||||
. 'den Alt-Text in der Mediathek nachtragen und dem Nutzer Bescheid geben.',
|
||||
details: ['attachment_id' => $attachmentId]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace LIT\MCP\Integrations\Media;
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\FollowUp;
|
||||
use LIT\MCP\Abilities\Rollback;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
@@ -266,24 +267,20 @@ final class MediaUpdateAbility implements Ability
|
||||
$unrestored = [];
|
||||
$failures = [];
|
||||
foreach (array_reverse($written) as $entry) {
|
||||
try {
|
||||
$this->writer->restore($entry['snapshot']);
|
||||
} catch (Throwable $e) {
|
||||
$failed = Rollback::attempt(fn () => $this->writer->restore($entry['snapshot']));
|
||||
if ($failed !== []) {
|
||||
$unrestored[] = $entry['attachment'];
|
||||
$failures[] = $e->getMessage();
|
||||
$failures = array_merge($failures, $failed);
|
||||
}
|
||||
}
|
||||
|
||||
$detail = 'Media update failed: ' . $cause->getMessage();
|
||||
if ($unrestored === []) {
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
self::REASON,
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
$cause,
|
||||
$detail,
|
||||
rolledBackHint: 'Das Zurücksetzen hat modified der Medien geändert: vor einem neuen Versuch die Medien '
|
||||
hint: 'Das Zurücksetzen hat modified der Medien geändert: vor einem neuen Versuch die Medien '
|
||||
. 'neu lesen (lit/media-get oder lit/media-search, direkt: lit-media-search) und den Stapel mit '
|
||||
. 'dem aktuellen modified senden; tritt der Fehler wieder auf, den Administrator informieren '
|
||||
. '(Details im PHP-Error-Log).'
|
||||
@@ -301,17 +298,14 @@ final class MediaUpdateAbility implements Ability
|
||||
);
|
||||
}
|
||||
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
self::REASON,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
$cause,
|
||||
$detail . '; rollback incomplete: ' . implode('; ', $failures),
|
||||
sprintf('Möglicherweise geändert: Medien %s (siehe changed_ids).', implode(', ', $ids)),
|
||||
'Den Aufruf nicht einfach wiederholen. Die unter changed_ids genannten Medien mit lit/media-get prüfen, '
|
||||
. 'die Metadaten ggf. korrigieren und dem Nutzer Bescheid geben.',
|
||||
['changed_ids' => $ids]
|
||||
state: sprintf('Möglicherweise geändert: Medien %s (siehe changed_ids).', implode(', ', $ids)),
|
||||
hint: 'Den Aufruf nicht einfach wiederholen. Die unter changed_ids genannten Medien mit lit/media-get '
|
||||
. 'prüfen, die Metadaten ggf. korrigieren und dem Nutzer Bescheid geben.',
|
||||
details: ['changed_ids' => $ids]
|
||||
);
|
||||
}
|
||||
|
||||
@@ -374,12 +368,11 @@ final class MediaUpdateAbility implements Ability
|
||||
*/
|
||||
private static function failure(int $index, array $item, WP_Error $error): array
|
||||
{
|
||||
$payload = json_decode($error->get_error_message(), true);
|
||||
return [
|
||||
'index' => $index,
|
||||
'id' => PostGuard::id($item['id'] ?? null),
|
||||
'code' => (string) preg_replace('/^lit_/', '', (string) $error->get_error_code()),
|
||||
'error' => is_array($payload) ? (string) ($payload['message'] ?? '') : $error->get_error_message(),
|
||||
'code' => Errors::codeOf($error),
|
||||
'error' => Errors::clientMessage($error),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -7,12 +7,14 @@ namespace LIT\MCP\Integrations\WordPress\Content;
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\Rollback;
|
||||
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 RuntimeException;
|
||||
use Throwable;
|
||||
use WP_Error;
|
||||
use WP_Post;
|
||||
@@ -137,7 +139,7 @@ final class ContentCreateAbility implements Ability
|
||||
// A hook threw – the row may or may not exist and its ID is unknown; nothing is
|
||||
// searched or deleted, the client is told to check (lit_partial_write without id).
|
||||
$this->logPartial($postType, '', 'Anlegen abgebrochen; Entwurf möglicherweise vorhanden');
|
||||
throw new WriteFailed(self::REASON_INSERT, false, null, null, $e);
|
||||
throw WriteFailed::partial(self::REASON_INSERT, $e);
|
||||
}
|
||||
if ($postId instanceof WP_Error) {
|
||||
return Errors::invalidInput('WordPress hat den Eintrag abgelehnt: ' . $postId->get_error_message());
|
||||
@@ -153,7 +155,7 @@ final class ContentCreateAbility implements Ability
|
||||
try {
|
||||
$layout = $withDivi ? $this->divi?->write($postId, $postType, self::sections($input)) : null;
|
||||
} catch (Throwable $e) {
|
||||
$this->discard($postId, $postType, $e);
|
||||
$this->discard($postId, $postType, $e, self::REASON_EXTRAS);
|
||||
}
|
||||
if ($layout instanceof WP_Error) {
|
||||
return $this->refuse($postId, $postType, $layout);
|
||||
@@ -162,7 +164,7 @@ final class ContentCreateAbility implements Ability
|
||||
try {
|
||||
$this->writer->writeExtras($postId, $postType, $prepared, $input);
|
||||
} catch (Throwable $e) {
|
||||
$this->discard($postId, $postType, $e);
|
||||
$this->discard($postId, $postType, $e, self::REASON_EXTRAS);
|
||||
}
|
||||
|
||||
$warnings = array_merge($prepared['warnings'], $layout['warnings'] ?? []);
|
||||
@@ -207,7 +209,7 @@ final class ContentCreateAbility implements Ability
|
||||
return $prepared instanceof WP_Error ? $prepared : $divi;
|
||||
}
|
||||
|
||||
$fields = array_merge(self::fields($prepared), self::fields($divi));
|
||||
$fields = array_merge(Errors::fieldsOf($prepared), Errors::fieldsOf($divi));
|
||||
if ($fields === []) {
|
||||
return $prepared;
|
||||
}
|
||||
@@ -217,14 +219,6 @@ final class ContentCreateAbility implements Ability
|
||||
: Errors::invalidInput('Eingaben sind ungültig; nichts wurde angelegt.', $fields);
|
||||
}
|
||||
|
||||
/** @return array<string, string> */
|
||||
private static function fields(WP_Error $error): array
|
||||
{
|
||||
$data = $error->get_error_data();
|
||||
|
||||
return is_array($data) && is_array($data['fields'] ?? null) ? $data['fields'] : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $input
|
||||
* @param list<string> $warnings
|
||||
@@ -254,42 +248,38 @@ final class ContentCreateAbility implements Ability
|
||||
|
||||
/**
|
||||
* Rolls the brand-new draft back: terms it created, then the draft itself (force –
|
||||
* it cannot have been used anywhere yet).
|
||||
* it cannot have been used anywhere yet). $reason is the client text of the error.
|
||||
*
|
||||
* @throws WriteFailed Always.
|
||||
*/
|
||||
private function discard(int $postId, string $postType, Throwable $cause): never
|
||||
private function discard(int $postId, string $postType, Throwable $cause, string $reason): never
|
||||
{
|
||||
$problems = [];
|
||||
try {
|
||||
$this->writer->deleteCreatedTerms();
|
||||
} catch (Throwable $e) {
|
||||
$problems[] = $e->getMessage();
|
||||
}
|
||||
|
||||
try {
|
||||
if (! wp_delete_post($postId, true)) {
|
||||
$problems[] = sprintf('draft %d could not be deleted', $postId);
|
||||
$problems = Rollback::attempt(
|
||||
fn () => $this->writer->deleteCreatedTerms(),
|
||||
static function () use ($postId): void {
|
||||
try {
|
||||
$deleted = wp_delete_post($postId, true);
|
||||
} catch (Throwable $e) {
|
||||
throw new RuntimeException(
|
||||
sprintf('draft %d could not be deleted: %s', $postId, $e->getMessage()),
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
if (! $deleted) {
|
||||
throw new RuntimeException(sprintf('draft %d could not be deleted', $postId));
|
||||
}
|
||||
}
|
||||
} catch (Throwable $e) {
|
||||
$problems[] = sprintf('draft %d could not be deleted: %s', $postId, $e->getMessage());
|
||||
}
|
||||
);
|
||||
|
||||
$detail = sprintf('Extras of new post %d could not be written: %s', $postId, $cause->getMessage());
|
||||
if ($problems === []) {
|
||||
throw new WriteFailed(self::REASON_EXTRAS, true, null, null, $cause, $detail);
|
||||
throw WriteFailed::rolledBack($reason, $cause, $detail);
|
||||
}
|
||||
|
||||
$summary = sprintf('Entwurf %d: Anlegen nur teilweise zurückgenommen', $postId);
|
||||
$this->logPartial($postType, (string) $postId, $summary);
|
||||
throw new WriteFailed(
|
||||
self::REASON_EXTRAS,
|
||||
false,
|
||||
$postId,
|
||||
null,
|
||||
$cause,
|
||||
$detail . '; rollback: ' . implode('; ', $problems)
|
||||
);
|
||||
throw WriteFailed::partial($reason, $cause, $detail . '; rollback: ' . implode('; ', $problems), $postId);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -311,15 +301,12 @@ final class ContentCreateAbility implements Ability
|
||||
if (! $deleted) {
|
||||
$summary = sprintf('Entwurf %d: Anlegen nicht zurückgenommen', $postId);
|
||||
$this->logPartial($postType, (string) $postId, $summary);
|
||||
$fields = $denied instanceof WP_Error ? self::fields($denied) : $denied;
|
||||
throw new WriteFailed(
|
||||
$fields = $denied instanceof WP_Error ? Errors::fieldsOf($denied) : $denied;
|
||||
throw WriteFailed::partial(
|
||||
($denied instanceof WP_Error ? 'Ungültiger Divi-Inhalt: ' : 'Keine Berechtigung für ')
|
||||
. implode(', ', array_keys($fields)) . '.',
|
||||
false,
|
||||
$postId,
|
||||
null,
|
||||
null,
|
||||
sprintf('New post %d refused after the insert; draft could not be deleted', $postId)
|
||||
detail: sprintf('New post %d refused after the insert; draft could not be deleted', $postId),
|
||||
postId: $postId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ namespace LIT\MCP\Integrations\WordPress\Content;
|
||||
use LIT\MCP\Abilities\Ability;
|
||||
use LIT\MCP\Abilities\Errors;
|
||||
use LIT\MCP\Abilities\Rev;
|
||||
use LIT\MCP\Abilities\Rollback;
|
||||
use LIT\MCP\Abilities\ToolResult;
|
||||
use LIT\MCP\Abilities\WriteFailed;
|
||||
use LIT\MCP\ChangeLog\ChangeLog;
|
||||
@@ -218,32 +219,21 @@ final class ContentUpdateAbility implements Ability
|
||||
private function rollBack(WP_Post $post, array $before, ?int $revisionId, array $snapshot, Throwable $cause): never
|
||||
{
|
||||
$postId = (int) $post->ID;
|
||||
$steps = [
|
||||
$failures = Rollback::attempt(
|
||||
fn () => $this->writer->deleteCreatedTerms(),
|
||||
fn () => $this->writer->restore($postId, (string) $post->post_type, $snapshot),
|
||||
fn () => $this->restoreRow($post, $before, $revisionId),
|
||||
];
|
||||
$failures = [];
|
||||
foreach ($steps as $step) {
|
||||
try {
|
||||
$step();
|
||||
} catch (Throwable $e) {
|
||||
$failures[] = $e->getMessage();
|
||||
}
|
||||
}
|
||||
fn () => $this->restoreRow($post, $before, $revisionId)
|
||||
);
|
||||
|
||||
$detail = sprintf('Update of post %d failed: %s', $postId, $cause->getMessage());
|
||||
if ($failures === []) {
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
self::REASON,
|
||||
true,
|
||||
$postId,
|
||||
$revisionId,
|
||||
$cause,
|
||||
$detail,
|
||||
rolledBackState: $revisionId === null
|
||||
? null
|
||||
: Errors::notSavedKeeping(sprintf('Revision %d', $revisionId))
|
||||
state: $revisionId === null ? null : Errors::notSavedKeeping(sprintf('Revision %d', $revisionId)),
|
||||
postId: $postId,
|
||||
revisionId: $revisionId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -254,13 +244,12 @@ final class ContentUpdateAbility implements Ability
|
||||
sprintf('"%s": Änderung nur teilweise zurückgenommen', $post->post_title),
|
||||
$revisionId
|
||||
);
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
self::REASON,
|
||||
false,
|
||||
$postId,
|
||||
$revisionId,
|
||||
$cause,
|
||||
$detail . '; rollback incomplete: ' . implode('; ', $failures)
|
||||
$detail . '; rollback incomplete: ' . implode('; ', $failures),
|
||||
$postId,
|
||||
$revisionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -454,19 +454,22 @@ class MenuWriter
|
||||
. ($this->deleted !== [] ? '; already deleted: ' . implode(', ', $this->deleted) : '')
|
||||
. ($problems !== [] ? '; rollback: ' . implode('; ', $problems) : '');
|
||||
|
||||
throw new WriteFailed(
|
||||
'Das Menü konnte nicht gespeichert werden.',
|
||||
$rolledBack,
|
||||
null,
|
||||
null,
|
||||
$reason = 'Das Menü konnte nicht gespeichert werden.';
|
||||
$details = ['menu_id' => $menuId, 'previous_items' => MenuTree::build(array_values($current))];
|
||||
if ($rolledBack) {
|
||||
throw WriteFailed::rolledBack($reason, $cause, $detail, details: $details);
|
||||
}
|
||||
|
||||
throw WriteFailed::partial(
|
||||
$reason,
|
||||
$cause,
|
||||
$detail,
|
||||
sprintf('Menü %d ist möglicherweise teilweise geändert worden.', $menuId),
|
||||
'Den Aufruf nicht einfach wiederholen. Zuerst den aktuellen Stand mit lit/menu-get prüfen und ihn ggf. '
|
||||
. 'mit lit/menu-set-items (beide über mcp-adapter-execute-ability) anhand von previous_items (Stand '
|
||||
. 'vorher) wiederherstellen; entfernte Einträge müssen dabei neu angelegt werden. Dem Nutzer Bescheid '
|
||||
. 'geben.',
|
||||
['menu_id' => $menuId, 'previous_items' => MenuTree::build(array_values($current))]
|
||||
state: sprintf('Menü %d ist möglicherweise teilweise geändert worden.', $menuId),
|
||||
hint: 'Den Aufruf nicht einfach wiederholen. Zuerst den aktuellen Stand mit lit/menu-get prüfen und ihn '
|
||||
. 'ggf. mit lit/menu-set-items (beide über mcp-adapter-execute-ability) anhand von previous_items '
|
||||
. '(Stand vorher) wiederherstellen; entfernte Einträge müssen dabei neu angelegt werden. Dem Nutzer '
|
||||
. 'Bescheid geben.',
|
||||
details: $details
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -238,7 +238,7 @@ final class WpSettingsUpdateAbility implements Ability
|
||||
|
||||
$reason = 'Eine Einstellung konnte nicht gespeichert werden.';
|
||||
if ($stuck === []) {
|
||||
throw new WriteFailed($reason, true, null, null, $cause);
|
||||
throw WriteFailed::rolledBack($reason, $cause);
|
||||
}
|
||||
|
||||
$this->log->recordPartial(
|
||||
@@ -247,17 +247,14 @@ final class WpSettingsUpdateAbility implements Ability
|
||||
implode(',', $stuck),
|
||||
'Einstellungen nur teilweise zurückgenommen: ' . implode(', ', $stuck)
|
||||
);
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
$reason,
|
||||
false,
|
||||
null,
|
||||
null,
|
||||
$cause,
|
||||
$cause->getMessage() . '; not restored: ' . implode(', ', $stuck),
|
||||
sprintf('Möglicherweise auf dem neuen, nicht vollständigen Stand: %s.', implode(', ', $stuck)),
|
||||
'Aktuelle Werte über lit/wp-settings-get (mcp-adapter-execute-ability) prüfen und ggf. erneut auf die '
|
||||
. 'gewünschten Werte setzen.',
|
||||
['keys' => $stuck]
|
||||
state: sprintf('Möglicherweise auf dem neuen, nicht vollständigen Stand: %s.', implode(', ', $stuck)),
|
||||
hint: 'Aktuelle Werte über lit/wp-settings-get (mcp-adapter-execute-ability) prüfen und ggf. erneut auf '
|
||||
. 'die gewünschten Werte setzen.',
|
||||
details: ['keys' => $stuck]
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -182,13 +182,9 @@ class PostCloner
|
||||
|
||||
if ($cloneId instanceof WP_Error || (int) $cloneId === 0) {
|
||||
$reason = $cloneId instanceof WP_Error ? $cloneId->get_error_message() : 'unknown error';
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
$label . ' konnte nicht angelegt werden.',
|
||||
true,
|
||||
null,
|
||||
null,
|
||||
null,
|
||||
sprintf('Clone (%s) of post %d could not be created: %s', $markerKey, $originalId, $reason)
|
||||
detail: sprintf('Clone (%s) of post %d could not be created: %s', $markerKey, $originalId, $reason)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -216,10 +212,10 @@ class PostCloner
|
||||
$deleted = wp_delete_post($cloneId, true);
|
||||
$detail = sprintf('Clone %d of post %d failed: %s', $cloneId, (int) $original->ID, $cause->getMessage());
|
||||
if ($deleted) {
|
||||
throw new WriteFailed($reason, true, null, null, $cause, $detail . '; clone deleted');
|
||||
throw WriteFailed::rolledBack($reason, $cause, $detail . '; clone deleted');
|
||||
}
|
||||
|
||||
throw new WriteFailed($reason, false, $cloneId, null, $cause, $detail . '; clone could not be deleted');
|
||||
throw WriteFailed::partial($reason, $cause, $detail . '; clone could not be deleted', $cloneId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -126,7 +126,7 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
try {
|
||||
$snapshot = $this->cloner->snapshot($original);
|
||||
} catch (Throwable $e) {
|
||||
throw new WriteFailed(self::REASON, true, $originalId, null, $e);
|
||||
throw WriteFailed::rolledBack(self::REASON, $e, postId: $originalId);
|
||||
}
|
||||
|
||||
// Throws WriteFailed (backup deleted again) before anything touches the original.
|
||||
@@ -275,13 +275,12 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
sprintf('"%s": Austausch nur teilweise zurückgenommen', $original->post_title),
|
||||
$revisionId
|
||||
);
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
self::REASON,
|
||||
false,
|
||||
$originalId,
|
||||
$revisionId,
|
||||
$cause,
|
||||
$detail . '; rollback incomplete: ' . $e->getMessage(),
|
||||
$originalId,
|
||||
$revisionId,
|
||||
sprintf(
|
||||
'Eintrag %d ist möglicherweise teilweise geändert worden (Stand vorher: Revision %s); die '
|
||||
. 'vollständige Sicherung des vorherigen Stands liegt als Eintrag %d im Papierkorb.',
|
||||
@@ -297,17 +296,14 @@ final class PostReplaceWithCopyAbility implements Ability
|
||||
);
|
||||
}
|
||||
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::rolledBack(
|
||||
self::REASON,
|
||||
true,
|
||||
$originalId,
|
||||
$revisionId,
|
||||
$cause,
|
||||
$detail,
|
||||
null,
|
||||
null,
|
||||
$details,
|
||||
rolledBackState: Errors::notSavedKeeping(sprintf('Sicherung %d im Papierkorb', $backupId))
|
||||
state: Errors::notSavedKeeping(sprintf('Sicherung %d im Papierkorb', $backupId)),
|
||||
details: $details,
|
||||
postId: $originalId,
|
||||
revisionId: $revisionId
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -33,16 +33,13 @@ final class StatusWrite
|
||||
sprintf('"%s": Statusänderung abgebrochen, Stand unklar', $post->post_title)
|
||||
);
|
||||
|
||||
throw new WriteFailed(
|
||||
throw WriteFailed::partial(
|
||||
$reason,
|
||||
false,
|
||||
$postId,
|
||||
null,
|
||||
$e,
|
||||
'',
|
||||
sprintf('Status von Eintrag %d ist möglicherweise schon geändert worden.', $postId),
|
||||
'Den Aufruf nicht einfach wiederholen. Zuerst mit lit/content-get (direkt: lit-content-get) Status '
|
||||
. 'und Inhalt prüfen und dem Nutzer Bescheid geben.'
|
||||
postId: $postId,
|
||||
state: sprintf('Status von Eintrag %d ist möglicherweise schon geändert worden.', $postId),
|
||||
hint: 'Den Aufruf nicht einfach wiederholen. Zuerst mit lit/content-get (direkt: lit-content-get) '
|
||||
. 'Status und Inhalt prüfen und dem Nutzer Bescheid geben.'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user