Fixed page includes erroring on save

Closes #514
This commit is contained in:
Dan Brown 2017-09-20 21:03:40 +01:00
parent df0a982433
commit 74a5e3113e
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 19 additions and 3 deletions

View File

@ -158,9 +158,9 @@ class PageController extends Controller
$this->checkOwnablePermission('page-view', $page); $this->checkOwnablePermission('page-view', $page);
$pageContent = $this->entityRepo->renderPage($page); $page->html = $this->entityRepo->renderPage($page);
$sidebarTree = $this->entityRepo->getBookChildren($page->book); $sidebarTree = $this->entityRepo->getBookChildren($page->book);
$pageNav = $this->entityRepo->getPageNav($pageContent); $pageNav = $this->entityRepo->getPageNav($page->html);
$page->load(['comments.createdBy']); $page->load(['comments.createdBy']);
Views::add($page); Views::add($page);
@ -441,6 +441,7 @@ class PageController extends Controller
public function exportPdf($bookSlug, $pageSlug) public function exportPdf($bookSlug, $pageSlug)
{ {
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$page->html = $this->entityRepo->renderPage($page);
$pdfContent = $this->exportService->pageToPdf($page); $pdfContent = $this->exportService->pageToPdf($page);
return response()->make($pdfContent, 200, [ return response()->make($pdfContent, 200, [
'Content-Type' => 'application/octet-stream', 'Content-Type' => 'application/octet-stream',
@ -457,6 +458,7 @@ class PageController extends Controller
public function exportHtml($bookSlug, $pageSlug) public function exportHtml($bookSlug, $pageSlug)
{ {
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug); $page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$page->html = $this->entityRepo->renderPage($page);
$containedHtml = $this->exportService->pageToContainedHtml($page); $containedHtml = $this->exportService->pageToContainedHtml($page);
return response()->make($containedHtml, 200, [ return response()->make($containedHtml, 200, [
'Content-Type' => 'application/octet-stream', 'Content-Type' => 'application/octet-stream',

View File

@ -716,7 +716,6 @@ class EntityRepo
$content = str_replace($matches[0][$index], trim($innerContent), $content); $content = str_replace($matches[0][$index], trim($innerContent), $content);
} }
$page->setAttribute('renderedHTML', $content);
return $content; return $content;
} }

View File

@ -35,6 +35,21 @@ class PageContentTest extends TestCase
$pageContent->assertSee('Well This is a second block of content'); $pageContent->assertSee('Well This is a second block of content');
} }
public function test_saving_page_with_includes()
{
$page = Page::first();
$secondPage = Page::all()->get(2);
$this->asEditor();
$page->html = "<p>{{@$secondPage->id}}</p>";
$resp = $this->put($page->getUrl(), ['name' => $page->name, 'html' => $page->html, 'summary' => '']);
$resp->assertStatus(302);
$page = Page::find($page->id);
$this->assertContains("{{@$secondPage->id}}", $page->html);
}
public function test_page_revision_views_viewable() public function test_page_revision_views_viewable()
{ {
$this->asEditor(); $this->asEditor();