fix(core): improve instantSave logic and error handling
This commit is contained in:
@@ -114,19 +114,24 @@ class SettingsEmail extends Component
|
|||||||
public function instantSave(string $type)
|
public function instantSave(string $type)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
|
$currentSmtpEnabled = $this->settings->smtp_enabled;
|
||||||
|
$currentResendEnabled = $this->settings->resend_enabled;
|
||||||
$this->resetErrorBag();
|
$this->resetErrorBag();
|
||||||
|
|
||||||
if ($type === 'SMTP') {
|
if ($type === 'SMTP') {
|
||||||
$this->submitSmtp();
|
$this->submitSmtp();
|
||||||
|
$this->resendEnabled = $this->settings->resend_enabled = false;
|
||||||
} elseif ($type === 'Resend') {
|
} elseif ($type === 'Resend') {
|
||||||
$this->submitResend();
|
$this->submitResend();
|
||||||
|
$this->smtpEnabled = $this->settings->smtp_enabled = false;
|
||||||
}
|
}
|
||||||
|
$this->settings->save();
|
||||||
|
|
||||||
} catch (\Throwable $e) {
|
} catch (\Throwable $e) {
|
||||||
if ($type === 'SMTP') {
|
if ($type === 'SMTP') {
|
||||||
$this->smtpEnabled = false;
|
$this->smtpEnabled = $currentSmtpEnabled;
|
||||||
} elseif ($type === 'Resend') {
|
} elseif ($type === 'Resend') {
|
||||||
$this->resendEnabled = false;
|
$this->resendEnabled = $currentResendEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return handleError($e, $this);
|
return handleError($e, $this);
|
||||||
@@ -156,9 +161,6 @@ class SettingsEmail extends Component
|
|||||||
'smtpEncryption.required' => 'Encryption type is required.',
|
'smtpEncryption.required' => 'Encryption type is required.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->resendEnabled = false;
|
|
||||||
$this->settings->resend_enabled = false;
|
|
||||||
|
|
||||||
$this->settings->smtp_enabled = $this->smtpEnabled;
|
$this->settings->smtp_enabled = $this->smtpEnabled;
|
||||||
$this->settings->smtp_host = $this->smtpHost;
|
$this->settings->smtp_host = $this->smtpHost;
|
||||||
$this->settings->smtp_port = $this->smtpPort;
|
$this->settings->smtp_port = $this->smtpPort;
|
||||||
@@ -194,9 +196,6 @@ class SettingsEmail extends Component
|
|||||||
'smtpFromName.required' => 'From Name is required.',
|
'smtpFromName.required' => 'From Name is required.',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->smtpEnabled = false;
|
|
||||||
$this->settings->smtp_enabled = false;
|
|
||||||
|
|
||||||
$this->settings->resend_enabled = $this->resendEnabled;
|
$this->settings->resend_enabled = $this->resendEnabled;
|
||||||
$this->settings->resend_api_key = $this->resendApiKey;
|
$this->settings->resend_api_key = $this->resendApiKey;
|
||||||
$this->settings->smtp_from_address = $this->smtpFromAddress;
|
$this->settings->smtp_from_address = $this->smtpFromAddress;
|
||||||
|
Reference in New Issue
Block a user