Fix cron.js : Max Keep Days
- now main "Max Keep Days" excludes monitors with custom "Max Keep Days"merge-requests/25/head
parent
9bde8ba386
commit
294055eaba
96
cron.js
96
cron.js
|
@ -57,59 +57,70 @@ s.sqlDate = function(value){
|
||||||
}else{
|
}else{
|
||||||
value = value.toUpperCase()
|
value = value.toUpperCase()
|
||||||
if (value.slice(-1) === 'S') {
|
if (value.slice(-1) === 'S') {
|
||||||
value = value.slice(0, -1);
|
value = value.slice(0, -1);
|
||||||
}
|
}
|
||||||
dateQueryFunction = "DATE_SUB(NOW(), INTERVAL "+value+")"
|
dateQueryFunction = "DATE_SUB(NOW(), INTERVAL "+value+")"
|
||||||
}
|
}
|
||||||
return dateQueryFunction
|
return dateQueryFunction
|
||||||
}
|
}
|
||||||
s.sqlQuery = function(query,values,onMoveOn,hideLog){
|
s.mergeQueryValues = function(query,values){
|
||||||
s.debugLog(query,values)
|
|
||||||
if(!values){values=[]}
|
if(!values){values=[]}
|
||||||
var valuesNotFunction = true;
|
var valuesNotFunction = true;
|
||||||
if(typeof values === 'function'){
|
if(typeof values === 'function'){
|
||||||
var onMoveOn = values;
|
|
||||||
var values = [];
|
var values = [];
|
||||||
valuesNotFunction = false;
|
valuesNotFunction = false;
|
||||||
}
|
}
|
||||||
if(!onMoveOn){onMoveOn=function(){}}
|
|
||||||
if(values&&valuesNotFunction){
|
if(values&&valuesNotFunction){
|
||||||
var splitQuery = query.split('?')
|
var splitQuery = query.split('?')
|
||||||
var newQuery = ''
|
var newQuery = ''
|
||||||
splitQuery.forEach(function(v,n){
|
splitQuery.forEach(function(v,n){
|
||||||
newQuery += v
|
newQuery += v
|
||||||
if(values[n]){
|
var value = values[n]
|
||||||
if(isNaN(values[n])){
|
if(value){
|
||||||
newQuery += "'"+values[n]+"'"
|
if(isNaN(value) || value instanceof Date){
|
||||||
|
newQuery += "'"+value+"'"
|
||||||
}else{
|
}else{
|
||||||
newQuery += values[n]
|
newQuery += value
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}else{
|
}else{
|
||||||
newQuery = query
|
newQuery = query
|
||||||
}
|
}
|
||||||
return s.databaseEngine.raw(newQuery)
|
return newQuery
|
||||||
.asCallback(function(err,r){
|
}
|
||||||
if(err&&config.databaseLogs){
|
s.stringToSqlTime = function(value){
|
||||||
s.systemLog('s.sqlQuery QUERY',query)
|
newValue = new Date(value.replace('T',' '))
|
||||||
s.systemLog('s.sqlQuery ERROR',err)
|
return newValue
|
||||||
|
}
|
||||||
|
s.sqlQuery = function(query,values,onMoveOn){
|
||||||
|
if(!values){values=[]}
|
||||||
|
if(typeof values === 'function'){
|
||||||
|
var onMoveOn = values;
|
||||||
|
var values = [];
|
||||||
|
}
|
||||||
|
if(!onMoveOn){onMoveOn=function(){}}
|
||||||
|
var mergedQuery = s.mergeQueryValues(query,values)
|
||||||
|
s.debugLog('s.sqlQuery QUERY',mergedQuery)
|
||||||
|
return s.databaseEngine
|
||||||
|
.raw(query,values)
|
||||||
|
.asCallback(function(err,r){
|
||||||
|
if(err){
|
||||||
|
console.log('s.sqlQuery QUERY ERRORED',query)
|
||||||
|
console.log('s.sqlQuery ERROR',err)
|
||||||
|
}
|
||||||
|
if(onMoveOn && typeof onMoveOn === 'function'){
|
||||||
|
switch(databaseOptions.client){
|
||||||
|
case'sqlite3':
|
||||||
|
if(!r)r=[]
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if(r)r=r[0]
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if(onMoveOn)
|
onMoveOn(err,r)
|
||||||
if(typeof onMoveOn === 'function'){
|
}
|
||||||
switch(databaseOptions.client){
|
})
|
||||||
case'sqlite3':
|
|
||||||
if(!r)r=[]
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if(r)r=r[0]
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
onMoveOn(err,r)
|
|
||||||
}else{
|
|
||||||
s.debugLog('onMoveOn',onMoveOn)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
s.debugLog = function(arg1,arg2){
|
s.debugLog = function(arg1,arg2){
|
||||||
|
@ -177,6 +188,20 @@ s.checkFilterRules=function(v,callback){
|
||||||
}
|
}
|
||||||
//delete old videos with filter
|
//delete old videos with filter
|
||||||
if(config.cron.deleteOld===true){
|
if(config.cron.deleteOld===true){
|
||||||
|
var where = [{
|
||||||
|
"p1":"end",
|
||||||
|
"p2":"<",
|
||||||
|
"p3":s.sqlDate(v.d.days+" DAYS"),
|
||||||
|
"p3_type":"function",
|
||||||
|
}]
|
||||||
|
//exclude monitors with their own max days
|
||||||
|
v.monitorsWithMaxKeepDays.forEach(function(mid){
|
||||||
|
where.push({
|
||||||
|
"p1":"mid",
|
||||||
|
"p2":"!=",
|
||||||
|
"p3":mid,
|
||||||
|
})
|
||||||
|
})
|
||||||
v.d.filters.deleteOldVideosByCron={
|
v.d.filters.deleteOldVideosByCron={
|
||||||
"id":"deleteOldVideosByCron",
|
"id":"deleteOldVideosByCron",
|
||||||
"name":"deleteOldVideosByCron",
|
"name":"deleteOldVideosByCron",
|
||||||
|
@ -188,12 +213,7 @@ s.checkFilterRules=function(v,callback){
|
||||||
"email":"0",
|
"email":"0",
|
||||||
"delete":"1",
|
"delete":"1",
|
||||||
"execute":"",
|
"execute":"",
|
||||||
"where":[{
|
"where":where
|
||||||
"p1":"end",
|
|
||||||
"p2":"<",
|
|
||||||
"p3":s.sqlDate(v.d.days+" DAYS"),
|
|
||||||
"p3_type":"function",
|
|
||||||
}]
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
s.debugLog('Filters')
|
s.debugLog('Filters')
|
||||||
|
@ -456,9 +476,11 @@ s.processUser = function(number,rows){
|
||||||
if(!v.d.filters||v.d.filters==''){
|
if(!v.d.filters||v.d.filters==''){
|
||||||
v.d.filters={};
|
v.d.filters={};
|
||||||
}
|
}
|
||||||
|
v.monitorsWithMaxKeepDays = []
|
||||||
rr.forEach(function(b,m){
|
rr.forEach(function(b,m){
|
||||||
b.details=JSON.parse(b.details);
|
b.details=JSON.parse(b.details);
|
||||||
if(b.details.max_keep_days&&b.details.max_keep_days!==''){
|
if(b.details.max_keep_days&&b.details.max_keep_days!==''){
|
||||||
|
v.monitorsWithMaxKeepDays.push(b.mid)
|
||||||
v.d.filters['deleteOldVideosByCron'+b.mid]={
|
v.d.filters['deleteOldVideosByCron'+b.mid]={
|
||||||
"id":'deleteOldVideosByCron'+b.mid,
|
"id":'deleteOldVideosByCron'+b.mid,
|
||||||
"name":'deleteOldVideosByCron'+b.mid,
|
"name":'deleteOldVideosByCron'+b.mid,
|
||||||
|
@ -471,7 +493,7 @@ s.processUser = function(number,rows){
|
||||||
"delete":"1",
|
"delete":"1",
|
||||||
"execute":"",
|
"execute":"",
|
||||||
"where":[{
|
"where":[{
|
||||||
"p1":"ke",
|
"p1":"mid",
|
||||||
"p2":"=",
|
"p2":"=",
|
||||||
"p3":b.mid
|
"p3":b.mid
|
||||||
},{
|
},{
|
||||||
|
@ -538,4 +560,4 @@ io.on('f',function(d){
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
console.log('Shinobi : cron.js started')
|
console.log('Shinobi : cron.js started')
|
||||||
|
|
Loading…
Reference in New Issue