}
// Get the current revision for the page
- $current = $revision->getCurrent();
+ $currentRevision = $page->getCurrentRevision();
// Check if its the latest revision, cannot delete latest revision.
- if (intval($current->id) === intval($revId)) {
+ if (intval($currentRevision->id) === intval($revId)) {
session()->flash('error', trans('entities.revision_cannot_delete_latest'));
return view('pages/revisions', ['page' => $page, 'book' => $page->book, 'current' => $page]);
}
$htmlQuery = $withContent ? 'html' : "'' as html";
return "'BookStack\\\\Page' as entity_type, id, id as entity_id, slug, name, {$this->textField} as text, {$htmlQuery}, book_id, priority, chapter_id, draft, created_by, updated_by, updated_at, created_at";
}
+
+ /**
+ * Get the current revision for the page if existing
+ * @return \BookStack\PageRevision|null
+ */
+ public function getCurrentRevision()
+ {
+ if ($id = PageRevision::where('page_id', '=', $this->id)->max('id')) {
+ return PageRevision::find($id);
+ }
+ return null;
+ }
}
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.
&.neg {
color: $negative;
}
- &.link {
- &:hover {
- text-decoration: underline;
- }
- }
}
.button-group {
'pages_revisions_current' => 'Current Version',
'pages_revisions_preview' => 'Preview',
'pages_revisions_restore' => 'Restore',
- 'pages_revisions_delete' => 'Delete',
'pages_revisions_none' => 'This page has no revisions',
'pages_copy_link' => 'Copy Link',
'pages_edit_content_link' => 'Edit Content',
<a href="{{ $revision->getUrl('restore') }}">{{ trans('entities.pages_revisions_restore') }}</a>
<span class="text-muted"> | </span>
<div dropdown class="dropdown-container">
- <button type="button" dropdown-toggle class="text-button link">{{ trans('common.delete') }}</button>
+ <a dropdown-toggle>{{ trans('common.delete') }}</a>
<ul>
<li class="padded"><small class="text-muted">{{trans('entities.revision_delete_confirm')}}</small></li>
<li>
$this->assertTrue($beforeRevisionCount === ($afterRevisionCount + 1));
// Try to delete the latest revision
- $revision = $page->revisions->get($page->revisions->count() - 1);
- $resp = $this->asEditor()->delete($revision->getUrl('/delete/'));
- $resp->assertSee('Cannot delete the latest revision');
+ $beforeRevisionCount = $page->revisions->count();
+ $currentRevision = $page->getCurrentRevision();
+ $this->asEditor()->delete($currentRevision->getUrl('/delete/'));
+
+ $page = Page::find($page->id);
+ $afterRevisionCount = $page->revisions->count();
+ $this->assertTrue($beforeRevisionCount === $afterRevisionCount);
}
}
\ No newline at end of file