mirror of
https://github.com/BookStackApp/BookStack.git
synced 2024-11-22 20:56:55 +08:00
Added ability to configure revision limit
This commit is contained in:
parent
0931ff38e9
commit
3f58800ed1
|
@ -746,10 +746,13 @@ class EntityRepo
|
|||
$revision->revision_number = $page->revision_count;
|
||||
$revision->save();
|
||||
|
||||
// Clear old revisions
|
||||
if ($this->pageRevision->where('page_id', '=', $page->id)->count() > 50) {
|
||||
$this->pageRevision->where('page_id', '=', $page->id)
|
||||
->orderBy('created_at', 'desc')->skip(50)->take(5)->delete();
|
||||
$revisionLimit = config('app.revision_limit');
|
||||
if ($revisionLimit !== false) {
|
||||
$revisionsToDelete = $this->pageRevision->where('page_id', '=', $page->id)
|
||||
->orderBy('created_at', 'desc')->skip(intval($revisionLimit))->take(10)->get(['id']);
|
||||
if ($revisionsToDelete->count() > 0) {
|
||||
$this->pageRevision->whereIn('id', $revisionsToDelete->pluck('id'))->delete();
|
||||
}
|
||||
}
|
||||
|
||||
return $revision;
|
||||
|
|
|
@ -6,9 +6,10 @@
|
|||
"type": "project",
|
||||
"require": {
|
||||
"php": ">=7.0.0",
|
||||
"ext-tidy": "*",
|
||||
"ext-dom": "*",
|
||||
"laravel/framework": "~5.5.42",
|
||||
"fideloper/proxy": "~3.3",
|
||||
"ext-tidy": "*",
|
||||
"intervention/image": "^2.4",
|
||||
"laravel/socialite": "^3.0",
|
||||
"league/flysystem-aws-s3-v3": "^1.0",
|
||||
|
|
|
@ -12,6 +12,13 @@ return [
|
|||
'books' => env('APP_VIEWS_BOOKS', 'list')
|
||||
],
|
||||
|
||||
/**
|
||||
* The number of revisions to keep in the database.
|
||||
* Once this limit is reached older revisions will be deleted.
|
||||
* If set to false then a limit will not be enforced.
|
||||
*/
|
||||
'revision_limit' => env('REVISION_LIMIT', 50),
|
||||
|
||||
/**
|
||||
* Allow <script> tags to entered within page content.
|
||||
* <script> tags are escaped by default.
|
||||
|
|
|
@ -60,4 +60,34 @@ class PageRevisionTest extends TestCase
|
|||
$afterRevisionCount = $page->revisions->count();
|
||||
$this->assertTrue($beforeRevisionCount === $afterRevisionCount);
|
||||
}
|
||||
|
||||
public function test_revision_limit_enforced()
|
||||
{
|
||||
config()->set('app.revision_limit', 2);
|
||||
$page = Page::first();
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
$page = Page::find($page->id);
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
}
|
||||
|
||||
$revisionCount = $page->revisions()->count();
|
||||
$this->assertEquals(2, $revisionCount);
|
||||
}
|
||||
|
||||
public function test_false_revision_limit_allows_many_revisions()
|
||||
{
|
||||
config()->set('app.revision_limit', false);
|
||||
$page = Page::first();
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
$page = Page::find($page->id);
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
for ($i = 0; $i < 10; $i++) {
|
||||
$this->asEditor()->put($page->getUrl(), ['name' => 'Updated page', 'html' => 'new page html', 'summary' => 'Update a']);
|
||||
}
|
||||
|
||||
$revisionCount = $page->revisions()->count();
|
||||
$this->assertEquals(12, $revisionCount);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user