40 lines
965 B
PHP
40 lines
965 B
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Models\PopularDaily;
|
|
use App\Models\PopularWeekly;
|
|
use App\Models\PopularMonthly;
|
|
|
|
use Illuminate\Support\Carbon;
|
|
use Illuminate\Console\Command;
|
|
|
|
class AutoStats extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'app:auto-stats';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Clear Outdated Popular Stats';
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*/
|
|
public function handle()
|
|
{
|
|
PopularDaily::where('created_at', '<=', Carbon::now()->subMinutes(1440))->forceDelete();
|
|
PopularWeekly::where('created_at', '<=', Carbon::now()->subMinutes(10080))->forceDelete();
|
|
PopularMonthly::where('created_at', '<=', Carbon::now()->subMinutes(43200))->forceDelete();
|
|
|
|
$this->comment('Automated Purge Stats Complete');
|
|
}
|
|
}
|