diff --git a/app/Entities/Repos/PageRepo.php b/app/Entities/Repos/PageRepo.php index 60ae85510..721485b11 100644 --- a/app/Entities/Repos/PageRepo.php +++ b/app/Entities/Repos/PageRepo.php @@ -220,7 +220,7 @@ class PageRepo /** * Saves a page revision into the system. */ - protected function savePageRevision(Page $page, string $summary = null) + protected function savePageRevision(Page $page, string $summary = null): PageRevision { $revision = new PageRevision($page->getAttributes()); @@ -287,8 +287,6 @@ class PageRepo { $page->revision_count++; $revision = $page->revisions()->where('id', '=', $revisionId)->first(); - $summary = trans('entities.pages_revision_restored_from', ['id' => strval($revisionId), 'summary' => $revision->summary]); - $this->savePageRevision($page, $summary); $page->fill($revision->toArray()); $content = new PageContent($page); @@ -296,8 +294,11 @@ class PageRepo $page->updated_by = user()->id; $page->refreshSlug(); $page->save(); - $page->indexForSearch(); + + $summary = trans('entities.pages_revision_restored_from', ['id' => strval($revisionId), 'summary' => $revision->summary]); + $this->savePageRevision($page, $summary); + Activity::addForEntity($page, ActivityType::PAGE_RESTORE); return $page; } diff --git a/resources/lang/en/entities.php b/resources/lang/en/entities.php index f668c6181..6c0980fab 100644 --- a/resources/lang/en/entities.php +++ b/resources/lang/en/entities.php @@ -210,7 +210,7 @@ return [ 'pages_revisions' => 'Page Revisions', 'pages_revisions_named' => 'Page Revisions for :pageName', 'pages_revision_named' => 'Page Revision for :pageName', - 'pages_revision_restored_from' => 'Restored from #:id ":summary"', + 'pages_revision_restored_from' => 'Restored from #:id; :summary', 'pages_revisions_created_by' => 'Created By', 'pages_revisions_date' => 'Revision Date', 'pages_revisions_number' => '#', diff --git a/tests/Entity/PageRevisionTest.php b/tests/Entity/PageRevisionTest.php index 6eaea129c..68a8f01a9 100644 --- a/tests/Entity/PageRevisionTest.php +++ b/tests/Entity/PageRevisionTest.php @@ -66,6 +66,28 @@ class PageRevisionTest extends TestCase $pageView->assertSee('def456'); } + public function test_page_revision_restore_sets_new_revision_with_summary() + { + $this->asEditor(); + + $pageRepo = app(PageRepo::class); + $page = Page::first(); + $pageRepo->update($page, ['name' => 'updated page abc123', 'html' => '

new contente def456

', 'summary' => 'My first update']); + $pageRepo->update($page, ['name' => 'updated page again', 'html' => '

new content

', 'summary' => '']); + $page->refresh(); + + $revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first(); + $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore'); + $page->refresh(); + + $this->assertDatabaseHas('page_revisions', [ + 'page_id' => $page->id, + 'text' => 'new contente def456', + 'type' => 'version', + 'summary' => "Restored from #{$revToRestore->id}; My first update", + ]); + } + public function test_page_revision_count_increments_on_update() { $page = Page::first();