feat: change log table with retention cron and limits option
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01At3V6SjwbMe6eMzVGW3Hs7
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP\ChangeLog;
|
||||
|
||||
use LIT\MCP\Limits;
|
||||
|
||||
/**
|
||||
* Daily WP-Cron job that removes log rows older than the configured retention.
|
||||
*/
|
||||
final class ChangeLogCleanup
|
||||
{
|
||||
public const HOOK = 'lit_mcp_log_cleanup';
|
||||
|
||||
public function __construct(private ChangeLog $log, private Limits $limits)
|
||||
{
|
||||
}
|
||||
|
||||
public function register(): void
|
||||
{
|
||||
add_action(self::HOOK, [$this, 'run']);
|
||||
add_action('init', [$this, 'ensureScheduled']);
|
||||
}
|
||||
|
||||
public function ensureScheduled(): void
|
||||
{
|
||||
if (wp_next_scheduled(self::HOOK) === false) {
|
||||
wp_schedule_event(time() + 3600, 'daily', self::HOOK);
|
||||
}
|
||||
}
|
||||
|
||||
public function run(): void
|
||||
{
|
||||
$this->log->purgeOlderThan($this->limits->logRetentionDays());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user