1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Use queues in send reminders command

This commit is contained in:
Hillel Coren 2018-03-27 15:56:04 +03:00
parent d2e39f9c6c
commit 497154becb

View File

@ -6,9 +6,10 @@ use App\Libraries\CurlUtils;
use Carbon; use Carbon;
use Str; use Str;
use Cache; use Cache;
use Exception;
use App\Jobs\SendInvoiceEmail;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Currency; use App\Models\Currency;
use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Mailers\UserMailer; use App\Ninja\Mailers\UserMailer;
use App\Ninja\Repositories\AccountRepository; use App\Ninja\Repositories\AccountRepository;
use App\Ninja\Repositories\InvoiceRepository; use App\Ninja\Repositories\InvoiceRepository;
@ -33,11 +34,6 @@ class SendReminders extends Command
*/ */
protected $description = 'Send reminder emails'; protected $description = 'Send reminder emails';
/**
* @var Mailer
*/
protected $mailer;
/** /**
* @var InvoiceRepository * @var InvoiceRepository
*/ */
@ -55,11 +51,10 @@ class SendReminders extends Command
* @param InvoiceRepository $invoiceRepo * @param InvoiceRepository $invoiceRepo
* @param accountRepository $accountRepo * @param accountRepository $accountRepo
*/ */
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, AccountRepository $accountRepo, UserMailer $userMailer) public function __construct(InvoiceRepository $invoiceRepo, AccountRepository $accountRepo, UserMailer $userMailer)
{ {
parent::__construct(); parent::__construct();
$this->mailer = $mailer;
$this->invoiceRepo = $invoiceRepo; $this->invoiceRepo = $invoiceRepo;
$this->accountRepo = $accountRepo; $this->accountRepo = $accountRepo;
$this->userMailer = $userMailer; $this->userMailer = $userMailer;
@ -136,7 +131,7 @@ class SendReminders extends Command
continue; continue;
} }
$this->info('Send email: ' . $invoice->id); $this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, $reminder); dispatch(new SendInvoiceEmail($invoice, $invoice->user_id, $reminder));
} }
} }
@ -149,7 +144,7 @@ class SendReminders extends Command
continue; continue;
} }
$this->info('Send email: ' . $invoice->id); $this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, 'reminder4'); dispatch(new SendInvoiceEmail($invoice, $invoice->user_id, 'reminder4'));
} }
} }
} }
@ -162,6 +157,8 @@ class SendReminders extends Command
$this->info($scheduledReports->count() . ' scheduled reports'); $this->info($scheduledReports->count() . ' scheduled reports');
foreach ($scheduledReports as $scheduledReport) { foreach ($scheduledReports as $scheduledReport) {
$this->info('Processing report: ' . $scheduledReport->id);
$user = $scheduledReport->user; $user = $scheduledReport->user;
$account = $scheduledReport->account; $account = $scheduledReport->account;
@ -179,7 +176,14 @@ class SendReminders extends Command
$file = dispatch(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams)); $file = dispatch(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams));
if ($file) { if ($file) {
$this->userMailer->sendScheduledReport($scheduledReport, $file); try {
$this->userMailer->sendScheduledReport($scheduledReport, $file);
$this->info('Sent report');
} catch (Exception $exception) {
$this->info('ERROR: ' . $exception->getMessage());
}
} else {
$this->info('ERROR: Failed to run report');
} }
$scheduledReport->updateSendDate(); $scheduledReport->updateSendDate();