mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Support using queues for emails
This commit is contained in:
parent
6880e3abd2
commit
dc034d06dd
@ -3,7 +3,7 @@
|
|||||||
if (!defined('APP_NAME'))
|
if (!defined('APP_NAME'))
|
||||||
{
|
{
|
||||||
define('APP_NAME', env('APP_NAME', 'Invoice Ninja'));
|
define('APP_NAME', env('APP_NAME', 'Invoice Ninja'));
|
||||||
define('CONTACT_EMAIL', env('MAIL_FROM_ADDRESS'));
|
define('CONTACT_EMAIL', env('MAIL_FROM_ADDRESS', env('MAIL_USERNAME')));
|
||||||
define('CONTACT_NAME', env('MAIL_FROM_NAME'));
|
define('CONTACT_NAME', env('MAIL_FROM_NAME'));
|
||||||
define('SITE_URL', env('APP_URL'));
|
define('SITE_URL', env('APP_URL'));
|
||||||
|
|
||||||
|
@ -19,7 +19,7 @@ use App\Models\Payment;
|
|||||||
use App\Models\TaxRate;
|
use App\Models\TaxRate;
|
||||||
use App\Models\InvoiceDesign;
|
use App\Models\InvoiceDesign;
|
||||||
use App\Models\Activity;
|
use App\Models\Activity;
|
||||||
use App\Ninja\Mailers\ContactMailer as Mailer;
|
use App\Jobs\SendInvoiceEmail;
|
||||||
use App\Ninja\Repositories\InvoiceRepository;
|
use App\Ninja\Repositories\InvoiceRepository;
|
||||||
use App\Ninja\Repositories\ClientRepository;
|
use App\Ninja\Repositories\ClientRepository;
|
||||||
use App\Ninja\Repositories\DocumentRepository;
|
use App\Ninja\Repositories\DocumentRepository;
|
||||||
@ -33,7 +33,6 @@ use App\Http\Requests\UpdateInvoiceRequest;
|
|||||||
|
|
||||||
class InvoiceController extends BaseController
|
class InvoiceController extends BaseController
|
||||||
{
|
{
|
||||||
protected $mailer;
|
|
||||||
protected $invoiceRepo;
|
protected $invoiceRepo;
|
||||||
protected $clientRepo;
|
protected $clientRepo;
|
||||||
protected $documentRepo;
|
protected $documentRepo;
|
||||||
@ -42,11 +41,10 @@ class InvoiceController extends BaseController
|
|||||||
protected $recurringInvoiceService;
|
protected $recurringInvoiceService;
|
||||||
protected $entityType = ENTITY_INVOICE;
|
protected $entityType = ENTITY_INVOICE;
|
||||||
|
|
||||||
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService, DocumentRepository $documentRepo, RecurringInvoiceService $recurringInvoiceService, PaymentService $paymentService)
|
public function __construct(InvoiceRepository $invoiceRepo, ClientRepository $clientRepo, InvoiceService $invoiceService, DocumentRepository $documentRepo, RecurringInvoiceService $recurringInvoiceService, PaymentService $paymentService)
|
||||||
{
|
{
|
||||||
// parent::__construct();
|
// parent::__construct();
|
||||||
|
|
||||||
$this->mailer = $mailer;
|
|
||||||
$this->invoiceRepo = $invoiceRepo;
|
$this->invoiceRepo = $invoiceRepo;
|
||||||
$this->clientRepo = $clientRepo;
|
$this->clientRepo = $clientRepo;
|
||||||
$this->invoiceService = $invoiceService;
|
$this->invoiceService = $invoiceService;
|
||||||
@ -459,7 +457,8 @@ class InvoiceController extends BaseController
|
|||||||
if ($invoice->is_recurring) {
|
if ($invoice->is_recurring) {
|
||||||
$response = $this->emailRecurringInvoice($invoice);
|
$response = $this->emailRecurringInvoice($invoice);
|
||||||
} else {
|
} else {
|
||||||
$response = $this->mailer->sendInvoice($invoice, false, $pdfUpload);
|
$this->dispatch(new SendInvoiceEmail($invoice, false, $pdfUpload));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($response === true) {
|
if ($response === true) {
|
||||||
@ -489,7 +488,8 @@ class InvoiceController extends BaseController
|
|||||||
if ($invoice->isPaid()) {
|
if ($invoice->isPaid()) {
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
return $this->mailer->sendInvoice($invoice);
|
$this->dispatch(new SendInvoiceEmail($invoice));
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
47
app/Jobs/Job.php
Normal file
47
app/Jobs/Job.php
Normal file
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Ninja\Mailers\ContactMailer;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Monolog\Logger;
|
||||||
|
|
||||||
|
abstract class Job
|
||||||
|
{
|
||||||
|
use Queueable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The name of the job.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $jobName;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a job failure.
|
||||||
|
*
|
||||||
|
* @param ContactMailer $mailer
|
||||||
|
* @param Logger $logger
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
protected function failed(ContactMailer $mailer, Logger $logger)
|
||||||
|
{
|
||||||
|
if(config('queue.failed.notify_email')) {
|
||||||
|
$mailer->sendTo(
|
||||||
|
config('queue.failed.notify_email'),
|
||||||
|
config('mail.from.address'),
|
||||||
|
config('mail.from.name'),
|
||||||
|
config('queue.failed.notify_subject', trans('texts.job_failed', ['name'=>$this->jobName])),
|
||||||
|
'job_failed',
|
||||||
|
[
|
||||||
|
'name' => $this->jobName,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
$logger->error(
|
||||||
|
trans('texts.job_failed', ['name' => $this->jobName])
|
||||||
|
);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
73
app/Jobs/SendInvoiceEmail.php
Normal file
73
app/Jobs/SendInvoiceEmail.php
Normal file
@ -0,0 +1,73 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs;
|
||||||
|
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Ninja\Mailers\ContactMailer;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Monolog\Logger;
|
||||||
|
use Carbon;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class SendInvoiceEmail
|
||||||
|
*/
|
||||||
|
class SendInvoiceEmail extends Job implements ShouldQueue
|
||||||
|
{
|
||||||
|
use InteractsWithQueue, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var Invoice
|
||||||
|
*/
|
||||||
|
protected $invoice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
protected $reminder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $pdfString;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*
|
||||||
|
* @param Invoice $invoice
|
||||||
|
* @param string $pdf
|
||||||
|
* @param bool $reminder
|
||||||
|
*/
|
||||||
|
public function __construct(Invoice $invoice, $reminder = false, $pdfString = false)
|
||||||
|
{
|
||||||
|
$this->invoice = $invoice;
|
||||||
|
$this->reminder = $reminder;
|
||||||
|
$this->pdfString = $pdfString;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*
|
||||||
|
* @param ContactMailer $mailer
|
||||||
|
*/
|
||||||
|
public function handle(ContactMailer $mailer)
|
||||||
|
{
|
||||||
|
$mailer->sendInvoice($this->invoice, $this->reminder, $this->pdfString);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a job failure.
|
||||||
|
*
|
||||||
|
* @param ContactMailer $mailer
|
||||||
|
* @param Logger $logger
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
public function failed(ContactMailer $mailer, Logger $logger)
|
||||||
|
{
|
||||||
|
$this->jobName = $this->job->getName();
|
||||||
|
|
||||||
|
parent::failed($mailer, $logger);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
}
|
@ -119,7 +119,7 @@ return [
|
|||||||
*/
|
*/
|
||||||
'Illuminate\Auth\AuthServiceProvider',
|
'Illuminate\Auth\AuthServiceProvider',
|
||||||
'Collective\Html\HtmlServiceProvider',
|
'Collective\Html\HtmlServiceProvider',
|
||||||
'Collective\Bus\BusServiceProvider',
|
'Illuminate\Bus\BusServiceProvider',
|
||||||
'Illuminate\Cache\CacheServiceProvider',
|
'Illuminate\Cache\CacheServiceProvider',
|
||||||
'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
|
'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
|
||||||
'Illuminate\Cookie\CookieServiceProvider',
|
'Illuminate\Cookie\CookieServiceProvider',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user