spacing and quotes
This commit is contained in:
parent
acb95709e6
commit
1928d1153f
|
@ -72,15 +72,15 @@ sub find {
|
|||
$sql .= ' WHERE ' . join(' AND ', @sql_filters ) if @sql_filters;
|
||||
$sql .= ' LIMIT ' . $sql_filters{limit} if $sql_filters{limit};
|
||||
|
||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
||||
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
||||
my $res = $sth->execute( @sql_values )
|
||||
or Fatal( "Can't execute '$sql': ".$sth->errstr() );
|
||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached($sql)
|
||||
or Fatal("Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr());
|
||||
my $res = $sth->execute(@sql_values)
|
||||
or Fatal("Can't execute '$sql': ".$sth->errstr());
|
||||
|
||||
my @results;
|
||||
|
||||
while( my $db_filter = $sth->fetchrow_hashref() ) {
|
||||
my $filter = new ZoneMinder::Filter( $$db_filter{Id}, $db_filter );
|
||||
my $filter = new ZoneMinder::Filter($$db_filter{Id}, $db_filter);
|
||||
push @results, $filter;
|
||||
} # end while
|
||||
$sth->finish();
|
||||
|
@ -98,7 +98,7 @@ sub Execute {
|
|||
my $sql = $self->Sql(undef);
|
||||
|
||||
if ( $self->{HasDiskPercent} ) {
|
||||
my $disk_percent = getDiskPercent( $$self{Storage} ? $$self{Storage}->Path() : () );
|
||||
my $disk_percent = getDiskPercent($$self{Storage} ? $$self{Storage}->Path() : ());
|
||||
$sql =~ s/zmDiskPercent/$disk_percent/g;
|
||||
}
|
||||
if ( $self->{HasDiskBlocks} ) {
|
||||
|
@ -111,16 +111,16 @@ sub Execute {
|
|||
}
|
||||
|
||||
Debug("Filter::Execute SQL ($sql)");
|
||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached( $sql )
|
||||
or Fatal( "Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr() );
|
||||
my $sth = $ZoneMinder::Database::dbh->prepare_cached($sql)
|
||||
or Fatal("Can't prepare '$sql': ".$ZoneMinder::Database::dbh->errstr());
|
||||
my $res = $sth->execute();
|
||||
if ( !$res ) {
|
||||
Error( "Can't execute filter '$sql', ignoring: ".$sth->errstr() );
|
||||
Error("Can't execute filter '$sql', ignoring: ".$sth->errstr());
|
||||
return;
|
||||
}
|
||||
my @results;
|
||||
|
||||
while( my $event = $sth->fetchrow_hashref() ) {
|
||||
while ( my $event = $sth->fetchrow_hashref() ) {
|
||||
push @results, $event;
|
||||
}
|
||||
$sth->finish();
|
||||
|
@ -152,7 +152,7 @@ sub Sql {
|
|||
$self->{Sql} .= ' '.$term->{cnj}.' ';
|
||||
}
|
||||
if ( exists($term->{obr}) ) {
|
||||
$self->{Sql} .= ' '.str_repeat( '(', $term->{obr} ).' ';
|
||||
$self->{Sql} .= ' '.str_repeat('(', $term->{obr}).' ';
|
||||
}
|
||||
my $value = $term->{val};
|
||||
my @value_list;
|
||||
|
@ -216,17 +216,17 @@ sub Sql {
|
|||
if ( $temp_value eq 'ZM_SERVER_ID' ) {
|
||||
$value = "'$ZoneMinder::Config::Config{ZM_SERVER_ID}'";
|
||||
# This gets used later, I forget for what
|
||||
$$self{Server} = new ZoneMinder::Server( $ZoneMinder::Config::Config{ZM_SERVER_ID} );
|
||||
$$self{Server} = new ZoneMinder::Server($ZoneMinder::Config::Config{ZM_SERVER_ID});
|
||||
} elsif ( $temp_value eq 'NULL' ) {
|
||||
$value = $temp_value;
|
||||
} else {
|
||||
$value = "'$temp_value'";
|
||||
# This gets used later, I forget for what
|
||||
$$self{Server} = new ZoneMinder::Server( $temp_value );
|
||||
$$self{Server} = new ZoneMinder::Server($temp_value);
|
||||
}
|
||||
} elsif ( $term->{attr} eq 'StorageId' ) {
|
||||
$value = "'$temp_value'";
|
||||
$$self{Storage} = new ZoneMinder::Storage( $temp_value );
|
||||
$$self{Storage} = new ZoneMinder::Storage($temp_value);
|
||||
} elsif ( $term->{attr} eq 'Name'
|
||||
|| $term->{attr} eq 'Cause'
|
||||
|| $term->{attr} eq 'Notes'
|
||||
|
@ -236,10 +236,9 @@ sub Sql {
|
|||
if ( $temp_value eq 'NULL' ) {
|
||||
$value = $temp_value;
|
||||
} else {
|
||||
$value = DateTimeToSQL( $temp_value );
|
||||
$value = DateTimeToSQL($temp_value);
|
||||
if ( !$value ) {
|
||||
Error( "Error parsing date/time '$temp_value', "
|
||||
."skipping filter '$self->{Name}'\n" );
|
||||
Error("Error parsing date/time '$temp_value', skipping filter '$self->{Name}'");
|
||||
return;
|
||||
}
|
||||
$value = "'$value'";
|
||||
|
@ -248,10 +247,9 @@ sub Sql {
|
|||
if ( $temp_value eq 'NULL' ) {
|
||||
$value = $temp_value;
|
||||
} else {
|
||||
$value = DateTimeToSQL( $temp_value );
|
||||
$value = DateTimeToSQL($temp_value);
|
||||
if ( !$value ) {
|
||||
Error( "Error parsing date/time '$temp_value', "
|
||||
."skipping filter '$self->{Name}'\n" );
|
||||
Error("Error parsing date/time '$temp_value', skipping filter '$self->{Name}'");
|
||||
return;
|
||||
}
|
||||
$value = "to_days( '$value' )";
|
||||
|
@ -260,10 +258,9 @@ sub Sql {
|
|||
if ( $temp_value eq 'NULL' ) {
|
||||
$value = $temp_value;
|
||||
} else {
|
||||
$value = DateTimeToSQL( $temp_value );
|
||||
$value = DateTimeToSQL($temp_value);
|
||||
if ( !$value ) {
|
||||
Error( "Error parsing date/time '$temp_value', "
|
||||
."skipping filter '$self->{Name}'\n" );
|
||||
Error("Error parsing date/time '$temp_value', skipping filter '$self->{Name}'");
|
||||
return;
|
||||
}
|
||||
$value = "extract( hour_second from '$value' )";
|
||||
|
@ -271,7 +268,7 @@ sub Sql {
|
|||
} else {
|
||||
$value = $temp_value;
|
||||
}
|
||||
push( @value_list, $value );
|
||||
push @value_list, $value;
|
||||
} # end foreach temp_value
|
||||
} # end if has an attr
|
||||
if ( $term->{op} ) {
|
||||
|
@ -290,15 +287,15 @@ sub Sql {
|
|||
} elsif ( $term->{op} eq 'IS NOT' ) {
|
||||
$self->{Sql} .= " IS NOT $value";
|
||||
} elsif ( $term->{op} eq '=[]' ) {
|
||||
$self->{Sql} .= " in (".join( ",", @value_list ).")";
|
||||
$self->{Sql} .= ' IN ('.join(',', @value_list).')';
|
||||
} elsif ( $term->{op} eq '!~' ) {
|
||||
$self->{Sql} .= " not in (".join( ",", @value_list ).")";
|
||||
$self->{Sql} .= ' NOT IN ('.join(',', @value_list).')';
|
||||
} else {
|
||||
$self->{Sql} .= ' '.$term->{op}." $value";
|
||||
$self->{Sql} .= ' '.$term->{op}.' '.$value;
|
||||
}
|
||||
} # end if has an operator
|
||||
if ( exists($term->{cbr}) ) {
|
||||
$self->{Sql} .= ' '.str_repeat( ")", $term->{cbr} )." ";
|
||||
$self->{Sql} .= ' '.str_repeat(')', $term->{cbr}).' ';
|
||||
}
|
||||
} # end foreach term
|
||||
} # end if terms
|
||||
|
@ -320,22 +317,22 @@ sub Sql {
|
|||
# Don't do this, it prevents re-generation and concatenation.
|
||||
# If the file already exists, then the video won't be re-recreated
|
||||
if ( $self->{AutoVideo} ) {
|
||||
push @auto_terms, "E.Videoed = 0";
|
||||
push @auto_terms, 'E.Videoed = 0';
|
||||
}
|
||||
if ( $self->{AutoUpload} ) {
|
||||
push @auto_terms, "E.Uploaded = 0";
|
||||
push @auto_terms, 'E.Uploaded = 0';
|
||||
}
|
||||
if ( $self->{AutoEmail} ) {
|
||||
push @auto_terms, "E.Emailed = 0";
|
||||
push @auto_terms, 'E.Emailed = 0';
|
||||
}
|
||||
if ( $self->{AutoMessage} ) {
|
||||
push @auto_terms, "E.Messaged = 0";
|
||||
push @auto_terms, 'E.Messaged = 0';
|
||||
}
|
||||
if ( $self->{AutoExecute} ) {
|
||||
push @auto_terms, "E.Executed = 0";
|
||||
push @auto_terms, 'E.Executed = 0';
|
||||
}
|
||||
if ( @auto_terms ) {
|
||||
$sql .= " and ( ".join( ' or ', @auto_terms )." )";
|
||||
$sql .= ' AND ( '.join(' or ', @auto_terms).' )';
|
||||
}
|
||||
if ( !$filter_expr->{sort_field} ) {
|
||||
$filter_expr->{sort_field} = 'StartTime';
|
||||
|
@ -369,10 +366,10 @@ sub Sql {
|
|||
} else {
|
||||
$sort_column = 'E.StartTime';
|
||||
}
|
||||
my $sort_order = $filter_expr->{sort_asc}?'asc':'desc';
|
||||
$sql .= ' order by '.$sort_column." ".$sort_order;
|
||||
my $sort_order = $filter_expr->{sort_asc} ? 'ASC' : 'DESC';
|
||||
$sql .= ' ORDER BY '.$sort_column." ".$sort_order;
|
||||
if ( $filter_expr->{limit} ) {
|
||||
$sql .= " limit 0,".$filter_expr->{limit};
|
||||
$sql .= ' LIMIT 0,'.$filter_expr->{limit};
|
||||
}
|
||||
$self->{Sql} = $sql;
|
||||
} # end if has Sql
|
||||
|
@ -386,7 +383,7 @@ sub getDiskPercent {
|
|||
if ( $df =~ /\s(\d+)%/ms ) {
|
||||
$space = $1;
|
||||
}
|
||||
return( $space );
|
||||
return $space;
|
||||
}
|
||||
|
||||
sub getDiskBlocks {
|
||||
|
@ -396,7 +393,7 @@ sub getDiskBlocks {
|
|||
if ( $df =~ /\s(\d+)\s+\d+\s+\d+%/ms ) {
|
||||
$space = $1;
|
||||
}
|
||||
return( $space );
|
||||
return $space;
|
||||
}
|
||||
|
||||
sub getLoad {
|
||||
|
@ -405,9 +402,9 @@ sub getLoad {
|
|||
my $load = -1;
|
||||
if ( $uptime =~ /load average:\s+([\d.]+)/ms ) {
|
||||
$load = $1;
|
||||
Info( "Load: $load" );
|
||||
Info("Load: $load");
|
||||
}
|
||||
return( $load );
|
||||
return $load;
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -415,7 +412,7 @@ sub getLoad {
|
|||
#
|
||||
sub strtotime {
|
||||
my $dt_str = shift;
|
||||
return( Date::Manip::UnixDate( $dt_str, '%s' ) );
|
||||
return Date::Manip::UnixDate($dt_str, '%s');
|
||||
}
|
||||
|
||||
#
|
||||
|
@ -424,18 +421,18 @@ sub strtotime {
|
|||
sub str_repeat {
|
||||
my $string = shift;
|
||||
my $count = shift;
|
||||
return( ${string}x${count} );
|
||||
return ${string}x${count};
|
||||
}
|
||||
|
||||
# Formats a date into MySQL format
|
||||
sub DateTimeToSQL {
|
||||
my $dt_str = shift;
|
||||
my $dt_val = strtotime( $dt_str );
|
||||
my $dt_val = strtotime($dt_str);
|
||||
if ( !$dt_val ) {
|
||||
Error( "Unable to parse date string '$dt_str'\n" );
|
||||
return( undef );
|
||||
Error("Unable to parse date string '$dt_str'");
|
||||
return undef;
|
||||
}
|
||||
return( POSIX::strftime( "%Y-%m-%d %H:%M:%S", localtime( $dt_val ) ) );
|
||||
return POSIX::strftime('%Y-%m-%d %H:%M:%S', localtime($dt_val));
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
Loading…
Reference in New Issue