Adds code to delete the revision.

Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
Abijeet
2018-09-15 15:15:42 +05:30
parent d2a9b312e9
commit 714c7bbd3a
9 changed files with 90 additions and 4 deletions

View File

@ -2,6 +2,7 @@
use Activity;
use BookStack\Exceptions\NotFoundException;
use BookStack\Exceptions\BadRequestException;
use BookStack\Repos\EntityRepo;
use BookStack\Repos\UserRepo;
use BookStack\Services\ExportService;
@ -454,6 +455,38 @@ class PageController extends Controller
return redirect($page->getUrl());
}
/**
* Deletes a revision using the id of the specified revision.
* @param string $bookSlug
* @param string $pageSlug
* @param int $revisionId
* @throws NotFoundException
* @throws BadRequestException
* @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
*/
public function destroyRevision($bookSlug, $pageSlug, $revId)
{
$page = $this->entityRepo->getBySlug('page', $pageSlug, $bookSlug);
$this->checkOwnablePermission('page-update', $page);
$revision = $page->revisions()->where('id', '=', $revId)->first();
if ($revision === null) {
throw new NotFoundException("Revision #{$revId} not found");
}
// Get the current revision for the page
$current = $revision->getCurrent();
// Check if its the latest revision, cannot delete latest revision.
if (intval($current->id) === intval($revId)) {
throw new BadRequestException("Cannot delete the current revision #{$revId}");
}
$revision->delete();
return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
}
/**
* Exports a page to a PDF.
* https://github.com/barryvdh/laravel-dompdf