From b6fc0b26282fc802fec4f6cdecdacf3c051561ab Mon Sep 17 00:00:00 2001 From: stan Date: Wed, 13 Feb 2008 22:41:17 +0000 Subject: [PATCH] Bug 447 - Added getEventPath function and changed scripts to use it. git-svn-id: http://svn.zoneminder.com/svn/zm/trunk@2302 e3e1d417-86f3-4887-817a-d78f3d33393f --- scripts/ZoneMinder/lib/ZoneMinder/General.pm | 17 +++++++++++++++++ scripts/zmfilter.pl | 8 ++++---- scripts/zmvideo.pl | 10 +--------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/General.pm b/scripts/ZoneMinder/lib/ZoneMinder/General.pm index 589d16905..3ff40ce8a 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/General.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/General.pm @@ -43,6 +43,7 @@ our @ISA = qw(Exporter ZoneMinder::Base); our %EXPORT_TAGS = ( 'functions' => [ qw( executeShellCommand + getEventPath deleteEventFiles ) ] ); @@ -76,6 +77,22 @@ sub executeShellCommand( $ ) } } +sub getEventPath( $ ) +{ + my $event = shift; + + my $event_path = ""; + if ( ZM_USE_DEEP_STORAGE ) + { + $event_path = ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorId}.'/'.strftime( "%y/%m/%d/%H/%M/%S", localtime($event->{Time}) ); + } + else + { + $event_path = ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorId}.'/'.$event->{Id}; + } + return( $event_path ); +} + sub deleteEventFiles( $;$ ) { # diff --git a/scripts/zmfilter.pl b/scripts/zmfilter.pl index ac1eaa1b9..6b454adf8 100644 --- a/scripts/zmfilter.pl +++ b/scripts/zmfilter.pl @@ -710,7 +710,7 @@ sub uploadArchFile my $event = shift; my $arch_file = ZM_UPLOAD_FTP_LOC_DIR.'/'.$event->{MonitorName}.'-'.$event->{Id}; - my $arch_image_path = "$event->{MonitorId}/$event->{Id}/".((ZM_UPLOAD_ARCH_ANALYSE)?'{*analyse,*capture}':'*capture').".jpg"; + my $arch_image_path = getEventPath( $event )."/".((ZM_UPLOAD_ARCH_ANALYSE)?'{*analyse,*capture}':'*capture').".jpg"; my $arch_error; if ( ZM_UPLOAD_ARCH_FORMAT eq "zip" ) @@ -860,14 +860,14 @@ sub substituteTags $text =~ s/%EPIM%/$url?view=frame&mid=$event->{MonitorId}&eid=$event->{Id}&fid=$max_alarm_frame->{FrameId}/g; if ( $attachments_ref && $text =~ s/%EI1%//g ) { - push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%d/%d/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $event->{MonitorId}, $event->{Id}, $first_alarm_frame->{FrameId} ) } ); + push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", getEventPath( $event ), $first_alarm_frame->{FrameId} ) } ); } if ( $attachments_ref && $text =~ s/%EIM%//g ) { # Don't attach the same image twice if ( !@$attachments_ref || ($first_alarm_frame->{FrameId} != $max_alarm_frame->{FrameId} ) ) { - push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%d/%d/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", $event->{MonitorId}, $event->{Id}, $max_alarm_frame->{FrameId} ) } ); + push( @$attachments_ref, { type=>"image/jpeg", path=>sprintf( "%s/%0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg", getEventPath( $event ), $max_alarm_frame->{FrameId} ) } ); } } } @@ -1092,7 +1092,7 @@ sub executeCommand my $filter = shift; my $event = shift; - my $event_path = "$event->{MonitorId}/$event->{Id}"; + my $event_path = getEventPath( $event ); my $command = $filter->{AutoExecuteCmd}; $command .= " $event_path"; diff --git a/scripts/zmvideo.pl b/scripts/zmvideo.pl index 7cc4c8cf7..1b71010ad 100644 --- a/scripts/zmvideo.pl +++ b/scripts/zmvideo.pl @@ -166,15 +166,7 @@ my $sth = $dbh->prepare_cached( $sql ) or Fatal( "Can't prepare '$sql': ".$dbh-> my $res = $sth->execute() or Fatal( "Can't execute: ".$sth->errstr() ); my $event = $sth->fetchrow_hashref(); $sth->finish(); -my $event_path; -if ( ZM_USE_DEEP_STORAGE ) -{ - $event_path = ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorId}.'/'.strftime( "%y/%m/%d/%H/%M/%S", localtime($event->{Time}) ); -} -else -{ - $event_path = ZM_PATH_WEB.'/'.ZM_DIR_EVENTS.'/'.$event->{MonitorId}.'/'.$event->{Id}; -} +my $event_path = getEventPath( $event ); chdir( $event_path ); ( my $video_name = $event->{Name} ) =~ s/\s/_/g;