fix AntAlert checking limits
This commit is contained in:
parent
9c2cce3d0b
commit
7d297ca19b
@ -55,6 +55,7 @@ class AdminAntAlert extends AdminTab {
|
||||
} else {
|
||||
$alert = new AntAlert();
|
||||
$alert->date_last_sent = date("Y-m-d H:i:s");
|
||||
$alert->date_last_check = date("Y-m-d H:i:s");
|
||||
}
|
||||
|
||||
$alert->id_contact = (int)Tools::getValue('id_contact');
|
||||
|
@ -99,12 +99,18 @@ class Ant_Alert extends Module
|
||||
SELECT COUNT(*) as total, MIN(ct.`date_add`) as `min_date`
|
||||
FROM '._DB_PREFIX_.'customer_thread ct
|
||||
WHERE ct.status = "open"
|
||||
AND ct.date_add > "'.pSQL($alert->date_last_sent).'"
|
||||
AND ct.date_add >= "'.pSQL($alert->date_last_check).'"
|
||||
GROUP BY ct.id_contact HAVING COUNT(*) > 0 AND ct.id_contact ='.(int)$alert->id_contact
|
||||
);
|
||||
$date_min = new Datetime($open_messages['min_date']);
|
||||
$minDiff = $date_min->diff($now);
|
||||
if ((int)$open_messages['total'] >= (int)$alert->limit && (int)$minDiff->format("%H") >= (int)$alert->hours) {
|
||||
$hourLimitMin = (int)$alert->hours;
|
||||
$hourLimitMax = (int)$alert->hours+1;
|
||||
if (
|
||||
(int)$open_messages['total'] >= (int)$alert->limit
|
||||
&& (int)$minDiff->format("%H") >= $hourLimitMin
|
||||
&& (int)$minDiff->format("%H") <= $hourLimitMax
|
||||
) {
|
||||
// dev
|
||||
//$to = array('marion@antadis.com');
|
||||
// prod
|
||||
@ -122,9 +128,13 @@ class Ant_Alert extends Module
|
||||
foreach ($to as $email) {
|
||||
if(Mail::Send(2, 'ant_alert', 'Alert error', $data, $email)) {
|
||||
$alert->date_last_sent = date('Y-m-d H:i:s');
|
||||
$alert->date_last_check = date('Y-m-d H:i:s');
|
||||
$alert->save();
|
||||
}
|
||||
}
|
||||
} elseif((int)$open_messages['total'] >= (int)$alert->limit && (int)$minDiff->format("%H") > $hourLimitMax) {
|
||||
$alert->date_last_check = date('Y-m-d H:i:s');
|
||||
$alert->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -11,17 +11,19 @@ class AntAlert extends ObjectModel
|
||||
public $date_add;
|
||||
public $date_upd;
|
||||
public $date_last_sent;
|
||||
public $date_last_check;
|
||||
|
||||
protected $fieldsRequired = array('id_contact','limit','hours');
|
||||
protected $fieldsValidate = array(
|
||||
'id_alert' => 'isUnsignedId',
|
||||
'enabled' => 'isBool',
|
||||
'id_contact' => 'isUnsignedId',
|
||||
'limit' => 'isInt',
|
||||
'hours' => 'isInt',
|
||||
'date_add' => 'isDate',
|
||||
'date_upd' => 'isDate',
|
||||
'date_last_sent' => 'isDate',
|
||||
'id_alert' => 'isUnsignedId',
|
||||
'enabled' => 'isBool',
|
||||
'id_contact' => 'isUnsignedId',
|
||||
'limit' => 'isInt',
|
||||
'hours' => 'isInt',
|
||||
'date_add' => 'isDate',
|
||||
'date_upd' => 'isDate',
|
||||
'date_last_sent' => 'isDate',
|
||||
'date_last_check' => 'isDate',
|
||||
);
|
||||
|
||||
protected $table = 'ant_alert';
|
||||
@ -32,14 +34,15 @@ class AntAlert extends ObjectModel
|
||||
{
|
||||
parent::validateFields();
|
||||
|
||||
$fields['id_alert'] = (int)$this->id_alert;
|
||||
$fields['enabled'] = (int)$this->enabled;
|
||||
$fields['id_contact'] = (int)$this->id_contact;
|
||||
$fields['limit'] = (int)$this->limit;
|
||||
$fields['hours'] = (int)$this->hours;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['date_last_sent'] = pSQL($this->date_last_sent);
|
||||
$fields['id_alert'] = (int)$this->id_alert;
|
||||
$fields['enabled'] = (int)$this->enabled;
|
||||
$fields['id_contact'] = (int)$this->id_contact;
|
||||
$fields['limit'] = (int)$this->limit;
|
||||
$fields['hours'] = (int)$this->hours;
|
||||
$fields['date_add'] = pSQL($this->date_add);
|
||||
$fields['date_upd'] = pSQL($this->date_upd);
|
||||
$fields['date_last_sent'] = pSQL($this->date_last_sent);
|
||||
$fields['date_last_check'] = pSQL($this->date_last_check);
|
||||
|
||||
return $fields;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user