Fix: Display Last Status Mail Sent for monitoring in admin panel correctly.

Naming of column is now also consistent.
This commit is contained in:
baldo 2016-06-25 14:33:51 +02:00
parent c5938d3e13
commit 0e5c5e4e1e
2 changed files with 51 additions and 6 deletions

View file

@ -0,0 +1,45 @@
-- sqlite only supports a limited subset of ALTER TABLE, thus this workaround
ALTER TABLE node_state RENAME TO tmp_node_state;
CREATE TABLE node_state (
id INTEGER PRIMARY KEY,
mac VARCHAR(17) NOT NULL UNIQUE,
state VARCHAR(10) NOT NULL,
last_seen DATETIME NOT NULL,
import_timestamp DATETIME NOT NULL,
last_status_mail_sent DATETIME,
last_status_mail_type VARCHAR(20),
created_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL,
modified_at DATETIME DEFAULT (strftime('%s','now')) NOT NULL
);
INSERT INTO node_state(
id,
mac,
state,
last_seen,
import_timestamp,
last_status_mail_sent,
last_status_mail_type,
created_at,
modified_at
)
SELECT
id,
mac,
state,
last_seen,
import_timestamp,
last_status_mail_send,
last_status_mail_type,
created_at,
modified_at
FROM tmp_node_state;
DROP TABLE tmp_node_state;

View file

@ -34,7 +34,7 @@ angular.module('ffffng')
return Database.run(
'INSERT INTO node_state ' +
'(mac, state, last_seen, import_timestamp, last_status_mail_send, last_status_mail_type) ' +
'(mac, state, last_seen, import_timestamp, last_status_mail_sent, last_status_mail_type) ' +
'VALUES (?, ?, ?, ?, ?, ?)',
[
node.mac,
@ -267,7 +267,7 @@ angular.module('ffffng')
var now = moment().unix();
Database.run(
'UPDATE node_state ' +
'SET modified_at = ?, last_status_mail_send = ?, last_status_mail_type = ?' +
'SET modified_at = ?, last_status_mail_sent = ?, last_status_mail_type = ?' +
'WHERE id = ?',
[
now, now, mailType,
@ -330,19 +330,19 @@ angular.module('ffffng')
var allowNull = mailNumber === 1 ? ' OR last_status_mail_type IS NULL' : '';
var schedule = MONITORING_OFFLINE_MAILS_SCHEDULE[mailNumber];
var scheduleTimeBefore = moment().subtract(schedule.amount, schedule.unit);
var scheduledTimeBefore = moment().subtract(schedule.amount, schedule.unit);
Database.all(
'SELECT * FROM node_state ' +
'WHERE modified_at < ? AND state = ? AND (last_status_mail_type = ?' + allowNull + ') AND ' +
'last_seen <= ? AND last_status_mail_send <= ? ' +
'last_seen <= ? AND last_status_mail_sent <= ? ' +
'ORDER BY id ASC LIMIT ?',
[
startTime.unix(),
'OFFLINE',
previousType,
scheduleTimeBefore.unix(),
scheduleTimeBefore.unix(),
scheduledTimeBefore.unix(),
scheduledTimeBefore.unix(),
MONITORING_MAILS_DB_BATCH_SIZE
],