add notifications logic and add support of both JWT and Sanctum
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Commands;
|
||||
|
||||
use CodeIgniter\CLI\BaseCommand;
|
||||
use CodeIgniter\CLI\CLI;
|
||||
use App\Models\NotificationModel;
|
||||
|
||||
class CleanupExpiredNotifications extends BaseCommand
|
||||
{
|
||||
protected $group = 'Maintenance';
|
||||
protected $name = 'notifications:cleanup';
|
||||
protected $description = 'Deletes expired notifications from the database.';
|
||||
|
||||
public function run(array $params)
|
||||
{
|
||||
$model = new NotificationModel();
|
||||
|
||||
// Fetch expired notifications
|
||||
$expired = $model->where('expires_at IS NOT NULL')
|
||||
->where('expires_at < NOW()')
|
||||
->findAll();
|
||||
|
||||
if (empty($expired)) {
|
||||
CLI::write("ℹ No expired notifications found to soft delete.", 'yellow');
|
||||
return;
|
||||
}
|
||||
|
||||
$count = 0;
|
||||
foreach ($expired as $note) {
|
||||
$model->delete($note['id']); // Soft delete
|
||||
$count++;
|
||||
}
|
||||
|
||||
CLI::write("✅ Soft-deleted {$count} expired notifications.", 'green');
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user