Adjustments for email quotas

This commit is contained in:
David Bomba 2024-03-13 20:19:17 +11:00
parent fa828b3ab6
commit fd06b42bc2
2 changed files with 15 additions and 2 deletions

View File

@ -145,7 +145,8 @@ class NinjaMailerJob implements ShouldQueue
->send($mailable); ->send($mailable);
/* Count the amount of emails sent across all the users accounts */ /* Count the amount of emails sent across all the users accounts */
Cache::increment("email_quota".$this->company->account->key);
$this->incrementEmailCounter();
LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject)) LightLogs::create(new EmailSuccess($this->nmo->company->company_key, $this->nmo->mailable->subject))
->send(); ->send();
@ -221,6 +222,12 @@ class NinjaMailerJob implements ShouldQueue
$this->cleanUpMailers(); $this->cleanUpMailers();
} }
private function incrementEmailCounter(): void
{
if(in_array($this->mailer, ['default','mailgun']))
Cache::increment("email_quota".$this->company->account->key);
}
/** /**
* Entity notification when an email fails to send * Entity notification when an email fails to send
* *

View File

@ -244,6 +244,12 @@ class Email implements ShouldQueue
return $this; return $this;
} }
private function incrementEmailCounter(): void
{
if(in_array($this->mailer, ['default','mailgun']))
Cache::increment("email_quota".$this->company->account->key);
}
/** /**
* Attempts to send the email * Attempts to send the email
* *
@ -270,7 +276,7 @@ class Email implements ShouldQueue
$mailer->send($this->mailable); $mailer->send($this->mailable);
Cache::increment("email_quota".$this->company->account->key); $this->incrementEmailCounter();
LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject)) LightLogs::create(new EmailSuccess($this->company->company_key, $this->mailable->subject))
->send(); ->send();