mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-08-09 10:22:51 +03:00
Adds code to delete the revision.
Signed-off-by: Abijeet <abijeetpatro@gmail.com>
This commit is contained in:
14
app/Exceptions/BadRequestException.php
Normal file
14
app/Exceptions/BadRequestException.php
Normal file
@@ -0,0 +1,14 @@
|
||||
<?php namespace BookStack\Exceptions;
|
||||
|
||||
class BadRequestException extends PrettyException
|
||||
{
|
||||
|
||||
/**
|
||||
* BadRequestException constructor.
|
||||
* @param string $message
|
||||
*/
|
||||
public function __construct($message = 'Bad request')
|
||||
{
|
||||
parent::__construct($message, 400);
|
||||
}
|
||||
}
|
@@ -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
|
||||
|
@@ -48,6 +48,18 @@ class PageRevision extends Model
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the current revision for the same page if existing
|
||||
* @return \BookStack\PageRevision|null
|
||||
*/
|
||||
public function getCurrent()
|
||||
{
|
||||
if ($id = static::where('page_id', '=', $this->page_id)->max('id')) {
|
||||
return static::find($id);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows checking of the exact class, Used to check entity type.
|
||||
* Included here to align with entities in similar use cases.
|
||||
|
Reference in New Issue
Block a user