feat: declarative and operation-based menu item editing
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:
@@ -112,24 +112,34 @@ final class Errors
|
||||
|
||||
/**
|
||||
* A write failed and could not be rolled back completely – something may have been saved.
|
||||
* $state and $hint replace the post-oriented defaults for writes that are not about a post
|
||||
* (e.g. menus); $extra is merged into the error details.
|
||||
*
|
||||
* @param array<string, mixed> $extra
|
||||
*/
|
||||
public static function partialWrite(string $reason, ?int $postId = null, ?int $revisionId = null): WP_Error
|
||||
{
|
||||
$state = $postId === null
|
||||
public static function partialWrite(
|
||||
string $reason,
|
||||
?int $postId = null,
|
||||
?int $revisionId = null,
|
||||
?string $state = null,
|
||||
?string $hint = null,
|
||||
array $extra = []
|
||||
): WP_Error {
|
||||
$state ??= $postId === null
|
||||
? 'Möglicherweise wurde trotzdem ein Entwurf angelegt.'
|
||||
: sprintf('Eintrag %d ist möglicherweise teilweise geändert bzw. angelegt worden', $postId)
|
||||
. ($revisionId === null ? '.' : sprintf(' (Stand vorher: Revision %d).', $revisionId));
|
||||
$details = array_filter(
|
||||
$details = array_merge($extra, array_filter(
|
||||
['post_id' => $postId, 'revision_id' => $revisionId],
|
||||
static fn (?int $id): bool => $id !== null
|
||||
);
|
||||
));
|
||||
|
||||
return self::make(
|
||||
'partial_write',
|
||||
trim('Speichern fehlgeschlagen: ' . $reason) . ' Die Änderung konnte nicht vollständig zurückgenommen '
|
||||
. 'werden. ' . $state,
|
||||
'Den Aufruf nicht einfach wiederholen. Zuerst den aktuellen Stand prüfen (lit-content-get, bei einem '
|
||||
. 'neuen Entwurf lit-content-query) und ggf. über lit-revisions-list den vorherigen Stand '
|
||||
$hint ?? 'Den Aufruf nicht einfach wiederholen. Zuerst den aktuellen Stand prüfen (lit-content-get, bei '
|
||||
. 'einem neuen Entwurf lit-content-query) und ggf. über lit-revisions-list den vorherigen Stand '
|
||||
. 'wiederherstellen; dem Nutzer Bescheid geben.',
|
||||
500,
|
||||
$details
|
||||
|
||||
@@ -13,16 +13,22 @@ use WP_Error;
|
||||
* written. getMessage() is the internal detail for the PHP error log; $reason is the
|
||||
* client-safe German text. The AbilityRegistrar logs the detail and returns toError():
|
||||
* lit_write_failed when everything was rolled back, lit_partial_write otherwise.
|
||||
* $state/$hint/$details customise the partial-write error for writes that are not about a
|
||||
* post (see Errors::partialWrite()).
|
||||
*/
|
||||
final class WriteFailed extends RuntimeException
|
||||
{
|
||||
/** @param array<string, mixed> $details Extra error details for an incomplete rollback. */
|
||||
public function __construct(
|
||||
public readonly string $reason,
|
||||
public readonly bool $rolledBack,
|
||||
public readonly ?int $postId = null,
|
||||
public readonly ?int $revisionId = null,
|
||||
?Throwable $previous = null,
|
||||
string $detail = ''
|
||||
string $detail = '',
|
||||
public readonly ?string $state = null,
|
||||
public readonly ?string $hint = null,
|
||||
public readonly array $details = []
|
||||
) {
|
||||
$internal = $detail !== '' ? $detail : ($previous !== null ? $previous->getMessage() : $reason);
|
||||
parent::__construct(
|
||||
@@ -36,6 +42,13 @@ final class WriteFailed extends RuntimeException
|
||||
{
|
||||
return $this->rolledBack
|
||||
? Errors::writeFailed($this->reason)
|
||||
: Errors::partialWrite($this->reason, $this->postId, $this->revisionId);
|
||||
: Errors::partialWrite(
|
||||
$this->reason,
|
||||
$this->postId,
|
||||
$this->revisionId,
|
||||
$this->state,
|
||||
$this->hint,
|
||||
$this->details
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user