diff --git a/assets/src/js/functions/hooks.js b/assets/src/js/functions/hooks.js index 23fa891b3..23b54cd7e 100644 --- a/assets/src/js/functions/hooks.js +++ b/assets/src/js/functions/hooks.js @@ -88,14 +88,14 @@ function executeHook(hook, token) { var timeout; if (result.execute) { - timeout = 1; + startHook(hook); } else { timeout = 30; - } - setTimeout(function () { - startHook(hook); - }, timeout * 1000); + setTimeout(function () { + startHook(hook); + }, timeout * 1000); + } }, }); } diff --git a/modules/emails/src/EmailHook.php b/modules/emails/src/EmailHook.php index e4697b188..8303a4414 100644 --- a/modules/emails/src/EmailHook.php +++ b/modules/emails/src/EmailHook.php @@ -2,6 +2,7 @@ namespace Modules\Emails; +use Carbon\Carbon; use Hooks\Manager; use Notifications\EmailNotification; @@ -29,20 +30,32 @@ class EmailHook extends Manager public function execute() { - $accounts = Account::all(); $diff = date('Y-m-d', strtotime('-4 hours')); + $failed = function ($query) use ($diff) { + $query->whereDate('failed_at', '<', $diff) + ->orWhereNull('failed_at'); + }; + $accounts = Account::all(); $list = []; foreach ($accounts as $account) { - $mail = Mail::whereNull('sent_at') - ->where('id_account', $account->id) - ->whereNull('failed_at') - ->orWhereDate('failed_at', '<', $diff) - ->orderBy('created_at') - ->first(); + $last_mail = $account->emails()->whereNotNull('sent_at')->orderBy('sent_at')->first(); - if (!empty($mail)) { - $list[] = $mail; + // Controllo sul timeout dell'account + $date = new Carbon($last_mail->sent_at); + $now = new Carbon(); + $diff = $date->diffInMilliseconds($now); + + if (empty($last_mail) || $diff > $account->timeout) { + $mail = Mail::whereNull('sent_at') + ->where('id_account', $account->id) + ->where($failed) + ->orderBy('created_at') + ->first(); + + if (!empty($mail)) { + $list[] = $mail; + } } } diff --git a/modules/smtp/actions.php b/modules/smtp/actions.php index 4d8d3efcc..01ec5ce6f 100644 --- a/modules/smtp/actions.php +++ b/modules/smtp/actions.php @@ -35,6 +35,7 @@ switch (post('op')) { 'from_address' => post('from_address'), 'encryption' => post('encryption'), 'pec' => post('pec'), + 'timeout' => post('timeout'), 'ssl_no_verify' => post('ssl_no_verify'), 'predefined' => $predefined, ], ['id' => $id_record]); diff --git a/modules/smtp/edit.php b/modules/smtp/edit.php index 6216f3e71..b5286de18 100644 --- a/modules/smtp/edit.php +++ b/modules/smtp/edit.php @@ -63,8 +63,12 @@ include_once __DIR__.'/../../core.php'; {[ "type": "text", "label": "", "name": "username", "value": "$username$" ]} -
- {[ "type": "password", "label": "", "class": "", "name": "password", "value": "$password$" ]} +
+ {[ "type": "password", "label": "", "name": "password", "value": "$password$" ]} +
+ +
+ {[ "type": "number", "label": "", "name": "timeout", "value": "$timeout$", "decimals": 0 ]}
diff --git a/update/2_4_11.sql b/update/2_4_11.sql index 1a5f26855..7fcb13923 100644 --- a/update/2_4_11.sql +++ b/update/2_4_11.sql @@ -419,7 +419,7 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Newsletter'), 'Completato', 'IF(completed_at IS NULL, ''No'', ''Si'')', 4, 1, 0, 1, 1); -- Modulo Stato email -INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stato email', 'Stato email', 'stato_email', 'SELECT |select| FROM `em_emails` WHERE 1=1 AND (`em_emails`.`created_at` BETWEEN ''|period_start|'' AND ''|period_end|'' OR `em_emails`.`sent_at` IS NULL) HAVING 2=2', '', 'fa fa-spinner ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1'); +INSERT INTO `zz_modules` (`id`, `name`, `title`, `directory`, `options`, `options2`, `icon`, `version`, `compatibility`, `order`, `parent`, `default`, `enabled`) VALUES (NULL, 'Stato email', 'Coda di invio', 'stato_email', 'SELECT |select| FROM `em_emails` WHERE 1=1 AND (`em_emails`.`created_at` BETWEEN ''|period_start|'' AND ''|period_end|'' OR `em_emails`.`sent_at` IS NULL) HAVING 2=2', '', 'fa fa-spinner ', '2.4.11', '2.4.11', '1', (SELECT `id` FROM `zz_modules` t WHERE t.`name` = 'Gestione email'), '1', '1'); INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, `default`, `visible`, `format`) VALUES ((SELECT `id` FROM `zz_modules` WHERE `name` = 'Stato email'), 'id', 'id', 1, 0, 0, 1, 0, 0), @@ -432,3 +432,4 @@ INSERT INTO `zz_views` (`id_module`, `name`, `query`, `order`, `search`, `slow`, ALTER TABLE `em_templates` CHANGE `id_smtp` `id_account` INT(11) NOT NULL; ALTER TABLE `em_print_template` CHANGE `id_email` `id_template` INT(11) NOT NULL; +ALTER TABLE `em_accounts` ADD `timeout` INT(11) NOT NULL DEFAULT 1000;