Merge branch 'v0.31.x' into release
This commit is contained in:
commit
b54702ab08
|
@ -177,17 +177,13 @@ class PageRepo
|
||||||
// Hold the old details to compare later
|
// Hold the old details to compare later
|
||||||
$oldHtml = $page->html;
|
$oldHtml = $page->html;
|
||||||
$oldName = $page->name;
|
$oldName = $page->name;
|
||||||
|
$oldMarkdown = $page->markdown;
|
||||||
|
|
||||||
$this->updateTemplateStatusAndContentFromInput($page, $input);
|
$this->updateTemplateStatusAndContentFromInput($page, $input);
|
||||||
$this->baseRepo->update($page, $input);
|
$this->baseRepo->update($page, $input);
|
||||||
|
|
||||||
// Update with new details
|
// Update with new details
|
||||||
$page->revision_count++;
|
$page->revision_count++;
|
||||||
|
|
||||||
if (setting('app-editor') !== 'markdown') {
|
|
||||||
$page->markdown = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$page->save();
|
$page->save();
|
||||||
|
|
||||||
// Remove all update drafts for this user & page.
|
// Remove all update drafts for this user & page.
|
||||||
|
@ -195,7 +191,10 @@ class PageRepo
|
||||||
|
|
||||||
// Save a revision after updating
|
// Save a revision after updating
|
||||||
$summary = $input['summary'] ?? null;
|
$summary = $input['summary'] ?? null;
|
||||||
if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $summary !== null) {
|
$htmlChanged = isset($input['html']) && $input['html'] !== $oldHtml;
|
||||||
|
$nameChanged = isset($input['name']) && $input['name'] !== $oldName;
|
||||||
|
$markdownChanged = isset($input['markdown']) && $input['markdown'] !== $oldMarkdown;
|
||||||
|
if ($htmlChanged || $nameChanged || $markdownChanged || $summary !== null) {
|
||||||
$this->savePageRevision($page, $summary);
|
$this->savePageRevision($page, $summary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,10 +223,6 @@ class PageRepo
|
||||||
{
|
{
|
||||||
$revision = new PageRevision($page->getAttributes());
|
$revision = new PageRevision($page->getAttributes());
|
||||||
|
|
||||||
if (setting('app-editor') !== 'markdown') {
|
|
||||||
$revision->markdown = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
$revision->page_id = $page->id;
|
$revision->page_id = $page->id;
|
||||||
$revision->slug = $page->slug;
|
$revision->slug = $page->slug;
|
||||||
$revision->book_slug = $page->book->slug;
|
$revision->book_slug = $page->book->slug;
|
||||||
|
@ -290,7 +285,13 @@ class PageRepo
|
||||||
|
|
||||||
$page->fill($revision->toArray());
|
$page->fill($revision->toArray());
|
||||||
$content = new PageContent($page);
|
$content = new PageContent($page);
|
||||||
|
|
||||||
|
if (!empty($revision->markdown)) {
|
||||||
|
$content->setNewMarkdown($revision->markdown);
|
||||||
|
} else {
|
||||||
$content->setNewHTML($revision->html);
|
$content->setNewHTML($revision->html);
|
||||||
|
}
|
||||||
|
|
||||||
$page->updated_by = user()->id;
|
$page->updated_by = user()->id;
|
||||||
$page->refreshSlug();
|
$page->refreshSlug();
|
||||||
$page->save();
|
$page->save();
|
||||||
|
|
|
@ -273,11 +273,11 @@ class TrashCan
|
||||||
$count++;
|
$count++;
|
||||||
};
|
};
|
||||||
|
|
||||||
if ($entity->isA('chapter') || $entity->isA('book')) {
|
if ($entity instanceof Chapter || $entity instanceof Book) {
|
||||||
$entity->pages()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
$entity->pages()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($entity->isA('book')) {
|
if ($entity instanceof Book) {
|
||||||
$entity->chapters()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
$entity->chapters()->withTrashed()->withCount('deletions')->get()->each($restoreAction);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,19 +286,20 @@ class TrashCan
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy the given entity.
|
* Destroy the given entity.
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
protected function destroyEntity(Entity $entity): int
|
protected function destroyEntity(Entity $entity): int
|
||||||
{
|
{
|
||||||
if ($entity->isA('page')) {
|
if ($entity instanceof Page) {
|
||||||
return $this->destroyPage($entity);
|
return $this->destroyPage($entity);
|
||||||
}
|
}
|
||||||
if ($entity->isA('chapter')) {
|
if ($entity instanceof Chapter) {
|
||||||
return $this->destroyChapter($entity);
|
return $this->destroyChapter($entity);
|
||||||
}
|
}
|
||||||
if ($entity->isA('book')) {
|
if ($entity instanceof Book) {
|
||||||
return $this->destroyBook($entity);
|
return $this->destroyBook($entity);
|
||||||
}
|
}
|
||||||
if ($entity->isA('shelf')) {
|
if ($entity instanceof Bookshelf) {
|
||||||
return $this->destroyShelf($entity);
|
return $this->destroyShelf($entity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,36 @@ class PageRevisionTest extends TestCase
|
||||||
$pageView->assertSee('def456');
|
$pageView->assertSee('def456');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_page_revision_restore_with_markdown_retains_markdown_content()
|
||||||
|
{
|
||||||
|
$this->asEditor();
|
||||||
|
|
||||||
|
$pageRepo = app(PageRepo::class);
|
||||||
|
$page = Page::first();
|
||||||
|
$pageRepo->update($page, ['name' => 'updated page abc123', 'markdown' => '## New Content def456', 'summary' => 'initial page revision testing']);
|
||||||
|
$pageRepo->update($page, ['name' => 'updated page again', 'markdown' => '## New Content Updated', 'summary' => 'page revision testing']);
|
||||||
|
$page = Page::find($page->id);
|
||||||
|
|
||||||
|
$pageView = $this->get($page->getUrl());
|
||||||
|
$pageView->assertDontSee('abc123');
|
||||||
|
$pageView->assertDontSee('def456');
|
||||||
|
|
||||||
|
$revToRestore = $page->revisions()->where('name', 'like', '%abc123')->first();
|
||||||
|
$restoreReq = $this->put($page->getUrl() . '/revisions/' . $revToRestore->id . '/restore');
|
||||||
|
$page = Page::find($page->id);
|
||||||
|
|
||||||
|
$restoreReq->assertStatus(302);
|
||||||
|
$restoreReq->assertRedirect($page->getUrl());
|
||||||
|
|
||||||
|
$pageView = $this->get($page->getUrl());
|
||||||
|
$this->assertDatabaseHas('pages', [
|
||||||
|
'id' => $page->id,
|
||||||
|
'markdown' => '## New Content def456',
|
||||||
|
]);
|
||||||
|
$pageView->assertSee('abc123');
|
||||||
|
$pageView->assertSee('def456');
|
||||||
|
}
|
||||||
|
|
||||||
public function test_page_revision_restore_sets_new_revision_with_summary()
|
public function test_page_revision_restore_sets_new_revision_with_summary()
|
||||||
{
|
{
|
||||||
$this->asEditor();
|
$this->asEditor();
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
<?php namespace Tests;
|
<?php namespace Tests;
|
||||||
|
|
||||||
use BookStack\Entities\Models\Book;
|
use BookStack\Entities\Models\Book;
|
||||||
|
use BookStack\Entities\Models\Bookshelf;
|
||||||
|
use BookStack\Entities\Models\Chapter;
|
||||||
use BookStack\Entities\Models\Deletion;
|
use BookStack\Entities\Models\Deletion;
|
||||||
|
use BookStack\Entities\Models\Entity;
|
||||||
use BookStack\Entities\Models\Page;
|
use BookStack\Entities\Models\Page;
|
||||||
use DB;
|
use DB;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
|
@ -129,6 +132,21 @@ class RecycleBinTest extends TestCase
|
||||||
$redirectReq->assertNotificationContains('Deleted '.$itemCount.' total items from the recycle bin');
|
$redirectReq->assertNotificationContains('Deleted '.$itemCount.' total items from the recycle bin');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test_permanent_delete_for_each_type()
|
||||||
|
{
|
||||||
|
/** @var Entity $entity */
|
||||||
|
foreach ([new Bookshelf, new Book, new Chapter, new Page] as $entity) {
|
||||||
|
$entity = $entity->newQuery()->first();
|
||||||
|
$this->asEditor()->delete($entity->getUrl());
|
||||||
|
$deletion = Deletion::query()->orderBy('id', 'desc')->firstOrFail();
|
||||||
|
|
||||||
|
$deleteReq = $this->asAdmin()->delete("/settings/recycle-bin/{$deletion->id}");
|
||||||
|
$deleteReq->assertRedirect('/settings/recycle-bin');
|
||||||
|
$this->assertDatabaseMissing('deletions', ['id' => $deletion->id]);
|
||||||
|
$this->assertDatabaseMissing($entity->getTable(), ['id' => $entity->id]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function test_permanent_entity_delete_updates_existing_activity_with_entity_name()
|
public function test_permanent_entity_delete_updates_existing_activity_with_entity_name()
|
||||||
{
|
{
|
||||||
$page = Page::query()->firstOrFail();
|
$page = Page::query()->firstOrFail();
|
||||||
|
|
Loading…
Reference in New Issue