]> BookStack Code Mirror - bookstack/blobdiff - app/Http/Controllers/PageRevisionController.php
Apply fixes from StyleCI
[bookstack] / app / Http / Controllers / PageRevisionController.php
index 3c65b50ac5ae6e2d9c9769ba2f4a4ace572ea51f..d595a6e26fd797cb0c7693f473e0680a168caf3e 100644 (file)
@@ -1,13 +1,14 @@
-<?php namespace BookStack\Http\Controllers;
+<?php
+
+namespace BookStack\Http\Controllers;
 
 use BookStack\Entities\Repos\PageRepo;
+use BookStack\Entities\Tools\PageContent;
 use BookStack\Exceptions\NotFoundException;
-use BookStack\Facades\Activity;
-use GatherContent\Htmldiff\Htmldiff;
+use Ssddanbrown\HtmlDiff\Diff;
 
 class PageRevisionController extends Controller
 {
-
     protected $pageRepo;
 
     /**
@@ -16,25 +17,27 @@ class PageRevisionController extends Controller
     public function __construct(PageRepo $pageRepo)
     {
         $this->pageRepo = $pageRepo;
-        parent::__construct();
     }
 
     /**
      * Shows the last revisions for this page.
+     *
      * @throws NotFoundException
      */
     public function index(string $bookSlug, string $pageSlug)
     {
         $page = $this->pageRepo->getBySlug($bookSlug, $pageSlug);
         $this->setPageTitle(trans('entities.pages_revisions_named', ['pageName'=>$page->getShortName()]));
+
         return view('pages.revisions', [
-            'page' => $page,
-            'current' => $page
+            'page'    => $page,
+            'current' => $page,
         ]);
     }
 
     /**
      * Shows a preview of a single revision.
+     *
      * @throws NotFoundException
      */
     public function show(string $bookSlug, string $pageSlug, int $revisionId)
@@ -46,18 +49,23 @@ class PageRevisionController extends Controller
         }
 
         $page->fill($revision->toArray());
+        // TODO - Refactor PageContent so we don't need to juggle this
+        $page->html = $revision->html;
+        $page->html = (new PageContent($page))->render();
 
         $this->setPageTitle(trans('entities.pages_revision_named', ['pageName' => $page->getShortName()]));
+
         return view('pages.revision', [
-            'page' => $page,
-            'book' => $page->book,
-            'diff' => null,
-            'revision' => $revision
+            'page'     => $page,
+            'book'     => $page->book,
+            'diff'     => null,
+            'revision' => $revision,
         ]);
     }
 
     /**
      * Shows the changes of a single revision.
+     *
      * @throws NotFoundException
      */
     public function changes(string $bookSlug, string $pageSlug, int $revisionId)
@@ -70,21 +78,25 @@ class PageRevisionController extends Controller
 
         $prev = $revision->getPrevious();
         $prevContent = $prev->html ?? '';
-        $diff = (new Htmldiff)->diff($prevContent, $revision->html);
+        $diff = Diff::excecute($prevContent, $revision->html);
 
         $page->fill($revision->toArray());
+        // TODO - Refactor PageContent so we don't need to juggle this
+        $page->html = $revision->html;
+        $page->html = (new PageContent($page))->render();
         $this->setPageTitle(trans('entities.pages_revision_named', ['pageName'=>$page->getShortName()]));
 
         return view('pages.revision', [
-            'page' => $page,
-            'book' => $page->book,
-            'diff' => $diff,
-            'revision' => $revision
+            'page'     => $page,
+            'book'     => $page->book,
+            'diff'     => $diff,
+            'revision' => $revision,
         ]);
     }
 
     /**
      * Restores a page using the content of the specified revision.
+     *
      * @throws NotFoundException
      */
     public function restore(string $bookSlug, string $pageSlug, int $revisionId)
@@ -94,12 +106,12 @@ class PageRevisionController extends Controller
 
         $page = $this->pageRepo->restoreRevision($page, $revisionId);
 
-        Activity::add($page, 'page_restore', $page->book->id);
         return redirect($page->getUrl());
     }
 
     /**
      * Deletes a revision using the id of the specified revision.
+     *
      * @throws NotFoundException
      */
     public function destroy(string $bookSlug, string $pageSlug, int $revId)
@@ -118,11 +130,13 @@ class PageRevisionController extends Controller
         // Check if its the latest revision, cannot delete latest revision.
         if (intval($currentRevision->id) === intval($revId)) {
             $this->showErrorNotification(trans('entities.revision_cannot_delete_latest'));
+
             return redirect($page->getUrl('/revisions'));
         }
 
         $revision->delete();
         $this->showSuccessNotification(trans('entities.revision_delete_success'));
+
         return redirect($page->getUrl('/revisions'));
     }
 }