- Add highly optimized Dockerfile with Nginx and PHP-FPM 8.4 - Add docker-compose.yml configured with Redis and MariaDB 10.11 - Implement entrypoint.sh and supervisord.conf for background workers - Refactor legacy IMAP scripts into scheduled Artisan Commands - Secure app by removing old routes with hardcoded basic auth credentials - Configure email attachments to use Laravel Storage instead of insecure public/tmp
44 lines
944 B
PHP
44 lines
944 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
class Log extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array
|
|
*/
|
|
protected $fillable = [
|
|
'user_id',
|
|
'ip',
|
|
'email',
|
|
];
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class);
|
|
}
|
|
|
|
public static function deleteLogsFromDB(): string
|
|
{
|
|
$cutoff = Date::now('UTC')->subMonths(3)->toDateTimeString();
|
|
$count = count(self::query()->where('created_at', '<', $cutoff)->latest()
|
|
->get());
|
|
|
|
if ($count > 0) {
|
|
self::query()->where('created_at', '<', $cutoff)->delete();
|
|
|
|
return "$count old log(s) deleted from the database.";
|
|
}
|
|
|
|
return 'No logs older than 3 months found.';
|
|
}
|
|
}
|