Enable email notifications to all active subscribers
This commit is contained in:
parent
d15a2fcb30
commit
81aaa22875
1 changed files with 40 additions and 20 deletions
|
|
@ -144,39 +144,59 @@ class DocketEntryController extends Controller
|
|||
}
|
||||
|
||||
/**
|
||||
* Send email notifications to subscribers.
|
||||
* TESTING MODE: Only sends to chris@deafgain.org
|
||||
* Send email notifications to all active subscribers.
|
||||
*/
|
||||
private function sendEmailNotifications(DocketEntry $entry): void
|
||||
{
|
||||
try {
|
||||
// TESTING MODE: Only send to chris@deafgain.org
|
||||
// In production, this would query all active subscribers
|
||||
$testEmail = 'chris@deafgain.org';
|
||||
$testToken = 'test-unsubscribe-token'; // Placeholder for testing
|
||||
// Get all active subscribers
|
||||
$subscribers = Subscription::where('is_active', true)->get();
|
||||
|
||||
if ($subscribers->isEmpty()) {
|
||||
Log::info('No active subscribers to notify', [
|
||||
'entry_id' => $entry->id,
|
||||
]);
|
||||
return;
|
||||
}
|
||||
|
||||
Log::info('Sending email notification for new docket entry', [
|
||||
Log::info('Sending email notifications for new docket entry', [
|
||||
'entry_id' => $entry->id,
|
||||
'entry_title' => $entry->title,
|
||||
'recipient' => $testEmail,
|
||||
'subscriber_count' => $subscribers->count(),
|
||||
]);
|
||||
|
||||
Mail::to($testEmail)->send(new NewDocketEntryNotification($entry, $testToken));
|
||||
$successCount = 0;
|
||||
$failureCount = 0;
|
||||
|
||||
Log::info('Email notification sent successfully', [
|
||||
foreach ($subscribers as $subscriber) {
|
||||
try {
|
||||
Mail::to($subscriber->email)->send(
|
||||
new NewDocketEntryNotification($entry, $subscriber->unsubscribe_token)
|
||||
);
|
||||
$successCount++;
|
||||
|
||||
Log::debug('Email sent to subscriber', [
|
||||
'entry_id' => $entry->id,
|
||||
'subscriber_email' => $subscriber->email,
|
||||
]);
|
||||
} catch (\Exception $e) {
|
||||
$failureCount++;
|
||||
Log::error('Failed to send email to subscriber', [
|
||||
'entry_id' => $entry->id,
|
||||
'subscriber_email' => $subscriber->email,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
Log::info('Email notification batch complete', [
|
||||
'entry_id' => $entry->id,
|
||||
'recipient' => $testEmail,
|
||||
'success_count' => $successCount,
|
||||
'failure_count' => $failureCount,
|
||||
'total_subscribers' => $subscribers->count(),
|
||||
]);
|
||||
|
||||
// Production code (commented out for testing):
|
||||
// $subscribers = Subscription::where('is_active', true)->get();
|
||||
// foreach ($subscribers as $subscriber) {
|
||||
// Mail::to($subscriber->email)->send(
|
||||
// new NewDocketEntryNotification($entry, $subscriber->unsubscribe_token)
|
||||
// );
|
||||
// }
|
||||
} catch (\Exception $e) {
|
||||
Log::error('Failed to send email notification', [
|
||||
Log::error('Failed to send email notifications', [
|
||||
'entry_id' => $entry->id,
|
||||
'error' => $e->getMessage(),
|
||||
]);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue