wn-easyaudit-plugin icon indicating copy to clipboard operation
wn-easyaudit-plugin copied to clipboard

Audit log grows infinitly

Open AIC-BV opened this issue 1 year ago • 3 comments

As you said before, the audit log keeps growing and has no automatic maintenance. Adding an automatic removal of logs older than X days (30, 60, ...) could be a nice addition. Can probably add this in my own cronjobs too

Just wanted to write it down somewhere x)

AIC-BV avatar Oct 23 '24 13:10 AIC-BV

@AIC-BV just to double check, did you purchase a license for this plugin? 😉

I think I'll start adding the usernames that have paid to the license file to keep track for now until we finish the marketplace and then I'll move license management to there instead.

LukeTowers avatar Oct 25 '24 19:10 LukeTowers

Yes you know I did it using Paypal x)

AIC-BV avatar Oct 28 '24 08:10 AIC-BV

That's what I thought, I just couldn't remember for sure, hence why I need to start logging the purchases 😂

LukeTowers avatar Oct 28 '24 09:10 LukeTowers

Added a cron to clean it up

use LukeTowers\EasyAudit\Models\Activity as ActivityLog;
$schedule->call(function() {

    // get all activity logs older than three months
    $logs = ActivityLog::select('id')
                       ->whereDate('created_at', '<=', Carbon::now()->subMonths(3))
                       ->get();

    // delete each log
    $amount = 0;
    foreach ($logs as $log) {
        $amount++;
        $log->delete();
    }

    trace_log('--- 1st day of the month at 5:00 AM: Deleted ' . $amount . ' items. (Activity Logs)');

})->timezone('Europe/Brussels')->cron('0 5 1 * *');

AIC-BV avatar Jul 29 '25 11:07 AIC-BV

@AIC-BV 🫨

I'm just waiting on https://github.com/wintercms/winter/pull/1263 to be finished and then there will be a much nicer solution

LukeTowers avatar Jul 31 '25 04:07 LukeTowers