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,59 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace LIT\MCP;
|
||||
|
||||
/**
|
||||
* Admin-configurable limits (settings tab "Limits", spec §8.4).
|
||||
*/
|
||||
final class Limits
|
||||
{
|
||||
public const OPTION = 'lit_mcp_limits';
|
||||
public const DEFAULTS = ['upload_mb' => 5, 'log_retention_days' => 90, 'snapshot_count' => 20];
|
||||
private const BOUNDS = ['upload_mb' => [1, 100], 'log_retention_days' => [1, 3650], 'snapshot_count' => [1, 100]];
|
||||
|
||||
public function uploadBytes(): int
|
||||
{
|
||||
return $this->uploadMegabytes() * 1024 * 1024;
|
||||
}
|
||||
|
||||
public function uploadMegabytes(): int
|
||||
{
|
||||
return $this->all()['upload_mb'];
|
||||
}
|
||||
|
||||
public function logRetentionDays(): int
|
||||
{
|
||||
return $this->all()['log_retention_days'];
|
||||
}
|
||||
|
||||
public function snapshotCount(): int
|
||||
{
|
||||
return $this->all()['snapshot_count'];
|
||||
}
|
||||
|
||||
/** @return array{upload_mb: int, log_retention_days: int, snapshot_count: int} */
|
||||
public function all(): array
|
||||
{
|
||||
return self::sanitize(get_option(self::OPTION, []));
|
||||
}
|
||||
|
||||
/**
|
||||
* Settings API sanitize callback: always returns all keys, clamped to their bounds.
|
||||
*
|
||||
* @return array{upload_mb: int, log_retention_days: int, snapshot_count: int}
|
||||
*/
|
||||
public static function sanitize(mixed $input): array
|
||||
{
|
||||
$input = is_array($input) ? $input : [];
|
||||
$clean = self::DEFAULTS;
|
||||
foreach (self::BOUNDS as $key => [$min, $max]) {
|
||||
if (isset($input[$key]) && is_numeric($input[$key])) {
|
||||
$clean[$key] = max($min, min($max, (int) $input[$key]));
|
||||
}
|
||||
}
|
||||
|
||||
return $clean;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user