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
This commit is contained in:
stan 2003-05-29 16:07:42 +00:00
parent 0f693c084f
commit ca8b49e1d4
1 changed files with 62 additions and 62 deletions

View File

@ -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;
}