![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/inventory.corals.io/vendor/spatie/laravel-activitylog/src/ |
<?php namespace Spatie\Activitylog; use Carbon\Carbon; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Builder; class CleanActivitylogCommand extends Command { 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.}'; protected $description = 'Clean up old records from the activity log.'; public function handle() { $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::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!'); } }