Files
athenahr/app/Jobs/InviteLifecycleCleanup.php
Miguel Nogueira d48b35e845 fix: make sure approved invites are not deleted daily
even though people would have time to use approved invites (24 hrs at least), it would be better to delete them when they expire instead.

Signed-off-by: Miguel Nogueira <me@nogueira.codes>
2025-08-10 11:01:24 +01:00

43 lines
1.0 KiB
PHP

<?php
namespace App\Jobs;
use App\Invitation;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Queue\Queueable;
use Illuminate\Support\Facades\Log;
// General Housekeeping Job: Drop Approved and Completed Invites
class InviteLifecycleCleanup implements ShouldQueue
{
use Queueable;
/**
* Create a new job instance.
*/
public function __construct()
{
//
}
/**
* Execute the job.
*/
public function handle(): void
{
Log::info("Invite lifecycle: processing completed invites.");
$deleted = 0;
Invitation::where('status', '=', 'completed')
->chunkById(100, function ($invites) use (&$deleted) {
foreach ($invites as $invite) {
Log::debug("Deleted invite {$invite->invitation_code} for {$invite->requestor_email}.");
$invite->delete();
$deleted++;
}
});
Log::info("Deleted {$deleted} completed invitations.");
}
}