Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix reminders not being sent #2505

Merged
merged 2 commits into from
Mar 9, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Enhancements:

Fixes:

* Fix reminders not being sent
* Fix setting deceased information with removing date and reminder
* Fix contact information update
* Fix adding people on activity create and update
Expand Down
4 changes: 2 additions & 2 deletions app/Jobs/Reminder/NotifyUserAboutReminder.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ private function getMessage()
{
switch ($this->reminderOutbox->nature) {
case 'reminder':
return new UserReminded($this->reminderOutbox);
return new UserReminded($this->reminderOutbox->reminder);
case 'notification':
return new UserNotified($this->reminderOutbox);
return new UserNotified($this->reminderOutbox->reminder, $this->reminderOutbox->notification_number_days_before);
default:
break;
}
Expand Down
26 changes: 14 additions & 12 deletions app/Notifications/UserNotified.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
use App\Helpers\DateHelper;
use Illuminate\Bus\Queueable;
use App\Models\Contact\Contact;
use App\Models\Contact\Reminder;
use Illuminate\Support\Facades\App;
use App\Interfaces\MailNotification;
use App\Models\Contact\ReminderOutbox;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -21,18 +21,20 @@ class UserNotified extends LaravelNotification implements ShouldQueue, MailNotif
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* @var ReminderOutbox
* @var Reminder
*/
public $reminderOutbox;
public $reminder;
public $numberDaysBefore;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(ReminderOutbox $reminderOutbox)
public function __construct(Reminder $reminder, $numberDaysBefore)
{
$this->reminderOutbox = $reminderOutbox;
$this->reminder = $reminder;
$this->numberDaysBefore = $numberDaysBefore;
}

/**
Expand All @@ -56,22 +58,22 @@ public function toMail(User $user) : MailMessage
App::setLocale($user->locale);

$contact = Contact::where('account_id', $user->account_id)
->findOrFail($this->reminderOutbox->reminder->contact_id);
->findOrFail($this->reminder->contact_id);

$message = (new MailMessage)
->subject(trans('mail.subject_line', ['contact' => $contact->name]))
->greeting(trans('mail.greetings', ['username' => $user->first_name]))
->line(trans_choice('mail.notification_description', $this->reminderOutbox->notification_number_days_before, [
'count' => $this->reminderOutbox->notification_number_days_before,
'date' => DateHelper::getShortDate($this->reminderOutbox->reminder->calculateNextExpectedDate()),
->line(trans_choice('mail.notification_description', $this->numberDaysBefore, [
'count' => $this->numberDaysBefore,
'date' => DateHelper::getShortDate($this->reminder->calculateNextExpectedDate()),
]))
->line($this->reminderOutbox->reminder->title)
->line($this->reminder->title)
->line(trans('mail.for', ['name' => $contact->name]))
->action(trans('mail.footer_contact_info2', ['name' => $contact->name]), $contact->getLink());

if (! is_null($this->reminderOutbox->reminder->description)) {
if (! is_null($this->reminder->description)) {
$message = $message
->line(trans('mail.comment', ['comment' => $this->reminderOutbox->reminder->description]));
->line(trans('mail.comment', ['comment' => $this->reminder->description]));
}

return $message;
Expand Down
18 changes: 9 additions & 9 deletions app/Notifications/UserReminded.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
use App\Models\User\User;
use Illuminate\Bus\Queueable;
use App\Models\Contact\Contact;
use App\Models\Contact\Reminder;
use Illuminate\Support\Facades\App;
use App\Interfaces\MailNotification;
use App\Models\Contact\ReminderOutbox;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
Expand All @@ -20,18 +20,18 @@ class UserReminded extends LaravelNotification implements ShouldQueue, MailNotif
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* @var ReminderOutbox
* @var Reminder
*/
public $reminderOutbox;
public $reminder;

/**
* Create a new message instance.
*
* @return void
*/
public function __construct(ReminderOutbox $reminderOutbox)
public function __construct(Reminder $reminder)
{
$this->reminderOutbox = $reminderOutbox;
$this->reminder = $reminder;
}

/**
Expand All @@ -55,18 +55,18 @@ public function toMail(User $user) : MailMessage
App::setLocale($user->locale);

$contact = Contact::where('account_id', $user->account_id)
->findOrFail($this->reminderOutbox->reminder->contact_id);
->findOrFail($this->reminder->contact_id);

$message = (new MailMessage)
->subject(trans('mail.subject_line', ['contact' => $contact->name]))
->greeting(trans('mail.greetings', ['username' => $user->first_name]))
->line(trans('mail.want_reminded_of', ['reason' => $this->reminderOutbox->reminder->title]))
->line(trans('mail.want_reminded_of', ['reason' => $this->reminder->title]))
->line(trans('mail.for', ['name' => $contact->name]))
->action(trans('mail.footer_contact_info2', ['name' => $contact->name]), $contact->getLink());

if (! is_null($this->reminderOutbox->reminder->description)) {
if (! is_null($this->reminder->description)) {
$message = $message
->line(trans('mail.comment', ['comment' => $this->reminderOutbox->reminder->description]));
->line(trans('mail.comment', ['comment' => $this->reminder->description]));
}

return $message;
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Jobs/Reminder/NotifyUserAboutReminderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,13 @@ public function test_it_sends_a_reminder_to_a_user()
Notification::assertSentTo(
$user,
UserReminded::class,
function ($notification, $channels) use ($reminderOutbox, $user, $contact) {
function ($notification, $channels) use ($reminderOutbox, $reminder, $user, $contact) {
$mailData = $notification->toMail($user)->toArray();
$this->assertEquals("Reminder for {$contact->name}", $mailData['subject']);
$this->assertEquals("Hi {$user->first_name}", $mailData['greeting']);
$this->assertContains("You wanted to be reminded of {$reminderOutbox->reminder->title}", $mailData['introLines']);

return $notification->reminderOutbox->id === $reminderOutbox->id;
return $notification->reminder->id === $reminder->id;
}
);
}
Expand Down Expand Up @@ -99,13 +99,13 @@ public function test_it_sends_a_notification_to_a_user()
Notification::assertSentTo(
$user,
UserNotified::class,
function ($notification, $channels) use ($reminderOutbox, $user, $contact) {
function ($notification, $channels) use ($reminderOutbox, $reminder, $user, $contact) {
$mailData = $notification->toMail($user)->toArray();
$this->assertEquals("Reminder for {$contact->name}", $mailData['subject']);
$this->assertEquals("Hi {$user->first_name}", $mailData['greeting']);
$this->assertContains('In days (on Jan 01, 2018), the following event will happen:', $mailData['introLines']);

return $notification->reminderOutbox->id === $reminderOutbox->id;
return $notification->reminder->id === $reminder->id;
}
);
}
Expand Down