2017-02-26 17:14:18 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace BookStack\Console\Commands;
|
|
|
|
|
2018-09-25 19:30:50 +08:00
|
|
|
use BookStack\Entities\PageRevision;
|
2017-02-26 17:14:18 +08:00
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
class ClearRevisions extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
|
|
|
|
protected $pageRevision;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a new command instance.
|
|
|
|
*
|
|
|
|
* @param PageRevision $pageRevision
|
|
|
|
*/
|
|
|
|
public function __construct(PageRevision $pageRevision)
|
|
|
|
{
|
|
|
|
$this->pageRevision = $pageRevision;
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
|
|
|
$deleteTypes = $this->option('all') ? ['version', 'update_draft'] : ['version'];
|
|
|
|
$this->pageRevision->newQuery()->whereIn('type', $deleteTypes)->delete();
|
|
|
|
$this->comment('Revisions deleted');
|
|
|
|
}
|
|
|
|
}
|