From ca8b49e1d470bda184df8ca51d43ac94438d2fd4 Mon Sep 17 00:00:00 2001 From: stan Date: Thu, 29 May 2003 16:07:42 +0000 Subject: [PATCH] Fixed filter bug with events not being checked unless filters have been reloaded. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@544 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/zmfilter.pl.z | 124 +++++++++++++++++++++--------------------- 1 file changed, 62 insertions(+), 62 deletions(-) diff --git a/scripts/zmfilter.pl.z b/scripts/zmfilter.pl.z index e4bab079f..6375adf21 100755 --- a/scripts/zmfilter.pl.z +++ b/scripts/zmfilter.pl.z @@ -219,71 +219,71 @@ while( 1 ) print( "Reloading filters\n" ) if ( VERBOSE ); $last_action = time(); $filters = GetFilters( $monitor ); + } - foreach my $filter ( @$filters ) + foreach my $filter ( @$filters ) + { + print( "Checking filter '$filter->{Name}'". + ($filter->{AutoArchive}?", archive":""). + ($filter->{AutoDelete}?", delete":""). + ($filter->{AutoUpload}?", upload":""). + ($filter->{AutoEmail}?", email":""). + ($filter->{AutoMessage}?", message":""). + "\n" ) if ( VERBOSE ); + my $sql = $filter->{Sql}; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res; + if ( $filter->{has_dates} ) { - print( "Checking filter '$filter->{Name}'". - ($filter->{AutoArchive}?", archive":""). - ($filter->{AutoDelete}?", delete":""). - ($filter->{AutoUpload}?", upload":""). - ($filter->{AutoEmail}?", email":""). - ($filter->{AutoMessage}?", message":""). - "\n" ) if ( VERBOSE ); - my $sql = $filter->{Sql}; - my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res; - if ( $filter->{has_dates} ) - { - $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); - } - else - { - $res = $sth->execute( $event_id ) or die( "Can't execute: ".$sth->errstr() ); - } - - while( my $event = $sth->fetchrow_hashref() ) - { - print( "Checking event $event->{Id}\n" ) if ( VERBOSE ); - if ( ZM_OPT_EMAIL && $filter->{AutoEmail} ) - { - next if ( $event->{Emailed} ); - - sendEmail( $filter, $event ); - } - if ( ZM_OPT_MESSAGE && $filter->{AutoMessage} ) - { - next if ( $event->{Messaged} ); - - sendMessage( $filter, $event ); - } - if ( ZM_OPT_UPLOAD && $filter->{AutoUpload} ) - { - next if ( $event->{Uploaded} ); - - uploadArchFile( $filter, $event ); - } - if ( $filter->{AutoArchive} ) - { - print( "Archiving event $event->{Id}\n" ); - # Do it individually to avoid locking up the table for new events - my $sql = "update Events set Archived = 1 where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or die( "Can't execute: ".$sth->errstr() ); - } - if ( $filter->{AutoDelete} ) - { - print( "Deleting event $event->{Id}\n" ); - # Do it individually to avoid locking up the table for new events - my $sql = "delete from Events where Id = ?"; - my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); - my $res = $sth->execute( $event->{Id} ) or die( "Can't execute: ".$sth->errstr() ); - - # We could now delete from the Frames and Stats table and the files themselves, - # but we can let the database checker sort that out for us instead. - } - } - $sth->finish(); + $res = $sth->execute() or die( "Can't execute: ".$sth->errstr() ); } + else + { + $res = $sth->execute( $event_id ) or die( "Can't execute: ".$sth->errstr() ); + } + + while( my $event = $sth->fetchrow_hashref() ) + { + print( "Checking event $event->{Id}\n" ) if ( VERBOSE ); + if ( ZM_OPT_EMAIL && $filter->{AutoEmail} ) + { + next if ( $event->{Emailed} ); + + sendEmail( $filter, $event ); + } + if ( ZM_OPT_MESSAGE && $filter->{AutoMessage} ) + { + next if ( $event->{Messaged} ); + + sendMessage( $filter, $event ); + } + if ( ZM_OPT_UPLOAD && $filter->{AutoUpload} ) + { + next if ( $event->{Uploaded} ); + + uploadArchFile( $filter, $event ); + } + if ( $filter->{AutoArchive} ) + { + print( "Archiving event $event->{Id}\n" ); + # Do it individually to avoid locking up the table for new events + my $sql = "update Events set Archived = 1 where Id = ?"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $event->{Id} ) or die( "Can't execute: ".$sth->errstr() ); + } + if ( $filter->{AutoDelete} ) + { + print( "Deleting event $event->{Id}\n" ); + # Do it individually to avoid locking up the table for new events + my $sql = "delete from Events where Id = ?"; + my $sth = $dbh->prepare_cached( $sql ) or die( "Can't prepare '$sql': ".$dbh->errstr() ); + my $res = $sth->execute( $event->{Id} ) or die( "Can't execute: ".$sth->errstr() ); + + # We could now delete from the Frames and Stats table and the files themselves, + # but we can let the database checker sort that out for us instead. + } + } + $sth->finish(); } $event_id = $last_event_id; }