Re-enable queue code

This commit is contained in:
Hillel Coren 2017-02-19 14:05:38 +02:00
parent 2d322bf2b3
commit 6ae4e63184
3 changed files with 29 additions and 71 deletions

View File

@ -401,13 +401,8 @@ class InvoiceController extends BaseController
if ($invoice->is_recurring) {
$response = $this->emailRecurringInvoice($invoice);
} else {
// TODO remove this with Laravel 5.3 (https://github.com/invoiceninja/invoiceninja/issues/1303)
if (config('queue.default') === 'sync') {
$response = app('App\Ninja\Mailers\ContactMailer')->sendInvoice($invoice, $reminder, $pdfUpload, $template);
} else {
$this->dispatch(new SendInvoiceEmail($invoice, $reminder, $pdfUpload, $template));
$response = true;
}
$this->dispatch(new SendInvoiceEmail($invoice, $reminder, $pdfUpload, $template));
$response = true;
}
if ($response === true) {
@ -438,13 +433,8 @@ class InvoiceController extends BaseController
if ($invoice->isPaid()) {
return true;
} else {
// TODO remove this with Laravel 5.3 (https://github.com/invoiceninja/invoiceninja/issues/1303)
if (config('queue.default') === 'sync') {
return app('App\Ninja\Mailers\ContactMailer')->sendInvoice($invoice);
} else {
$this->dispatch(new SendInvoiceEmail($invoice));
return true;
}
$this->dispatch(new SendInvoiceEmail($invoice));
return true;
}
}

View File

@ -1,49 +1,20 @@
<?php
<?php namespace App\Listeners;
namespace App\Listeners;
use App\Events\InvoiceInvitationWasViewed;
use App\Events\InvoiceWasEmailed;
use App\Events\PaymentWasCreated;
use App\Events\QuoteInvitationWasApproved;
use App\Events\QuoteInvitationWasViewed;
use App\Events\QuoteWasEmailed;
use App\Ninja\Mailers\ContactMailer;
use App\Ninja\Mailers\UserMailer;
use App\Services\PushService;
use App\Events\InvoiceInvitationWasViewed;
use App\Events\QuoteInvitationWasViewed;
use App\Events\QuoteInvitationWasApproved;
use App\Events\PaymentWasCreated;
use App\Jobs\SendPaymentEmail;
use App\Jobs\SendNotificationEmail;
use App\Jobs\SendPushNotification;
/**
* Class NotificationListener.
* Class NotificationListener
*/
class NotificationListener
{
/**
* @var UserMailer
*/
protected $userMailer;
/**
* @var ContactMailer
*/
protected $contactMailer;
/**
* @var PushService
*/
protected $pushService;
/**
* NotificationListener constructor.
*
* @param UserMailer $userMailer
* @param ContactMailer $contactMailer
* @param PushService $pushService
*/
public function __construct(UserMailer $userMailer, ContactMailer $contactMailer, PushService $pushService)
{
$this->userMailer = $userMailer;
$this->contactMailer = $contactMailer;
$this->pushService = $pushService;
}
/**
* @param $invoice
* @param $type
@ -51,9 +22,11 @@ class NotificationListener
*/
private function sendEmails($invoice, $type, $payment = null)
{
foreach ($invoice->account->users as $user) {
if ($user->{"notify_{$type}"}) {
$this->userMailer->sendNotification($user, $invoice, $type, $payment);
foreach ($invoice->account->users as $user)
{
if ($user->{"notify_{$type}"})
{
dispatch(new SendNotificationEmail($user, $invoice, $type, $payment));
}
}
}
@ -64,7 +37,7 @@ class NotificationListener
public function emailedInvoice(InvoiceWasEmailed $event)
{
$this->sendEmails($event->invoice, 'sent');
$this->pushService->sendNotification($event->invoice, 'sent');
dispatch(new SendPushNotification($event->invoice, 'sent'));
}
/**
@ -73,7 +46,7 @@ class NotificationListener
public function emailedQuote(QuoteWasEmailed $event)
{
$this->sendEmails($event->quote, 'sent');
$this->pushService->sendNotification($event->quote, 'sent');
dispatch(new SendPushNotification($event->quote, 'sent'));
}
/**
@ -81,12 +54,12 @@ class NotificationListener
*/
public function viewedInvoice(InvoiceInvitationWasViewed $event)
{
if (! floatval($event->invoice->balance)) {
if ( ! floatval($event->invoice->balance)) {
return;
}
$this->sendEmails($event->invoice, 'viewed');
$this->pushService->sendNotification($event->invoice, 'viewed');
dispatch(new SendPushNotification($event->invoice, 'viewed'));
}
/**
@ -99,7 +72,7 @@ class NotificationListener
}
$this->sendEmails($event->quote, 'viewed');
$this->pushService->sendNotification($event->quote, 'viewed');
dispatch(new SendPushNotification($event->quote, 'viewed'));
}
/**
@ -108,7 +81,7 @@ class NotificationListener
public function approvedQuote(QuoteInvitationWasApproved $event)
{
$this->sendEmails($event->quote, 'approved');
$this->pushService->sendNotification($event->quote, 'approved');
dispatch(new SendPushNotification($event->quote, 'approved'));
}
/**
@ -117,13 +90,13 @@ class NotificationListener
public function createdPayment(PaymentWasCreated $event)
{
// only send emails for online payments
if (! $event->payment->account_gateway_id) {
if ( ! $event->payment->account_gateway_id) {
return;
}
$this->contactMailer->sendPaymentConfirmation($event->payment);
$this->sendEmails($event->payment->invoice, 'paid', $event->payment);
$this->pushService->sendNotification($event->payment->invoice, 'paid');
dispatch(new SendPaymentEmail($event->payment));
dispatch(new SendPushNotification($event->payment->invoice, 'paid'));
}
}

View File

@ -789,12 +789,7 @@ class InvoiceRepository extends BaseRepository
*/
public function emailInvoice(Invoice $invoice)
{
// TODO remove this with Laravel 5.3 (https://github.com/invoiceninja/invoiceninja/issues/1303)
if (config('queue.default') === 'sync') {
app('App\Ninja\Mailers\ContactMailer')->sendInvoice($invoice);
} else {
dispatch(new SendInvoiceEmail($invoice));
}
dispatch(new SendInvoiceEmail($invoice));
}
/**