Bugfix invio email

This commit is contained in:
Thomas Zilio 2019-09-12 10:45:36 +02:00
parent 6d7cb74248
commit c37c5d48da
1 changed files with 10 additions and 5 deletions

View File

@ -17,12 +17,14 @@ class EmailHook extends Manager
{ {
$diff = date('Y-m-d H:i:s', strtotime('-4 hours')); $diff = date('Y-m-d H:i:s', strtotime('-4 hours'));
$failed = function ($query) use ($diff) { $failed = function ($query) use ($diff) {
$query->whereDate('failed_at', '<', $diff) $query->where('failed_at', '<', $diff)
->orWhereNull('failed_at'); ->orWhereNull('failed_at');
}; };
$accounts = Account::all();
$remaining = Mail::whereNull('sent_at') $remaining = Mail::whereNull('sent_at')
->where($failed) ->where($failed)
->whereIn('id_account', $accounts->pluck('id'))
->count(); ->count();
return !empty($remaining); return !empty($remaining);
@ -32,21 +34,24 @@ class EmailHook extends Manager
{ {
$diff = date('Y-m-d H:i:s', strtotime('-4 hours')); $diff = date('Y-m-d H:i:s', strtotime('-4 hours'));
$failed = function ($query) use ($diff) { $failed = function ($query) use ($diff) {
$query->whereDate('failed_at', '<', $diff) $query->where('failed_at', '<', $diff)
->orWhereNull('failed_at'); ->orWhereNull('failed_at');
}; };
$accounts = Account::all(); $accounts = Account::all();
$list = []; $list = [];
foreach ($accounts as $account) { foreach ($accounts as $account) {
$last_mail = $account->emails()->whereNotNull('sent_at')->orderBy('sent_at')->first(); $last_mail = $account->emails()
->whereNotNull('sent_at')
->orderBy('sent_at')
->first();
// Controllo sul timeout dell'account // Controllo sul timeout dell'account
$date = new Carbon($last_mail->sent_at); $date = new Carbon($last_mail->sent_at);
$now = new Carbon(); $now = new Carbon();
$diff = $date->diffInMilliseconds($now); $diff_milliseconds = $date->diffInMilliseconds($now);
if (empty($last_mail) || $diff > $account->timeout) { if (empty($last_mail) || $diff_milliseconds > $account->timeout) {
$mail = Mail::whereNull('sent_at') $mail = Mail::whereNull('sent_at')
->where('id_account', $account->id) ->where('id_account', $account->id)
->where($failed) ->where($failed)