From e78323a7a52946ec9a96434a8e114158d8667948 Mon Sep 17 00:00:00 2001 From: Thomas Zilio Date: Wed, 8 Jul 2020 09:26:17 +0200 Subject: [PATCH] Miglioramenti minori per account email --- modules/emails/src/Account.php | 22 ++++++++++++++++++++++ modules/smtp/actions.php | 8 +++----- modules/smtp/init.php | 4 ++++ update/2_4_16.sql | 4 ++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/modules/emails/src/Account.php b/modules/emails/src/Account.php index c46dc3864..8c90b9dca 100755 --- a/modules/emails/src/Account.php +++ b/modules/emails/src/Account.php @@ -2,8 +2,10 @@ namespace Modules\Emails; +use Carbon\Carbon; use Common\Model; use Illuminate\Database\Eloquent\SoftDeletes; +use Notifications\EmailNotification; use Traits\StoreTrait; class Account extends Model @@ -13,6 +15,26 @@ class Account extends Model protected $table = 'em_accounts'; + public function testConnection() + { + // Impostazione di connected_at a NULL + $this->connected_at = null; + $this->save(); + + // Creazione email di test + $mail = new EmailNotification($this->id); + // Tentativo di connessione + $result = $mail->testSMTP(); + + // Salvataggio della data di connessione per test riuscito + if ($result) { + $this->connected_at = Carbon::now(); + $this->save(); + } + + return $result; + } + /* Relazioni Eloquent */ public function templates() diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index 93b90ebe6..5024b314b 100755 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -1,7 +1,5 @@ testConnection(); echo json_encode([ - 'test' => $mail->testSMTP(), + 'test' => $result, ]); break; case 'delete': - $dbo->query('UPDATE em_accounts SET deleted_at = NOW() WHERE id='.prepare($id_record)); + $account->delete(); flash()->info(tr('Account email eliminato!')); diff --git a/modules/smtp/init.php b/modules/smtp/init.php index ebd678c96..50721a4b1 100755 --- a/modules/smtp/init.php +++ b/modules/smtp/init.php @@ -1,7 +1,11 @@ fetchOne('SELECT * FROM em_accounts WHERE id='.prepare($id_record).' AND deleted_at IS NULL'); } diff --git a/update/2_4_16.sql b/update/2_4_16.sql index f42629a17..5c9dd7f9d 100644 --- a/update/2_4_16.sql +++ b/update/2_4_16.sql @@ -115,3 +115,7 @@ ALTER TABLE `co_preventivi` ADD COLUMN `tipo_validita` ENUM('days', 'months', 'y -- Aggiunta campi Peso e Volume in DDT e Fatture accompagnatorie ALTER TABLE `dt_ddt` ADD COLUMN `peso` decimal(12, 4) AFTER `n_colli`, ADD COLUMN `volume` decimal(12, 4) AFTER `peso`; ALTER TABLE `co_documenti` ADD COLUMN `peso` decimal(12, 4) AFTER `n_colli`, ADD COLUMN `volume` decimal(12, 4) AFTER `peso`; + +-- Aggiunta data di connessione agli account SMTP +ALTER TABLE `em_accounts` ADD `connected_at` TIMESTAMP NULL DEFAULT NULL AFTER `timeout`; +UPDATE `em_accounts` SET `connected_at` = NOW();