Updated mass messaging to work with the queue system

This commit is contained in:
Dave Earley 2016-05-13 10:55:15 +01:00
parent d719a0c5a5
commit acbeffb0ef
2 changed files with 22 additions and 49 deletions

View File

@ -35,30 +35,27 @@ class AttendeeMailer extends Mailer
{
$event = $message_object->event;
$attendees = ($message_object->recipients == 0)
$attendees = ($message_object->recipients == 'all')
? $event->attendees // all attendees
: Attendee::where('ticket_id', '=', $message_object->recipients)->where('account_id', '=', $message_object->account_id)->get();
$toFields = [];
foreach($attendees as $attendee) {
$toFields[$attendee->email] = $attendee->full_name;
}
$data = [
'attendee' => $attendee,
'event' => $event,
'message_content' => $message_object->message,
'subject' => $message_object->subject,
'email_logo' => $attendee->event->organiser->full_logo_path,
];
/*
* Mandril lets us send the email to multiple people at once.
*/
Mail::send('Emails.messageAttendees', $data, function ($message) use ($toFields, $event, $message_object) {
$message->to($toFields)
->from(config('attendize.outgoing_email_noreply'), $event->organiser->name)
->replyTo($event->organiser->email, $event->organiser->name)
->subject($message_object->subject);
Mail::send('Emails.messageAttendees', $data, function ($message) use ($attendee, $data) {
$message->to($attendee->email, $attendee->full_name)
->from(config('attendize.outgoing_email_noreply'), $attendee->event->organiser->name)
->replyTo($attendee->event->organiser->email, $attendee->event->organiser->name)
->subject($data['subject']);
});
}
$message_object->is_sent = 1;
$message_object->sent_at = Carbon::now();

View File

@ -2,6 +2,7 @@
namespace App\Http\Controllers;
use App\Commands\MessageAttendeesCommand;
use App\Commands\OrderTicketsCommand;
use App\Commands\SendAttendeeTicketCommand;
use App\Models\Attendee;
@ -482,34 +483,9 @@ class EventAttendeesController extends MyBaseController
$message->recipients = $request->get('recipients');
}
$message->event_id = $event_id;
$message->sent_at = new \DateTime();
$message->save();
$query = Attendee::where("event_id", $event_id);
if ($request->get('recipients') != "all") {
$query->where('ticket_id', $request->get('recipients'));
}
$attendees = $query->get();
foreach($attendees as $attendee) {
$data = [
'attendee' => $attendee,
'message_content' => $request->get('message'),
'subject' => $request->get('subject'),
'event' => $attendee->event,
'email_logo' => $attendee->event->organiser->full_logo_path,
];
Mail::send('Emails.messageAttendees', $data, function ($message) use ($attendee, $data) {
$message->to($attendee->email, $attendee->full_name)
->from(config('attendize.outgoing_email_noreply'), $attendee->event->organiser->name)
->replyTo($attendee->event->organiser->email, $attendee->event->organiser->name)
->subject($data['subject']);
});
}
$this->dispatch(new MessageAttendeesCommand($message));
return response()->json([
'status' => 'success',