32 lines
892 B
PHP
Executable File
32 lines
892 B
PHP
Executable File
<?php
|
|
|
|
namespace App\Commands;
|
|
|
|
use CodeIgniter\CLI\BaseCommand;
|
|
use CodeIgniter\CLI\CLI;
|
|
use App\Models\PasswordResetRequestModel;
|
|
use CodeIgniter\I18n\Time;
|
|
|
|
class CleanupPasswordResets extends BaseCommand
|
|
{
|
|
protected $group = 'Maintenance';
|
|
protected $name = 'cleanup:password-resets';
|
|
protected $description = 'Delete password reset requests older than 30 days';
|
|
|
|
public function run(array $params)
|
|
{
|
|
$model = new PasswordResetRequestModel();
|
|
$threshold = Time::now()->subDays(30)->toDateTimeString();
|
|
|
|
$count = $model->where('requested_at <', $threshold)->delete();
|
|
|
|
CLI::write("Deleted $count old password reset request(s).", 'green');
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
Add this cron job to run every 24hrs
|
|
0 0 * * * /usr/bin/php /path/to/project/public/index.php cleanup:password-resets >> /path/to/project/writable/logs/cleanup.log 2>&1
|
|
|
|
*/ |