sqlQuery Conversion : basic, events, notifications, scheduler, socketio
parent
0f73187cb3
commit
21ea4d804f
|
@ -214,7 +214,15 @@ module.exports = function(s,config){
|
|||
if(!e){e=''}
|
||||
if(config.systemLog===true){
|
||||
if(typeof q==='string'&&s.databaseEngine){
|
||||
s.sqlQuery('INSERT INTO Logs (ke,mid,info) VALUES (?,?,?)',['$','$SYSTEM',s.s({type:q,msg:w})]);
|
||||
s.knexQuery({
|
||||
action: "insert",
|
||||
table: "Logs",
|
||||
insert: {
|
||||
ke: '$',
|
||||
mid: '$SYSTEM',
|
||||
info: s.s({type:q,msg:w}),
|
||||
}
|
||||
})
|
||||
s.tx({f:'log',log:{time:s.timeObject(),ke:'$',mid:'$SYSTEM',time:s.timeObject(),info:s.s({type:q,msg:w})}},'$');
|
||||
}
|
||||
return console.log(s.timeObject().format(),q,w,e)
|
||||
|
|
|
@ -394,7 +394,16 @@ module.exports = function(s,config,lang){
|
|||
}
|
||||
//save this detection result in SQL, only coords. not image.
|
||||
if(forceSave || (filter.save && currentConfig.detector_save === '1')){
|
||||
s.sqlQuery('INSERT INTO Events (ke,mid,details,time) VALUES (?,?,?,?)',[d.ke,d.id,detailString,eventTime])
|
||||
s.knexQuery({
|
||||
action: "insert",
|
||||
table: "Events",
|
||||
insert: {
|
||||
ke: d.ke,
|
||||
mid: d.id,
|
||||
details: detailString,
|
||||
time: eventTime,
|
||||
}
|
||||
})
|
||||
}
|
||||
if(currentConfig.detector === '1' && currentConfig.detector_notrigger === '1'){
|
||||
s.setNoEventsDetector(s.group[d.ke].rawMonitorConfigurations[d.id])
|
||||
|
|
|
@ -207,7 +207,15 @@ module.exports = function(s,config,lang){
|
|||
var onDetectorNoTriggerTimeoutForEmail = function(e){
|
||||
//e = monitor object
|
||||
if(config.mail && e.details.detector_notrigger_mail === '1'){
|
||||
s.sqlQuery('SELECT mail FROM Users WHERE ke=? AND details NOT LIKE ?',[e.ke,'%"sub"%'],function(err,r){
|
||||
s.knexQuery({
|
||||
action: "select",
|
||||
columns: "mail",
|
||||
table: "Users",
|
||||
where: [
|
||||
['ke','=',e.ke],
|
||||
['details','NOT LIKE','%"sub"%'],
|
||||
]
|
||||
},function(err,r) {
|
||||
r = r[0]
|
||||
var mailOptions = {
|
||||
from: config.mail.from, // sender address
|
||||
|
@ -283,7 +291,15 @@ module.exports = function(s,config,lang){
|
|||
}
|
||||
var onEventTriggerForEmail = function(d,filter){
|
||||
if(filter.mail && config.mail && !s.group[d.ke].activeMonitors[d.id].detector_mail){
|
||||
s.sqlQuery('SELECT mail FROM Users WHERE ke=? AND details NOT LIKE ?',[d.ke,'%"sub"%'],function(err,r){
|
||||
s.knexQuery({
|
||||
action: "select",
|
||||
columns: "mail",
|
||||
table: "Users",
|
||||
where: [
|
||||
['ke','=',d.ke],
|
||||
['details','NOT LIKE','%"sub"%'],
|
||||
]
|
||||
},function(err,r) {
|
||||
r=r[0];
|
||||
var detector_mail_timeout
|
||||
if(!d.mon.details.detector_mail_timeout||d.mon.details.detector_mail_timeout===''){
|
||||
|
|
|
@ -3,7 +3,11 @@ module.exports = function(s,config,lang,app,io){
|
|||
//Get all Schedules
|
||||
s.getAllSchedules = function(callback){
|
||||
s.schedules = {}
|
||||
s.sqlQuery('SELECT * FROM Schedules',function(err,rows){
|
||||
s.knexQuery({
|
||||
action: "select",
|
||||
columns: "*",
|
||||
table: "Schedules"
|
||||
},function(err,rows) {
|
||||
rows.forEach(function(schedule){
|
||||
s.updateSchedule(schedule)
|
||||
})
|
||||
|
@ -141,7 +145,16 @@ module.exports = function(s,config,lang,app,io){
|
|||
//
|
||||
s.findSchedule = function(groupKey,name,callback){
|
||||
//presetQueryVals = [ke, type, name]
|
||||
s.sqlQuery("SELECT * FROM Schedules WHERE ke=? AND name=? LIMIT 1",[groupKey,name],function(err,schedules){
|
||||
s.knexQuery({
|
||||
action: "select",
|
||||
columns: "*",
|
||||
table: "Schedules",
|
||||
where: [
|
||||
['ke','=',groupKey],
|
||||
['name','=',name],
|
||||
],
|
||||
limit: 1
|
||||
},function(err,schedules) {
|
||||
var schedule
|
||||
var notFound = false
|
||||
if(schedules && schedules[0]){
|
||||
|
@ -184,13 +197,18 @@ module.exports = function(s,config,lang,app,io){
|
|||
s.closeJsonResponse(res,endData)
|
||||
return
|
||||
}
|
||||
var theQuery = "SELECT * FROM Schedules WHERE ke=?"
|
||||
var theQueryValues = [req.params.ke]
|
||||
var whereQuery = [
|
||||
['ke','=',req.params.ke]
|
||||
]
|
||||
if(req.params.name){
|
||||
theQuery += ' AND name=?'
|
||||
theQueryValues.push(req.params.name)
|
||||
whereQuery.push(['name','=',req.params.name])
|
||||
}
|
||||
s.sqlQuery(theQuery,theQueryValues,function(err,schedules){
|
||||
s.knexQuery({
|
||||
action: "select",
|
||||
columns: "*",
|
||||
table: "Schedules",
|
||||
where: whereQuery,
|
||||
},function(err,schedules) {
|
||||
endData.ok = true
|
||||
schedules = schedules || []
|
||||
schedules.forEach(function(schedule){
|
||||
|
@ -240,7 +258,11 @@ module.exports = function(s,config,lang,app,io){
|
|||
end: form.end,
|
||||
enabled: form.enabled
|
||||
}
|
||||
s.sqlQuery('INSERT INTO Schedules ('+Object.keys(insertData).join(',')+') VALUES (?,?,?,?,?,?)',Object.values(insertData))
|
||||
s.knexQuery({
|
||||
action: "insert",
|
||||
table: "Schedules",
|
||||
insert: insertData
|
||||
})
|
||||
s.tx({
|
||||
f: 'add_schedule',
|
||||
insertData: insertData,
|
||||
|
@ -253,14 +275,23 @@ module.exports = function(s,config,lang,app,io){
|
|||
details: s.stringJSON(form.details),
|
||||
start: form.start,
|
||||
end: form.end,
|
||||
enabled: form.enabled,
|
||||
ke: req.params.ke,
|
||||
name: req.params.name
|
||||
enabled: form.enabled
|
||||
}
|
||||
s.sqlQuery('UPDATE Schedules SET details=?,start=?,end=?,enabled=? WHERE ke=? AND name=?',Object.values(insertData))
|
||||
s.knexQuery({
|
||||
action: "update",
|
||||
table: "Monitors",
|
||||
update: insertData,
|
||||
where: [
|
||||
['ke','=',req.params.ke],
|
||||
['name','=',req.params.name],
|
||||
]
|
||||
})
|
||||
s.tx({
|
||||
f: 'edit_schedule',
|
||||
insertData: insertData,
|
||||
insertData: Object.assign(insertData,{
|
||||
ke: req.params.ke,
|
||||
name: req.params.name,
|
||||
}),
|
||||
ke: req.params.ke,
|
||||
name: req.params.name
|
||||
},'GRP_'+req.params.ke)
|
||||
|
@ -283,7 +314,14 @@ module.exports = function(s,config,lang,app,io){
|
|||
endData.msg = user.lang['Schedule Configuration Not Found']
|
||||
s.closeJsonResponse(res,endData)
|
||||
}else{
|
||||
s.sqlQuery('DELETE FROM Schedules WHERE ke=? AND name=?',[req.params.ke,req.params.name],function(err){
|
||||
s.knexQuery({
|
||||
action: "delete",
|
||||
table: "Schedules",
|
||||
where: [
|
||||
['ke','=',req.params.ke],
|
||||
['name','=',req.params.name],
|
||||
]
|
||||
},function(err){
|
||||
if(!err){
|
||||
endData.msg = lang["Deleted Schedule Configuration"]
|
||||
endData.ok = true
|
||||
|
|
824
libs/socketio.js
824
libs/socketio.js
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue