fix: final review minors m-1 to m-8

- m-1: the no-change Divi result carries preview_url/edit_url too
- m-2: overview names replace-text's per-page tree_rev
- m-3: divi-shortform documents validation_failed vs not_found for unknown IDs
- m-4: DiviWriter/DiviPageLoader final (no mocks left), neutral NewDraft
  log detail, snapshots are Etappe 4
- m-5: Tested up to 7.1, changelog completed
- m-6: content-create warns when the extras changed the stored layout
- m-7: deleting a whole section outlines nothing instead of the next one
- m-8: uninstall removes the user meta lit_mcp_log_per_page; readme lists it

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:
2026-09-26 19:35:24 +02:00
co-authored by Claude Opus 5.5
parent b24eb6c3e9
commit 097fef2e32
15 changed files with 136 additions and 21 deletions
@@ -18,10 +18,9 @@ defined('ABSPATH') || exit;
/**
* Loads an entry for the Divi tools: rights and status via PostGuard (spec §4.5), then the
* block tree. Divi 4 shortcode content and unbalanced markup are refused with a hint –
* spec §3.4: Divi 4 content is kept, never edited. Not final so abilities can be tested
* with a mock.
* spec §3.4: Divi 4 content is kept, never edited.
*/
class DiviPageLoader
final class DiviPageLoader
{
public const OUTLINE_HINT = 'Aktuellen Stand mit lit/divi-outline (direkt: lit-divi-outline) neu lesen und die '
. 'Änderung mit der neuen tree_rev wiederholen.';
+7 -5
View File
@@ -23,10 +23,9 @@ defined('ABSPATH') || exit;
* (ruling P16; a mismatch is rev_mismatch and nothing is written), let the ability change the
* tree – only when its whole input validated (all or nothing) –, serialize, save via DiviSaver,
* then lit_mcp_after_save, change log and the ToolResult with changed nodes, affected outline,
* quality warnings (spec §5.5), revision_id, the new rev and tree_rev. Not final so abilities
* can be tested with a mock.
* quality warnings (spec §5.5), revision_id, the new rev and tree_rev.
*/
class DiviWriter
final class DiviWriter
{
public const OUTLINE_TRUNCATED = 'Die Übersicht der geänderten Abschnitte ist gekürzt; vollständig mit '
. 'lit-divi-outline lesen.';
@@ -89,6 +88,7 @@ class DiviWriter
->rev(Rev::ofPost($post))
->with('tree_rev', $page->treeRev())
->warnings($change->warnings())
->urls((string) get_preview_post_link($post), $page->editUrl())
->toArray();
}
@@ -143,7 +143,8 @@ class DiviWriter
/**
* Outline of the sections that contain changed nodes (breadth limit of ruling S18). A removed
* node has no block any more, but its ID from before the removal still names the (surviving)
* section.
* section – unless the removed node was that section itself: its ID now names the next section,
* which did not change (review m-7).
*
* @return array{text: ?string, truncated: bool}
*/
@@ -152,7 +153,8 @@ class DiviWriter
$sections = [];
foreach ($change->entries() as $entry) {
$id = DiviChange::idOf($entry, $index);
if ($id !== null) {
$wholeSection = $entry['block'] === null && $id !== null && ! str_contains($id, '.');
if ($id !== null && ! $wholeSection) {
$sections[explode('.', $id)[0]] = true;
}
}
@@ -34,6 +34,10 @@ defined('ABSPATH') || exit;
*/
final class ContentCreateAbility implements Ability
{
/** The extras (written after the layout) re-saved the entry and changed the stored layout (review m-6). */
public const LAYOUT_CHANGED = 'Der Divi-Inhalt wurde beim Speichern der Felder verändert (z. B. durch ein Plugin); '
. 'tree_rev beschreibt den gespeicherten Stand – vor weiteren Änderungen lit-divi-outline lesen.';
public function __construct(
private ContentSchema $schema,
private PostWriter $writer,
@@ -161,6 +165,7 @@ final class ContentCreateAbility implements Ability
return $draft->refuse($postId, $layout);
}
$stored = is_array($layout) ? self::content($postId) : null;
try {
$this->writer->writeExtras($postId, $postType, $prepared, $input);
} catch (Throwable $e) {
@@ -168,6 +173,9 @@ final class ContentCreateAbility implements Ability
}
$warnings = array_merge($prepared['warnings'], $layout['warnings'] ?? []);
if ($stored !== null && self::content($postId) !== $stored) {
$warnings[] = self::LAYOUT_CHANGED;
}
return $this->result($postId, $postType, $input, $warnings, $layout);
}
@@ -188,6 +196,13 @@ final class ContentCreateAbility implements Ability
return $this->divi?->check($postType, self::sections($input));
}
private static function content(int $postId): ?string
{
$post = get_post($postId);
return $post instanceof WP_Post ? (string) $post->post_content : null;
}
/**
* @param array<string, mixed> $input
* @return list<mixed>
@@ -106,7 +106,7 @@ final class NewDraft
static fn () => self::deleteDraft($postId)
);
$detail = sprintf('Extras of new post %d could not be written: %s', $postId, $cause->getMessage());
$detail = sprintf('Writing new post %d failed after the insert: %s', $postId, $cause->getMessage());
if ($problems === []) {
throw WriteFailed::rolledBack($reason, $cause, $detail);
}