diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php deleted file mode 100644 index 46d0c1c..0000000 --- a/app/Console/Kernel.php +++ /dev/null @@ -1,74 +0,0 @@ -. - */ - -namespace App\Console; - -use App\Jobs\ProcessDueSuspensions; -use App\Jobs\ProcessExpiredAbsences; -use Illuminate\Console\Scheduling\Schedule; -use Illuminate\Foundation\Console\Kernel as ConsoleKernel; - -class Kernel extends ConsoleKernel -{ - /** - * The Artisan commands provided by your application. - * - * @var array - */ - protected $commands = [ - // - ]; - - /** - * Define the application's command schedule. - * - * @param \Illuminate\Console\Scheduling\Schedule $schedule - * @return void - */ - protected function schedule(Schedule $schedule) - { - $schedule->command('vote:evaluate') - ->daily(); - // Production value: Every day - - $schedule->job(new ProcessDueSuspensions) - ->daily(); - // Production value: Every day - // Development value: Every minute - - $schedule->job(new ProcessExpiredAbsences) - ->daily(); - // Production value: Every day - // Development value: Every minute - } - - /** - * Register the commands for the application. - * - * @return void - */ - protected function commands() - { - $this->load(__DIR__.'/Commands'); - - require base_path('routes/console.php'); - } -} diff --git a/app/Jobs/ExpiredInviteCleanup.php b/app/Jobs/ExpiredInviteCleanup.php new file mode 100644 index 0000000..d1f9e96 --- /dev/null +++ b/app/Jobs/ExpiredInviteCleanup.php @@ -0,0 +1,52 @@ +where('notified', false) + ->whereBetween('expiration', [Carbon::now(), Carbon::now()->addDay()]) + ->chunkById(100, function ($invites) { + foreach ($invites as $invite) { + Mail::to($invite->requestor_email) + ->send(new InviteExpiringSoon($invite)); + + $invite->notified = true; + $invite->save(); + } + }); + + // 2. Delete invites that have actually expired + Invitation::where('status', 'pending') + ->where('expiration', '<', Carbon::now()) + ->chunkById(100, function ($invites) { + foreach ($invites as $invite) { + $invite->delete(); + } + }); + } +} diff --git a/app/Jobs/InviteLifecycleCleanup.php b/app/Jobs/InviteLifecycleCleanup.php new file mode 100644 index 0000000..4beaf04 --- /dev/null +++ b/app/Jobs/InviteLifecycleCleanup.php @@ -0,0 +1,34 @@ +chunkById(100, function ($invites) { + foreach ($invites as $invite) { + $invite->delete(); + } + }); + } +} diff --git a/app/Mail/InviteExpiringSoon.php b/app/Mail/InviteExpiringSoon.php new file mode 100644 index 0000000..c459131 --- /dev/null +++ b/app/Mail/InviteExpiringSoon.php @@ -0,0 +1,56 @@ +invite = $invite; + } + + /** + * Get the message envelope. + */ + public function envelope(): Envelope + { + return new Envelope( + subject: 'Your invitation to . ' . config('app.name') . ' is expiring soon', + ); + } + + /** + * Get the message content definition. + */ + public function content(): Content + { + return new Content( + view: 'mail.invite-expiring', + ); + } + + /** + * Get the attachments for the message. + * + * @return array + */ + public function attachments(): array + { + return []; + } +} diff --git a/resources/views/mail/invite-expiring.blade.php b/resources/views/mail/invite-expiring.blade.php new file mode 100644 index 0000000..cc447c6 --- /dev/null +++ b/resources/views/mail/invite-expiring.blade.php @@ -0,0 +1,150 @@ + + + + + + Invite request expiring soon - {{ config('app.name') }} + + + + + + + + + + +
  +
+ + + + + + + + + + +
+ + + + +
+

Hello there! We're writing to let you know that your invite request to {{ config('app.name') }} is expiring in approximately 24 hours as of this email.

+

Be aware that, once your invite expires, you won't be able to activate it and therefore create a new account with it.

+

If you want to receive another invite (it's OK, emails get lost all the time), you may request another one day after it expires (ex. if it expired on Saturday, you can request another on Sunday).

+

If you believe you received this message in error, you can ignore it safely; otherwise, feel free to unsubscribe at the bottom of this email.

+ + +

Kind regards,

+

The {{ config('app.name') }} Team

+
+
+ + + + + + +
+
 
+ + diff --git a/routes/console.php b/routes/console.php index 8a63b38..661d0bb 100644 --- a/routes/console.php +++ b/routes/console.php @@ -19,10 +19,22 @@ * along with Raspberry Staff Manager. If not, see . */ +use App\Jobs\ExpiredInviteCleanup; +use App\Jobs\InviteLifecycleCleanup; +use App\Jobs\ProcessDueSuspensions; +use App\Jobs\ProcessExpiredAbsences; use Illuminate\Foundation\Inspiring; use Illuminate\Support\Facades\Artisan; +use Illuminate\Support\Facades\Schedule; Artisan::command('inspire', function () { $this->comment(Inspiring::quote()); })->describe('Display an inspiring quote'); + +Schedule::command('votes:evaluate')->daily(); +Schedule::job(new ProcessDueSuspensions())->daily(); +Schedule::job(new ProcessExpiredAbsences())->daily(); + +Schedule::job(new InviteLifecycleCleanup())->daily(); +Schedule::job(new ExpiredInviteCleanup())->daily();