-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathSendPluginSubmissionReminders.php
More file actions
57 lines (43 loc) · 1.88 KB
/
SendPluginSubmissionReminders.php
File metadata and controls
57 lines (43 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
namespace App\Console\Commands;
use App\Enums\PluginStatus;
use App\Models\User;
use App\Notifications\PluginSubmissionReminder;
use Illuminate\Console\Command;
class SendPluginSubmissionReminders extends Command
{
protected $signature = 'plugins:send-submission-reminders
{--dry-run : Show what would be sent without actually sending}';
protected $description = 'Send a reminder to users with unapproved plugin submissions to finalize their configuration';
public function handle(): int
{
$dryRun = $this->option('dry-run');
if ($dryRun) {
$this->info('DRY RUN - No notifications will be sent');
}
$users = User::query()
->whereHas('plugins', function ($query) {
$query->whereIn('status', [PluginStatus::Draft, PluginStatus::Pending, PluginStatus::Rejected]);
})
->with(['plugins' => function ($query) {
$query->whereIn('status', [PluginStatus::Draft, PluginStatus::Pending, PluginStatus::Rejected])
->orderBy('name');
}])
->get();
$this->info("Found {$users->count()} user(s) with unapproved plugins");
$sent = 0;
foreach ($users as $user) {
$pluginNames = $user->plugins->pluck('name')->join(', ');
if ($dryRun) {
$this->line("Would send to: {$user->email} ({$user->plugins->count()} plugin(s): {$pluginNames})");
} else {
$user->notify(new PluginSubmissionReminder($user->plugins));
$this->line("Sent to: {$user->email} ({$user->plugins->count()} plugin(s): {$pluginNames})");
}
$sent++;
}
$this->newLine();
$this->info($dryRun ? "Would send: {$sent} notification(s)" : "Sent: {$sent} notification(s)");
return Command::SUCCESS;
}
}