![]() Server : Apache/2.4.62 (Unix) OpenSSL/1.0.2k-fips System : Linux server1.richineiserver.com 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : fdshops ( 1003) PHP Version : 8.2.21 Disable Function : NONE Directory : /home/fdshops/public_html/vendor/spatie/laravel-activitylog/src/ |
<?php namespace Spatie\Activitylog; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Console\ConfirmableTrait; use Illuminate\Database\Eloquent\Builder; class CleanActivitylogCommand extends Command { use ConfirmableTrait; protected $signature = 'activitylog:clean {log? : (optional) The log name that will be cleaned.} {--days= : (optional) Records older than this number of days will be cleaned.} {--force : (optional) Force the operation to run when in production.}'; protected $description = 'Clean up old records from the activity log.'; public function handle() { if (! $this->confirmToProceed()) { return 1; } $this->comment('Cleaning activity log...'); $log = $this->argument('log'); $maxAgeInDays = $this->option('days') ?? config('activitylog.delete_records_older_than_days'); $cutOffDate = Carbon::now()->subDays($maxAgeInDays)->format('Y-m-d H:i:s'); $activity = ActivitylogServiceProvider::getActivityModelInstance(); $amountDeleted = $activity::query() ->where('created_at', '<', $cutOffDate) ->when($log !== null, function (Builder $query) use ($log) { $query->inLog($log); }) ->delete(); $this->info("Deleted {$amountDeleted} record(s) from the activity log."); $this->comment('All done!'); } }