mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Working on email refactor
This commit is contained in:
parent
0d01f4b773
commit
9052a16b82
@ -130,11 +130,13 @@ class EmailController extends BaseController
|
||||
];
|
||||
|
||||
$mo = new EmailObject;
|
||||
$mo->subject = empty($subject) ? null : $subject;
|
||||
$mo->body = empty($body) ? null : $body;
|
||||
$mo->subject = strlen($subject) > 3 ? $subject : null;
|
||||
$mo->body = strlen($body) > 3 ? $body : null;
|
||||
$mo->entity_id = $request->input('entity_id');
|
||||
$mo->template = $template;
|
||||
$mo->entity_class = $this->resolveClass($entity);
|
||||
$mo->email_template_body = "email_template_{$template}";
|
||||
$mo->email_template_subject = "email_subject_{$template}";
|
||||
|
||||
if (Ninja::isHosted() && !$entity_obj->company->account->account_sms_verified) {
|
||||
return response(['message' => 'Please verify your account to send emails.'], 400);
|
||||
@ -151,7 +153,7 @@ class EmailController extends BaseController
|
||||
// EmailEntity::dispatch($invitation->fresh(), $invitation->company, $template, $data);
|
||||
|
||||
$mo->invitation_id = $invitation->id;
|
||||
|
||||
|
||||
Email::dispatch($mo, $invitation->company);
|
||||
// MailEntity::dispatch($invitation, $invitation->company->db, $mo);
|
||||
}
|
||||
|
@ -117,7 +117,7 @@ class Email implements ShouldQueue
|
||||
$this->email_object->client_contact_id ? $this->email_object->contact = ClientContact::withTrashed()->find($this->email_object->client_contact_id) : null;
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->email_object->user_id ? $this->email_object->user = User::withTrashed()->find($this->email_object->user_id) : $this->email_object->user = $this->company->owner();
|
||||
|
||||
$this->email_object->company_key = $this->company->company_key;
|
||||
@ -139,12 +139,12 @@ class Email implements ShouldQueue
|
||||
|
||||
private function resolveVariables(): self
|
||||
{
|
||||
match(get_class($this->email_object->entity)){
|
||||
Invoice::class => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->generateLabelsAndValues(),
|
||||
Quote::class => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->generateLabelsAndValues(),
|
||||
Credit::class => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->generateLabelsAndValues(),
|
||||
PurchaseOrder::class => $this->email_object->variables = (new VendorHtmlEngine($this->email_object->invitation))->generateLabelsAndValues(),
|
||||
default => null
|
||||
match(class_basename($this->email_object->entity)){
|
||||
"Invoice" => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
"Quote" => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
"Credit" => $this->email_object->variables = (new HtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
"PurchaseOrder" => $this->email_object->variables = (new VendorHtmlEngine($this->email_object->invitation))->makeValues(),
|
||||
default => $this->email_object->variables = []
|
||||
};
|
||||
|
||||
return $this;
|
||||
|
@ -151,8 +151,8 @@ class EmailDefaults
|
||||
{
|
||||
if ($this->email->email_object->body) {
|
||||
$this->email->email_object->body = $this->email->email_object->body;
|
||||
} elseif (isset($this->email->email_object->email_template_body) && strlen($this->email->email_object->settings->{$this->email->email_object->email_template_body}) > 3) {
|
||||
$this->email->email_object->body = $this->email->email_object->settings->{$this->email->email_object->email_template_body};
|
||||
} elseif (strlen($this->email->email_object->settings?->{$this->email->email_object->email_template_body}) > 3) {
|
||||
$this->email->email_object->body = $this->email->email_object->settings?->{$this->email->email_object->email_template_body};
|
||||
} else {
|
||||
$this->email->email_object->body = EmailTemplateDefaults::getDefaultTemplate($this->email->email_object->email_template_body, $this->locale);
|
||||
}
|
||||
@ -171,8 +171,8 @@ class EmailDefaults
|
||||
{
|
||||
if ($this->email->email_object->subject) { //where the user updates the subject from the UI
|
||||
return $this;
|
||||
} elseif (isset($this->email->email_object->email_template_subject) && strlen($this->email->email_object->settings->{$this->email->email_object->email_template_subject}) > 3) {
|
||||
$this->email->email_object->subject = $this->email->email_object->settings->{$this->email->email_object->email_template_subject};
|
||||
} elseif (strlen($this->email->email_object?->settings->{$this->email->email_object->email_template_subject}) > 3) {
|
||||
$this->email->email_object->subject = $this->email->email_object->settings?->{$this->email->email_object->email_template_subject};
|
||||
} else {
|
||||
$this->email->email_object->subject = EmailTemplateDefaults::getDefaultTemplate($this->email->email_object->email_template_subject, $this->locale);
|
||||
}
|
||||
@ -207,7 +207,7 @@ class EmailDefaults
|
||||
if ($this->template != 'custom') {
|
||||
$this->email->email_object->body = $this->parseMarkdownToHtml($this->email->email_object->body);
|
||||
}
|
||||
|
||||
nlog($this->email->email_object->subject);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user