diff --git a/metager/app/Console/Commands/TruncateLogs.php b/metager/app/Console/Commands/TruncateLogs.php new file mode 100644 index 0000000000000000000000000000000000000000..6be63a97ac58621343227e7db58a55a2436da3ee --- /dev/null +++ b/metager/app/Console/Commands/TruncateLogs.php @@ -0,0 +1,48 @@ +<?php + +namespace App\Console\Commands; + +use Illuminate\Console\Command; + +class TruncateLogs extends Command +{ + /** + * The name and signature of the console command. + * + * @var string + */ + protected $signature = 'logs:truncate'; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Truncates Logs that should only be kept for a day'; + + /** + * Execute the console command. + * + * @return int + */ + public function handle() + { + $log_files = [ + \storage_path("logs/metager/bv_fail.csv"), + \storage_path("logs/metager/captcha_show.csv"), + \storage_path("logs/metager/captcha_solve.csv"), + ]; + foreach ($log_files as $log_file) { + if (\file_exists($log_file) && \is_writable($log_file)) { + $fp = fopen($log_file, "r+"); + try { + ftruncate($fp, 0); + } finally { + fclose($fp); + } + } + } + + return 0; + } +} diff --git a/metager/app/Console/Kernel.php b/metager/app/Console/Kernel.php index 3886053b253243b5b893243f0819e54e48e0110d..d5f865445b0c1f95bb28bd8a8adc508d2c74ca01 100644 --- a/metager/app/Console/Kernel.php +++ b/metager/app/Console/Kernel.php @@ -20,6 +20,7 @@ class Kernel extends ConsoleKernel $schedule->command('requests:gather')->everyFifteenMinutes(); $schedule->command('requests:useragents')->everyFiveMinutes(); $schedule->command('logs:gather')->everyMinute(); + $schedule->command('logs:truncate')->daily()->onOneServer(); $schedule->command('spam:load')->everyMinute(); $schedule->command('load:affiliate-blacklist')->everyMinute(); $schedule->command('affilliates:store')->everyMinute()