2017-02-26 09:14:18 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2020-11-22 00:17:45 +00:00
|
|
|
use BookStack\Entities\Models\PageRevision;
|
2017-02-26 09:14:18 +00:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
2023-05-24 12:21:46 +00:00
|
|
|
class ClearRevisionsCommand extends Command
|
2017-02-26 09:14:18 +00: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 11:59:50 +00:00
|
|
|
public function handle(): int
|
2017-02-26 09:14:18 +00:00
|
|
|
{
|
|
|
|
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
|
2023-05-24 11:59:50 +00:00
|
|
|
PageRevision::query()->whereIn('type', $deleteTypes)->delete();
|
2017-02-26 09:14:18 +00:00
|
|
|
$this->comment('Revisions deleted');
|
2023-05-24 11:59:50 +00:00
|
|
|
return 0;
|
2017-02-26 09:14:18 +00:00
|
|
|
}
|
|
|
|
}
|