2017-02-26 17:14:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2020-11-22 08:17:45 +08:00
|
|
|
use BookStack\Entities\Models\PageRevision;
|
2017-02-26 17:14:18 +08:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2023-05-24 20:21:46 +08:00
|
|
|
class ClearRevisionsCommand extends Command
|
2017-02-26 17:14:18 +08:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'bookstack:clear-revisions
|
|
|
|
{--a|all : Include active update drafts in deletion}
|
|
|
|
';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Clear page revisions';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*/
|
2023-05-24 19:59:50 +08:00
|
|
|
public function handle(): int
|
2017-02-26 17:14:18 +08:00
|
|
|
{
|
|
|
|
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
|
2023-05-24 19:59:50 +08:00
|
|
|
PageRevision::query()->whereIn('type', $deleteTypes)->delete();
|
2017-02-26 17:14:18 +08:00
|
|
|
$this->comment('Revisions deleted');
|
2023-05-24 19:59:50 +08:00
|
|
|
return 0;
|
2017-02-26 17:14:18 +08:00
|
|
|
}
|
|
|
|
}
|