diff --git a/src/Integrations/Divi/Pages/DiviChange.php b/src/Integrations/Divi/Pages/DiviChange.php index 4348a16..2312dd0 100644 --- a/src/Integrations/Divi/Pages/DiviChange.php +++ b/src/Integrations/Divi/Pages/DiviChange.php @@ -16,7 +16,7 @@ use LIT\MCP\Integrations\Divi\BlockTree\NodeSummary; final class DiviChange { /** @var list */ - private array $changed = []; + private array $entries = []; /** @var list */ private array $touched = []; @@ -32,9 +32,9 @@ final class DiviChange * A node that still exists after the change: "inserted", "updated", "moved" or "duplicated". * Every action but "moved" counts for the quality warnings. */ - public function changed(Block $block, string $action): self + public function record(Block $block, string $action): self { - $this->changed[] = [ + $this->entries[] = [ 'block' => $block, 'id' => null, 'type' => $block->name(), @@ -51,7 +51,7 @@ final class DiviChange /** A node that is gone; $idBefore is its ID before the change. */ public function removed(string $idBefore, Block $block): self { - $this->changed[] = [ + $this->entries[] = [ 'block' => null, 'id' => $idBefore, 'type' => $block->name(), @@ -72,7 +72,7 @@ final class DiviChange /** @return list */ public function entries(): array { - return $this->changed; + return $this->entries; } /** diff --git a/src/Integrations/Divi/Pages/DiviDuplicateNodeAbility.php b/src/Integrations/Divi/Pages/DiviDuplicateNodeAbility.php index ce8c218..47468f7 100644 --- a/src/Integrations/Divi/Pages/DiviDuplicateNodeAbility.php +++ b/src/Integrations/Divi/Pages/DiviDuplicateNodeAbility.php @@ -75,6 +75,6 @@ final class DiviDuplicateNodeAbility extends DiviWriteAbility )); } - return (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->changed($copy, 'duplicated'); + return (new DiviChange(sprintf('Knoten %s dupliziert', $id)))->record($copy, 'duplicated'); } } diff --git a/src/Integrations/Divi/Pages/DiviInsertAbility.php b/src/Integrations/Divi/Pages/DiviInsertAbility.php index 590b2a4..2ed0250 100644 --- a/src/Integrations/Divi/Pages/DiviInsertAbility.php +++ b/src/Integrations/Divi/Pages/DiviInsertAbility.php @@ -91,7 +91,7 @@ final class DiviInsertAbility extends DiviWriteAbility $change = new DiviChange(sprintf('%d Divi-Knoten eingefügt', count($composed['blocks']))); foreach ($composed['blocks'] as $block) { - $change->changed($block, 'inserted'); + $change->record($block, 'inserted'); } return $change; diff --git a/src/Integrations/Divi/Pages/DiviMoveAbility.php b/src/Integrations/Divi/Pages/DiviMoveAbility.php index 283e1e6..9addb9b 100644 --- a/src/Integrations/Divi/Pages/DiviMoveAbility.php +++ b/src/Integrations/Divi/Pages/DiviMoveAbility.php @@ -71,6 +71,6 @@ final class DiviMoveAbility extends DiviWriteAbility ); } - return (new DiviChange(sprintf('Knoten %s verschoben', $id)))->changed($node, 'moved'); + return (new DiviChange(sprintf('Knoten %s verschoben', $id)))->record($node, 'moved'); } } diff --git a/src/Integrations/Divi/Pages/DiviReplaceTextAbility.php b/src/Integrations/Divi/Pages/DiviReplaceTextAbility.php index 02a6c55..114cd41 100644 --- a/src/Integrations/Divi/Pages/DiviReplaceTextAbility.php +++ b/src/Integrations/Divi/Pages/DiviReplaceTextAbility.php @@ -360,7 +360,7 @@ final class DiviReplaceTextAbility implements Ability $change = new DiviChange(sprintf('Text ersetzt (%d Stellen)', $found['count'])); foreach ($found['blocks'] as [$block, $attrs]) { $block->setAttrs($attrs); - $change->changed($block, 'updated'); + $change->record($block, 'updated'); } $saved = $this->writer->save($this->name(), $page, $change, $input); diff --git a/src/Integrations/Divi/Pages/DiviUpdateAbility.php b/src/Integrations/Divi/Pages/DiviUpdateAbility.php index f087750..1bde452 100644 --- a/src/Integrations/Divi/Pages/DiviUpdateAbility.php +++ b/src/Integrations/Divi/Pages/DiviUpdateAbility.php @@ -146,7 +146,7 @@ final class DiviUpdateAbility extends DiviWriteAbility foreach ($updates as [$block, $attrs]) { // Composer::update() output: every client value already passed the choke point. $block->setAttrs($attrs); - $change->changed($block, 'updated'); + $change->record($block, 'updated'); } return $change; diff --git a/src/Integrations/Divi/Pages/DiviWriter.php b/src/Integrations/Divi/Pages/DiviWriter.php index 13db8f7..b642e29 100644 --- a/src/Integrations/Divi/Pages/DiviWriter.php +++ b/src/Integrations/Divi/Pages/DiviWriter.php @@ -13,7 +13,7 @@ use LIT\MCP\Integrations\Divi\BlockTree\NodeIndex; use LIT\MCP\Integrations\Divi\BlockTree\Outline; use LIT\MCP\Integrations\Divi\BlockTree\Serializer; use LIT\MCP\Integrations\Divi\Design\DesignSystemReader; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use WP_Error; /** @@ -114,7 +114,7 @@ class DiviWriter $warnings[] = self::OUTLINE_TRUNCATED; } - $result = (new PostChangeResult( + $result = (new PostSaveFollowUp( $ability, $this->log, (int) $post->ID, diff --git a/src/Integrations/WordPress/Content/ContentCreateAbility.php b/src/Integrations/WordPress/Content/ContentCreateAbility.php index 58e3c3d..ca50a15 100644 --- a/src/Integrations/WordPress/Content/ContentCreateAbility.php +++ b/src/Integrations/WordPress/Content/ContentCreateAbility.php @@ -9,7 +9,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\Rev; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use Throwable; @@ -216,7 +216,7 @@ final class ContentCreateAbility implements Ability private function result(int $postId, string $postType, array $input, array $warnings, ?string $outline): array { // The draft is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $postId, 'der Entwurf', $warnings)) + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId, 'der Entwurf', $warnings)) ->afterSave($input); $post = $change->reread(); $title = $post instanceof WP_Post ? (string) $post->post_title : (string) $input['title']; diff --git a/src/Integrations/WordPress/Content/ContentUpdateAbility.php b/src/Integrations/WordPress/Content/ContentUpdateAbility.php index 8201665..ee1a429 100644 --- a/src/Integrations/WordPress/Content/ContentUpdateAbility.php +++ b/src/Integrations/WordPress/Content/ContentUpdateAbility.php @@ -11,7 +11,7 @@ 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\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\PostRow; use LIT\MCP\Integrations\WordPress\RevisionPoint; @@ -179,7 +179,7 @@ final class ContentUpdateAbility implements Ability $postType = (string) $post->post_type; // The change is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $warnings)) + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId, 'die Änderung', $warnings)) ->afterSave($input); $updated = $change->reread($post) ?? $post; $changedKeys = array_keys(array_intersect_key($input, array_flip(self::CHANGE_KEYS))); diff --git a/src/Integrations/WordPress/PostChangeResult.php b/src/Integrations/WordPress/PostSaveFollowUp.php similarity index 99% rename from src/Integrations/WordPress/PostChangeResult.php rename to src/Integrations/WordPress/PostSaveFollowUp.php index b4e317a..da2807c 100644 --- a/src/Integrations/WordPress/PostChangeResult.php +++ b/src/Integrations/WordPress/PostSaveFollowUp.php @@ -16,7 +16,7 @@ use WP_Post; * failure must not turn the saved change into an error – listener and log failures are * logged and reported as warnings ("… ist gespeichert"). */ -final class PostChangeResult +final class PostSaveFollowUp { /** @var list */ private array $warnings; diff --git a/src/Integrations/WordPress/Revisions/RevisionRestoreAbility.php b/src/Integrations/WordPress/Revisions/RevisionRestoreAbility.php index e1b3a98..ac4909a 100644 --- a/src/Integrations/WordPress/Revisions/RevisionRestoreAbility.php +++ b/src/Integrations/WordPress/Revisions/RevisionRestoreAbility.php @@ -9,7 +9,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\Rev; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\RevisionPoint; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; @@ -129,7 +129,7 @@ final class RevisionRestoreAbility implements Ability } // The restore is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Wiederherstellen'); + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId))->afterSave($input, 'Wiederherstellen'); $updated = $change->reread($post) ?? $post; $summary = sprintf('"%s" auf Stand vom %s zurückgesetzt', $updated->post_title, $revision->post_date); $postType = (string) $post->post_type; diff --git a/src/Integrations/WordPress/Status/PostDuplicateAbility.php b/src/Integrations/WordPress/Status/PostDuplicateAbility.php index a1a2ff5..ccda8d1 100644 --- a/src/Integrations/WordPress/Status/PostDuplicateAbility.php +++ b/src/Integrations/WordPress/Status/PostDuplicateAbility.php @@ -7,7 +7,7 @@ namespace LIT\MCP\Integrations\WordPress\Status; use LIT\MCP\Abilities\Ability; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use WP_Error; @@ -87,7 +87,7 @@ final class PostDuplicateAbility implements Ability $copyId = $this->cloner->duplicate($original); // The copy is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $copyId, 'die Kopie')) + $change = (new PostSaveFollowUp($this->name(), $this->log, $copyId, 'die Kopie')) ->afterSave($input, 'Anlegen der Kopie'); $copy = $change->reread(); $copyTitle = $copy instanceof WP_Post ? (string) $copy->post_title : ''; diff --git a/src/Integrations/WordPress/Status/PostPublishAbility.php b/src/Integrations/WordPress/Status/PostPublishAbility.php index 84c8124..1f8d27a 100644 --- a/src/Integrations/WordPress/Status/PostPublishAbility.php +++ b/src/Integrations/WordPress/Status/PostPublishAbility.php @@ -9,7 +9,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\Rev; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use WP_Error; @@ -120,7 +120,7 @@ final class PostPublishAbility implements Ability } // The status change is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Veröffentlichen'); + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId))->afterSave($input, 'Veröffentlichen'); $change->log((string) $post->post_type, sprintf('"%s" veröffentlicht', $title)); return $change->result(sprintf('"%s" ist jetzt veröffentlicht.', $title), $change->reread($post)) diff --git a/src/Integrations/WordPress/Status/PostReplaceWithCopyAbility.php b/src/Integrations/WordPress/Status/PostReplaceWithCopyAbility.php index 57cd164..6941c92 100644 --- a/src/Integrations/WordPress/Status/PostReplaceWithCopyAbility.php +++ b/src/Integrations/WordPress/Status/PostReplaceWithCopyAbility.php @@ -11,7 +11,7 @@ use LIT\MCP\Abilities\Rev; 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\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\RevisionPoint; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; @@ -222,7 +222,7 @@ final class PostReplaceWithCopyAbility implements Ability $warnings[] = $trashWarning; } - $change = (new PostChangeResult($this->name(), $this->log, $originalId, 'die Änderung', $warnings)) + $change = (new PostSaveFollowUp($this->name(), $this->log, $originalId, 'die Änderung', $warnings)) ->afterSave($input); $title = PostCloner::withoutSuffix((string) $copy->post_title); $summary = sprintf('Kopie ID %d in "%s" (ID %d) übernommen', $copyId, $title, $originalId); diff --git a/src/Integrations/WordPress/Status/PostScheduleAbility.php b/src/Integrations/WordPress/Status/PostScheduleAbility.php index f517d96..46223ff 100644 --- a/src/Integrations/WordPress/Status/PostScheduleAbility.php +++ b/src/Integrations/WordPress/Status/PostScheduleAbility.php @@ -10,7 +10,7 @@ use LIT\MCP\Abilities\Ability; use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use WP_Error; @@ -142,7 +142,7 @@ final class PostScheduleAbility implements Ability $raw )] : []; - $change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $warnings)) + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId, 'die Änderung', $warnings)) ->afterSave($input, 'Planen'); $title = (string) $post->post_title; $summary = sprintf('"%s" geplant für %s', $title, $raw) diff --git a/src/Integrations/WordPress/Status/PostTrashAbility.php b/src/Integrations/WordPress/Status/PostTrashAbility.php index f421d44..b2089ed 100644 --- a/src/Integrations/WordPress/Status/PostTrashAbility.php +++ b/src/Integrations/WordPress/Status/PostTrashAbility.php @@ -9,7 +9,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\Rev; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use WP_Error; @@ -137,7 +137,7 @@ final class PostTrashAbility implements Ability } // The change is saved – a failure of the change log from here on is a warning only. - $change = (new PostChangeResult($this->name(), $this->log, $postId, 'die Änderung', $impact)) + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId, 'die Änderung', $impact)) ->log((string) $post->post_type, sprintf('"%s" in den Papierkorb gelegt', $title)); $summary = sprintf('"%s" liegt im Papierkorb und ist dort wiederherstellbar.', $title); diff --git a/src/Integrations/WordPress/Status/PostUnpublishAbility.php b/src/Integrations/WordPress/Status/PostUnpublishAbility.php index c18307f..4bccc56 100644 --- a/src/Integrations/WordPress/Status/PostUnpublishAbility.php +++ b/src/Integrations/WordPress/Status/PostUnpublishAbility.php @@ -9,7 +9,7 @@ use LIT\MCP\Abilities\Errors; use LIT\MCP\Abilities\Rev; use LIT\MCP\Abilities\ToolResult; use LIT\MCP\ChangeLog\ChangeLog; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Integrations\WordPress\PostGuard; use LIT\MCP\Integrations\WordPress\Schema\ContentSchema; use WP_Error; @@ -103,7 +103,7 @@ final class PostUnpublishAbility implements Ability } // The status change is saved – failures from here on are logged and reported as warnings only. - $change = (new PostChangeResult($this->name(), $this->log, $postId))->afterSave($input, 'Zurückziehen'); + $change = (new PostSaveFollowUp($this->name(), $this->log, $postId))->afterSave($input, 'Zurückziehen'); $summary = sprintf('"%s" zurückgezogen (vorher %s, jetzt Entwurf)', $title, $post->post_status); $change->log((string) $post->post_type, $summary); $updated = $change->reread($post) ?? $post; diff --git a/tests/Unit/Integrations/Divi/Pages/DiviChangeTest.php b/tests/Unit/Integrations/Divi/Pages/DiviChangeTest.php index 4062d31..3a88be8 100644 --- a/tests/Unit/Integrations/Divi/Pages/DiviChangeTest.php +++ b/tests/Unit/Integrations/Divi/Pages/DiviChangeTest.php @@ -19,9 +19,9 @@ final class DiviChangeTest extends TestCase )); $row = $index->find('s0.r0'); $change = (new DiviChange('x')) - ->changed($row, 'updated') + ->record($row, 'updated') ->removed('s3.r1', Block::create('divi/row')) - ->changed(Block::create('divi/text'), 'inserted'); + ->record(Block::create('divi/text'), 'inserted'); self::assertSame( ['s0.r0', 's3.r1', null], diff --git a/tests/Unit/Integrations/Divi/Pages/DiviWriterTest.php b/tests/Unit/Integrations/Divi/Pages/DiviWriterTest.php index 5bb1ea8..0eda188 100644 --- a/tests/Unit/Integrations/Divi/Pages/DiviWriterTest.php +++ b/tests/Unit/Integrations/Divi/Pages/DiviWriterTest.php @@ -134,7 +134,7 @@ final class DiviWriterTest extends TestCase $button->setAttrs(AttrMap::set($button->attrs(), 'button.innerContent.desktop.value.text', 'Neu')); $page->document->children()[0]->removeChild($removed); $change = (new DiviChange('Button geändert')) - ->changed($button, 'updated') + ->record($button, 'updated') ->removed('s1', $removed) ->warning('eigene Warnung'); diff --git a/tests/Unit/Integrations/WordPress/PostChangeResultTest.php b/tests/Unit/Integrations/WordPress/PostSaveFollowUpTest.php similarity index 91% rename from tests/Unit/Integrations/WordPress/PostChangeResultTest.php rename to tests/Unit/Integrations/WordPress/PostSaveFollowUpTest.php index 4372fe0..895fb42 100644 --- a/tests/Unit/Integrations/WordPress/PostChangeResultTest.php +++ b/tests/Unit/Integrations/WordPress/PostSaveFollowUpTest.php @@ -7,13 +7,13 @@ namespace LIT\MCP\Tests\Unit\Integrations\WordPress; use Brain\Monkey\Actions; use Brain\Monkey\Functions; use LIT\MCP\Abilities\Rev; -use LIT\MCP\Integrations\WordPress\PostChangeResult; +use LIT\MCP\Integrations\WordPress\PostSaveFollowUp; use LIT\MCP\Tests\Support\FakeChangeLog; use LIT\MCP\Tests\Unit\TestCase; use RuntimeException; use WP_Post; -final class PostChangeResultTest extends TestCase +final class PostSaveFollowUpTest extends TestCase { private string $errorLog = ''; private string|false $previousLog = false; @@ -39,7 +39,7 @@ final class PostChangeResultTest extends TestCase Functions\when('get_post')->justReturn($post); $log = new FakeChangeLog(9); - $change = new PostChangeResult('lit/content-update', $log, 5, 'die Änderung', ['vorher']); + $change = new PostSaveFollowUp('lit/content-update', $log, 5, 'die Änderung', ['vorher']); $change->afterSave(['post_id' => 5]); $updated = $change->reread(); $change->log('page', 'geändert', 811); @@ -68,7 +68,7 @@ final class PostChangeResultTest extends TestCase $log = new FakeChangeLog(1, new RuntimeException('log kaputt')); $fallback = new WP_Post(['ID' => 5]); - $change = new PostChangeResult('lit/post-publish', $log, 5); + $change = new PostSaveFollowUp('lit/post-publish', $log, 5); $change->afterSave([], 'Veröffentlichen'); $updated = $change->reread($fallback); $change->log('page', 'x'); @@ -88,7 +88,7 @@ final class PostChangeResultTest extends TestCase { Functions\when('get_post')->justReturn(null); - $change = new PostChangeResult('lit/content-create', FakeChangeLog::forbidden(), 5, 'der Entwurf'); + $change = new PostSaveFollowUp('lit/content-create', FakeChangeLog::forbidden(), 5, 'der Entwurf'); self::assertNull($change->reread()); self::assertNull($change->result('ok', null)->toArray()['rev']);