mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-04 05:58:50 -05:00 
			
		
		
		
	Fixes for mailers
This commit is contained in:
		
							parent
							
								
									396b96cd34
								
							
						
					
					
						commit
						aeeb099d40
					
				@ -13,6 +13,7 @@ namespace App\Http\Controllers;
 | 
			
		||||
 | 
			
		||||
use App\Console\Commands\ImportMigrations;
 | 
			
		||||
use App\DataMapper\CompanySettings;
 | 
			
		||||
use App\Jobs\Mail\MailRouter;
 | 
			
		||||
use App\Jobs\Util\StartMigration;
 | 
			
		||||
use App\Mail\ExistingMigration;
 | 
			
		||||
use App\Models\Company;
 | 
			
		||||
@ -245,7 +246,7 @@ class MigrationController extends BaseController
 | 
			
		||||
        if ($checks['same_keys'] && ! $checks['with_force']) {
 | 
			
		||||
            info('Migrating: Same company keys, no force provided.');
 | 
			
		||||
 | 
			
		||||
            Mail::to($user)->send(new ExistingMigration());
 | 
			
		||||
            MailRouter::dispatch(new ExistingMigration(), $company, $user);
 | 
			
		||||
 | 
			
		||||
            return response()->json([
 | 
			
		||||
                '_id' => Str::uuid(),
 | 
			
		||||
@ -258,7 +259,7 @@ class MigrationController extends BaseController
 | 
			
		||||
        if (! $checks['same_keys'] && $checks['existing_company'] && ! $checks['with_force']) {
 | 
			
		||||
            info('Migrating: Different keys, existing company with the key without the force option.');
 | 
			
		||||
 | 
			
		||||
            Mail::to($user)->send(new ExistingMigration());
 | 
			
		||||
            MailRouter::dispatch(new ExistingMigration(), $company, $user);
 | 
			
		||||
 | 
			
		||||
            return response()->json([
 | 
			
		||||
                '_id' => Str::uuid(),
 | 
			
		||||
 | 
			
		||||
@ -14,9 +14,11 @@ namespace App\Jobs\Credit;
 | 
			
		||||
use App\Events\Credit\CreditWasEmailed;
 | 
			
		||||
use App\Events\Credit\CreditWasEmailedAndFailed;
 | 
			
		||||
use App\Jobs\Mail\BaseMailerJob;
 | 
			
		||||
use App\Jobs\Mail\MailRouter;
 | 
			
		||||
use App\Jobs\Util\SystemLogger;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Mail\TemplateEmail;
 | 
			
		||||
use App\Models\Company;
 | 
			
		||||
use App\Models\Credit;
 | 
			
		||||
use App\Models\SystemLog;
 | 
			
		||||
use App\Utils\Ninja;
 | 
			
		||||
@ -38,16 +40,17 @@ class EmailCredit extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
    public $settings;
 | 
			
		||||
 | 
			
		||||
    public $company;
 | 
			
		||||
    /**
 | 
			
		||||
     * Create a new job instance.
 | 
			
		||||
     *
 | 
			
		||||
     * @return void
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct(Credit $credit)
 | 
			
		||||
    public function __construct(Credit $credit, Company $company)
 | 
			
		||||
    {
 | 
			
		||||
        $this->credit = $credit;
 | 
			
		||||
 | 
			
		||||
        $this->settings = $credit->client->getMergedSettings();
 | 
			
		||||
        $this->company = $company;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -59,30 +62,29 @@ class EmailCredit extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        //todo - change runtime config of mail driver if necessary
 | 
			
		||||
        MultiDB::setDb($this->company->db);
 | 
			
		||||
 | 
			
		||||
        $this->settings = $this->credit->client->getMergedSettings();
 | 
			
		||||
 | 
			
		||||
        $template_style = $this->credit->client->getSetting('email_style');
 | 
			
		||||
 | 
			
		||||
        $this->setMailDriver();
 | 
			
		||||
 | 
			
		||||
        $this->credit->invitations->each(function ($invitation) use ($template_style) {
 | 
			
		||||
            if ($invitation->contact->send_email && $invitation->contact->email) {
 | 
			
		||||
 | 
			
		||||
            if ($invitation->contact->send_email && $invitation->contact->email) 
 | 
			
		||||
            {
 | 
			
		||||
 | 
			
		||||
                $message_array = $this->credit->getEmailData('', $invitation->contact);
 | 
			
		||||
                $message_array['title'] = &$message_array['subject'];
 | 
			
		||||
                $message_array['footer'] = 'Sent to '.$invitation->contact->present()->name();
 | 
			
		||||
 | 
			
		||||
                //send message
 | 
			
		||||
                Mail::to($invitation->contact->email, $invitation->contact->present()->name())
 | 
			
		||||
                ->send(new TemplateEmail($message_array, $template_style, $invitation->contact->user, $invitation->contact->client));
 | 
			
		||||
 | 
			
		||||
                if (count(Mail::failures()) > 0) {
 | 
			
		||||
                    event(new CreditWasEmailedAndFailed($this->credit, $this->credit->company, Mail::failures(), Ninja::eventVars()));
 | 
			
		||||
 | 
			
		||||
                    return $this->logMailError(Mail::failures(), $this->credit->client);
 | 
			
		||||
                }
 | 
			
		||||
                MailRouter::dispatch(new TemplateEmail($message_array, $template_style, $invitation->contact->user, $invitation->contact->client), $invitation->company, $invitation->contact);
 | 
			
		||||
 | 
			
		||||
                //fire any events
 | 
			
		||||
                event(new CreditWasEmailed($this->credit, $this->company, Ninja::eventVars()));
 | 
			
		||||
            }
 | 
			
		||||
            
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -44,11 +44,11 @@ class MailRouter extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
    public $to_user; //User or ClientContact
 | 
			
		||||
 | 
			
		||||
    public $sending_method;
 | 
			
		||||
    public $sending_method; //not sure if we even need this
 | 
			
		||||
 | 
			
		||||
    public $settings;
 | 
			
		||||
 | 
			
		||||
    public function __construct(Mailable $mailable, Company $company, $to_user, string $sending_method)
 | 
			
		||||
    public function __construct(Mailable $mailable, Company $company, $to_user, $sending_method = null)
 | 
			
		||||
    {
 | 
			
		||||
        $this->mailable = $mailable;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -61,6 +61,8 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
        $this->amount = $amount;
 | 
			
		||||
 | 
			
		||||
        $this->company = $company;
 | 
			
		||||
 | 
			
		||||
        $this->settings = $client->getMergedSettings();
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
@ -71,7 +73,6 @@ class PaymentFailureMailer extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        info('entity payment failure mailer');
 | 
			
		||||
        //Set DB
 | 
			
		||||
        MultiDB::setDb($this->company->db);
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -7,6 +7,7 @@ use App\Events\Invoice\InvoiceWasEmailedAndFailed;
 | 
			
		||||
use App\Events\Payment\PaymentWasEmailed;
 | 
			
		||||
use App\Events\Payment\PaymentWasEmailedAndFailed;
 | 
			
		||||
use App\Helpers\Email\BuildEmail;
 | 
			
		||||
use App\Jobs\Mail\BaseMailerJob;
 | 
			
		||||
use App\Jobs\Utils\SystemLogger;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Mail\TemplateEmail;
 | 
			
		||||
@ -21,7 +22,7 @@ use Illuminate\Queue\InteractsWithQueue;
 | 
			
		||||
use Illuminate\Queue\SerializesModels;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
 | 
			
		||||
class EmailPayment implements ShouldQueue
 | 
			
		||||
class EmailPayment extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
{
 | 
			
		||||
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 | 
			
		||||
 | 
			
		||||
@ -52,6 +53,13 @@ class EmailPayment implements ShouldQueue
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        if ($this->contact->email) {
 | 
			
		||||
 | 
			
		||||
            MultiDB::setDb($this->payment->company->db); //this may fail if we don't pass the serialized object with the company record
 | 
			
		||||
            //todo fix!!
 | 
			
		||||
 | 
			
		||||
            //if we need to set an email driver do it now
 | 
			
		||||
            $this->setMailDriver();
 | 
			
		||||
 | 
			
		||||
            Mail::to($this->contact->email, $this->contact->present()->name())
 | 
			
		||||
                ->send(new TemplateEmail($this->email_builder, $this->contact->user, $this->contact->customer));
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -6,6 +6,7 @@ use App\Events\Invoice\InvoiceWasEmailed;
 | 
			
		||||
use App\Events\Invoice\InvoiceWasEmailedAndFailed;
 | 
			
		||||
use App\Events\Quote\QuoteWasEmailed;
 | 
			
		||||
use App\Events\Quote\QuoteWasEmailedAndFailed;
 | 
			
		||||
use App\Jobs\Mail\BaseMailerJob;
 | 
			
		||||
use App\Jobs\Utils\SystemLogger;
 | 
			
		||||
use App\Libraries\MultiDB;
 | 
			
		||||
use App\Mail\TemplateEmail;
 | 
			
		||||
@ -20,7 +21,7 @@ use Illuminate\Queue\InteractsWithQueue;
 | 
			
		||||
use Illuminate\Queue\SerializesModels;
 | 
			
		||||
use Illuminate\Support\Facades\Mail;
 | 
			
		||||
 | 
			
		||||
class EmailQuote implements ShouldQueue
 | 
			
		||||
class EmailQuote extends BaseMailerJob implements ShouldQueue
 | 
			
		||||
{
 | 
			
		||||
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 | 
			
		||||
 | 
			
		||||
@ -28,15 +29,19 @@ class EmailQuote implements ShouldQueue
 | 
			
		||||
 | 
			
		||||
    public $email_builder;
 | 
			
		||||
 | 
			
		||||
    public $company;
 | 
			
		||||
 | 
			
		||||
    public $settings;
 | 
			
		||||
    /**
 | 
			
		||||
     * EmailQuote constructor.
 | 
			
		||||
     * @param BuildEmail $email_builder
 | 
			
		||||
     * @param QuoteInvitation $quote_invitation
 | 
			
		||||
     */
 | 
			
		||||
    public function __construct($email_builder, QuoteInvitation $quote_invitation)
 | 
			
		||||
    public function __construct($email_builder, QuoteInvitation $quote_invitation, Company $company)
 | 
			
		||||
    {
 | 
			
		||||
        $this->quote_invitation = $quote_invitation;
 | 
			
		||||
        $this->email_builder = $email_builder;
 | 
			
		||||
        $this->company = $company;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
@ -47,6 +52,12 @@ class EmailQuote implements ShouldQueue
 | 
			
		||||
     */
 | 
			
		||||
    public function handle()
 | 
			
		||||
    {
 | 
			
		||||
        MultiDB::setDb($this->company->db);
 | 
			
		||||
 | 
			
		||||
        $this->settings = $this->quote_invitation->contact->client->getMergedSettings();
 | 
			
		||||
 | 
			
		||||
        $this->setMailDriver();
 | 
			
		||||
 | 
			
		||||
        Mail::to($this->quote_invitation->contact->email, $this->quote_invitation->contact->present()->name())
 | 
			
		||||
            ->send(
 | 
			
		||||
                new TemplateEmail(
 | 
			
		||||
 | 
			
		||||
@ -35,7 +35,7 @@ class EntityNotificationMailer extends Mailable
 | 
			
		||||
     */
 | 
			
		||||
    public function build()
 | 
			
		||||
    {
 | 
			
		||||
        return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1]) //todo
 | 
			
		||||
        return $this->from($this->mail_obj->from[0], $this->mail_obj->from[1])
 | 
			
		||||
                    ->subject($this->mail_obj->subject)
 | 
			
		||||
                    ->markdown($this->mail_obj->markdown, $this->mail_obj->data)
 | 
			
		||||
                    ->withSwiftMessage(function ($message) {
 | 
			
		||||
 | 
			
		||||
@ -48,7 +48,7 @@ class SendEmail
 | 
			
		||||
            if ($invitation->contact->send_email && $invitation->contact->email) {
 | 
			
		||||
                $email_builder = (new QuoteEmail())->build($invitation, $this->reminder_template);
 | 
			
		||||
 | 
			
		||||
                EmailQuote::dispatchNow($email_builder, $invitation);
 | 
			
		||||
                EmailQuote::dispatchNow($email_builder, $invitation, $invitation->company);
 | 
			
		||||
            }
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user