mirror of
https://github.com/BookStackApp/BookStack.git
synced 2025-02-17 07:22:45 +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->revision_number = $page->revision_count;
|
||||||
$revision->save();
|
$revision->save();
|
||||||
|
|
||||||
// Clear old revisions
|
$revisionLimit = config('app.revision_limit');
|
||||||
if ($this->pageRevision->where('page_id', '=', $page->id)->count() > 50) {
|
if ($revisionLimit !== false) {
|
||||||
$this->pageRevision->where('page_id', '=', $page->id)
|
$revisionsToDelete = $this->pageRevision->where('page_id', '=', $page->id)
|
||||||
->orderBy('created_at', 'desc')->skip(50)->take(5)->delete();
|
->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;
|
return $revision;
|
||||||
|
|
|
@ -6,9 +6,10 @@
|
||||||
"type": "project",
|
"type": "project",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=7.0.0",
|
"php": ">=7.0.0",
|
||||||
|
"ext-tidy": "*",
|
||||||
|
"ext-dom": "*",
|
||||||
"laravel/framework": "~5.5.42",
|
"laravel/framework": "~5.5.42",
|
||||||
"fideloper/proxy": "~3.3",
|
"fideloper/proxy": "~3.3",
|
||||||
"ext-tidy": "*",
|
|
||||||
"intervention/image": "^2.4",
|
"intervention/image": "^2.4",
|
||||||
"laravel/socialite": "^3.0",
|
"laravel/socialite": "^3.0",
|
||||||
"league/flysystem-aws-s3-v3": "^1.0",
|
"league/flysystem-aws-s3-v3": "^1.0",
|
||||||
|
|
|
@ -12,6 +12,13 @@ return [
|
||||||
'books' => env('APP_VIEWS_BOOKS', 'list')
|
'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.
|
* Allow <script> tags to entered within page content.
|
||||||
* <script> tags are escaped by default.
|
* <script> tags are escaped by default.
|
||||||
|
|
|
@ -60,4 +60,34 @@ class PageRevisionTest extends TestCase
|
||||||
$afterRevisionCount = $page->revisions->count();
|
$afterRevisionCount = $page->revisions->count();
|
||||||
$this->assertTrue($beforeRevisionCount === $afterRevisionCount);
|
$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