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:
@@ -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.';
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ final class Limits
|
||||
return $this->all()['log_retention_days'];
|
||||
}
|
||||
|
||||
/** Reserved for design-system snapshots (Etappe 3); LimitsTab keeps the field hidden until then. */
|
||||
/** Reserved for design-system snapshots (Etappe 4, spec §12); LimitsTab keeps the field hidden until then. */
|
||||
public function snapshotCount(): int
|
||||
{
|
||||
return $this->all()['snapshot_count'];
|
||||
|
||||
+9
-2
@@ -9,14 +9,15 @@ defined('ABSPATH') || exit;
|
||||
/**
|
||||
* Removes WP-LIT-MCP's own data (uninstall.php, Task 12): options, the endpoint-check
|
||||
* transient, the log-cleanup cron hook and the change log table – on every site of a
|
||||
* network.
|
||||
* network – and the Protokoll tab's per-user screen option.
|
||||
*
|
||||
* Deliberately self-contained (no reference to any other LIT\MCP\* class): uninstall.php
|
||||
* is executed by WordPress core standalone, without loading the plugin's main file first,
|
||||
* so the Composer/Jetpack autoloader is not guaranteed to have run. The option/hook/table
|
||||
* names below are therefore duplicated from Access::OPTION, Abilities\ExposurePolicy::OPTION,
|
||||
* Limits::OPTION, ChangeLog\ChangeLogInstaller::VERSION_OPTION, Admin\ConnectionStatus::
|
||||
* ENDPOINT_TRANSIENT, ChangeLog\ChangeLogCleanup::HOOK and ChangeLog\ChangeLog::TABLE on
|
||||
* ENDPOINT_TRANSIENT, ChangeLog\ChangeLogCleanup::HOOK, ChangeLog\ChangeLog::TABLE and
|
||||
* Admin\LogTab::PER_PAGE_OPTION on
|
||||
* purpose; tests/Unit/UninstallerTest.php and tests/Unit/UninstallTest.php keep them in
|
||||
* sync with those constants.
|
||||
*
|
||||
@@ -32,8 +33,14 @@ final class Uninstaller
|
||||
private const CRON_HOOK = 'lit_mcp_log_cleanup';
|
||||
private const TABLE = 'lit_mcp_log';
|
||||
|
||||
/** Screen option "Einträge pro Seite" of the Protokoll tab (Admin\LogTab::PER_PAGE_OPTION): user meta. */
|
||||
private const USER_META = 'lit_mcp_log_per_page';
|
||||
|
||||
public static function run(): void
|
||||
{
|
||||
// User meta is shared by every site of a network: removed once, for all users.
|
||||
delete_metadata('user', 0, self::USER_META, '', true);
|
||||
|
||||
if (! is_multisite()) {
|
||||
self::removeSiteData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user