Refactor Email Integration Handling
- Removed the AbstractEmailIntegrationHandler class to streamline email integration logic. - Updated EmailIntegration class to extend AbstractIntegrationHandler instead of the removed class. - Modified FormEmailNotification to handle mailer configuration internally, eliminating the need to pass the mailer as a parameter. These changes enhance the clarity and maintainability of the email integration process by consolidating configuration logic and reducing class dependencies.
This commit is contained in:
@@ -1,47 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Integrations\Handlers;
|
||||
|
||||
use App\Events\Forms\FormSubmitted;
|
||||
use App\Models\Integration\FormIntegration;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
abstract class AbstractEmailIntegrationHandler extends AbstractIntegrationHandler
|
||||
{
|
||||
protected $mailer;
|
||||
|
||||
public function __construct(FormSubmitted $event, FormIntegration $formIntegration, array $integration)
|
||||
{
|
||||
parent::__construct($event, $formIntegration, $integration);
|
||||
$this->initializeMailer();
|
||||
}
|
||||
|
||||
protected function initializeMailer()
|
||||
{
|
||||
$this->mailer = config('mail.default');
|
||||
$this->setWorkspaceSMTPSettings();
|
||||
|
||||
if (!$this->mailer) {
|
||||
Log::error('Mailer not specified', [
|
||||
'form_id' => $this->form->id
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
protected function setWorkspaceSMTPSettings()
|
||||
{
|
||||
$workspace = $this->form->workspace;
|
||||
$emailSettings = $workspace->settings['email_settings'] ?? [];
|
||||
if (!$workspace->is_pro || !$emailSettings || empty($emailSettings['host']) || empty($emailSettings['port']) || empty($emailSettings['username']) || empty($emailSettings['password'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
config([
|
||||
'mail.mailers.custom_smtp.host' => $emailSettings['host'],
|
||||
'mail.mailers.custom_smtp.port' => $emailSettings['port'],
|
||||
'mail.mailers.custom_smtp.username' => $emailSettings['username'],
|
||||
'mail.mailers.custom_smtp.password' => $emailSettings['password']
|
||||
]);
|
||||
$this->mailer = 'custom_smtp';
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@ use App\Open\MentionParser;
|
||||
use App\Service\Forms\FormSubmissionFormatter;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
class EmailIntegration extends AbstractEmailIntegrationHandler
|
||||
class EmailIntegration extends AbstractIntegrationHandler
|
||||
{
|
||||
public const RISKY_USERS_LIMIT = 120;
|
||||
|
||||
@@ -95,16 +95,15 @@ class EmailIntegration extends AbstractEmailIntegrationHandler
|
||||
->filter(function ($email) {
|
||||
return filter_var($email, FILTER_VALIDATE_EMAIL);
|
||||
});
|
||||
Log::debug('Sending email notification', [
|
||||
Log::info('Sending email notification', [
|
||||
'recipients' => $recipients->toArray(),
|
||||
'form_id' => $this->form->id,
|
||||
'form_slug' => $this->form->slug,
|
||||
'mailer' => $this->mailer
|
||||
]);
|
||||
|
||||
$recipients->each(function ($subscriber) {
|
||||
Notification::route('mail', $subscriber)->notify(
|
||||
new FormEmailNotification($this->event, $this->integrationData, $this->mailer)
|
||||
new FormEmailNotification($this->event, $this->integrationData)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user