Rename StartTime, EndTime in Events to StartDateTime and EndDateTime

This commit is contained in:
Isaac Connor 2020-11-04 13:49:39 -05:00
parent 4731041a40
commit adbd3486bf
10 changed files with 90 additions and 88 deletions

View File

@ -152,13 +152,13 @@ BEGIN
SET SET
ArchivedEvents = GREATEST(COALESCE(ArchivedEvents,0)-1,0), ArchivedEvents = GREATEST(COALESCE(ArchivedEvents,0)-1,0),
ArchivedEventDiskSpace = GREATEST(COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0),0) ArchivedEventDiskSpace = GREATEST(COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0),0)
WHERE Id=OLD.MonitorId; WHERE Monitors.Id=OLD.MonitorId;
ELSE ELSE
IF ( OLD.DiskSpace != NEW.DiskSpace ) THEN IF ( OLD.DiskSpace != NEW.DiskSpace ) THEN
UPDATE Events_Archived SET DiskSpace=NEW.DiskSpace WHERE EventId=NEW.Id; UPDATE Events_Archived SET DiskSpace=NEW.DiskSpace WHERE EventId=NEW.Id;
UPDATE Monitors SET UPDATE Monitors SET
ArchivedEventDiskSpace = GREATEST(COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0) + COALESCE(NEW.DiskSpace,0),0) ArchivedEventDiskSpace = GREATEST(COALESCE(ArchivedEventDiskSpace,0) - COALESCE(OLD.DiskSpace,0) + COALESCE(NEW.DiskSpace,0),0)
WHERE Id=OLD.MonitorId; WHERE Monitors.Id=OLD.MonitorId;
END IF; END IF;
END IF; END IF;
ELSEIF ( NEW.Archived AND diff ) THEN ELSEIF ( NEW.Archived AND diff ) THEN
@ -185,10 +185,10 @@ CREATE TRIGGER event_insert_trigger AFTER INSERT ON Events
FOR EACH ROW FOR EACH ROW
BEGIN BEGIN
INSERT INTO Events_Hour (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0); INSERT INTO Events_Hour (EventId,MonitorId,StartDateTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartDateTime,0);
INSERT INTO Events_Day (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0); INSERT INTO Events_Day (EventId,MonitorId,StartDateTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartDateTime,0);
INSERT INTO Events_Week (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0); INSERT INTO Events_Week (EventId,MonitorId,StartDateTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartDateTime,0);
INSERT INTO Events_Month (EventId,MonitorId,StartTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartTime,0); INSERT INTO Events_Month (EventId,MonitorId,StartDateTime,DiskSpace) VALUES (NEW.Id,NEW.MonitorId,NEW.StartDateTime,0);
UPDATE Monitors SET UPDATE Monitors SET
HourEvents = COALESCE(HourEvents,0)+1, HourEvents = COALESCE(HourEvents,0)+1,
DayEvents = COALESCE(DayEvents,0)+1, DayEvents = COALESCE(DayEvents,0)+1,

View File

@ -189,8 +189,8 @@ CREATE TABLE `Events` (
`SecondaryStorageId` smallint(5) unsigned default 0, `SecondaryStorageId` smallint(5) unsigned default 0,
`Name` varchar(64) NOT NULL default '', `Name` varchar(64) NOT NULL default '',
`Cause` varchar(32) NOT NULL default '', `Cause` varchar(32) NOT NULL default '',
`StartTime` datetime default NULL, `StartDateTime` datetime default NULL,
`EndTime` datetime default NULL, `EndDateTime` datetime default NULL,
`Width` smallint(5) unsigned NOT NULL default '0', `Width` smallint(5) unsigned NOT NULL default '0',
`Height` smallint(5) unsigned NOT NULL default '0', `Height` smallint(5) unsigned NOT NULL default '0',
`Length` decimal(10,2) NOT NULL default '0.00', `Length` decimal(10,2) NOT NULL default '0.00',
@ -216,52 +216,52 @@ CREATE TABLE `Events` (
PRIMARY KEY (`Id`), PRIMARY KEY (`Id`),
KEY `Events_MonitorId_idx` (`MonitorId`), KEY `Events_MonitorId_idx` (`MonitorId`),
KEY `Events_StorageId_idx` (`StorageId`), KEY `Events_StorageId_idx` (`StorageId`),
KEY `Events_StartTime_idx` (`StartTime`), KEY `Events_StartDateTime_idx` (`StartDateTime`),
KEY `Events_EndTime_DiskSpace` (`EndTime`,`DiskSpace`) KEY `Events_EndDateTime_DiskSpace` (`EndDateTime`,`DiskSpace`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;
DROP TABLE IF EXISTS `Events_Hour`; DROP TABLE IF EXISTS `Events_Hour`;
CREATE TABLE `Events_Hour` ( CREATE TABLE `Events_Hour` (
`EventId` BIGINT unsigned NOT NULL, `EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL, `MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL, `StartDateTime` datetime default NULL,
`DiskSpace` bigint default NULL, `DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`), PRIMARY KEY (`EventId`),
KEY `Events_Hour_MonitorId_idx` (`MonitorId`), KEY `Events_Hour_MonitorId_idx` (`MonitorId`),
KEY `Events_Hour_StartTime_idx` (`StartTime`) KEY `Events_Hour_StartDateTime_idx` (`StartDateTime`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;
DROP TABLE IF EXISTS `Events_Day`; DROP TABLE IF EXISTS `Events_Day`;
CREATE TABLE `Events_Day` ( CREATE TABLE `Events_Day` (
`EventId` BIGINT unsigned NOT NULL, `EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL, `MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL, `StartDateTime` datetime default NULL,
`DiskSpace` bigint default NULL, `DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`), PRIMARY KEY (`EventId`),
KEY `Events_Day_MonitorId_idx` (`MonitorId`), KEY `Events_Day_MonitorId_idx` (`MonitorId`),
KEY `Events_Day_StartTime_idx` (`StartTime`) KEY `Events_Day_StartDateTime_idx` (`StartDateTime`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;
DROP TABLE IF EXISTS `Events_Week`; DROP TABLE IF EXISTS `Events_Week`;
CREATE TABLE `Events_Week` ( CREATE TABLE `Events_Week` (
`EventId` BIGINT unsigned NOT NULL, `EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL, `MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL, `StartDateTime` datetime default NULL,
`DiskSpace` bigint default NULL, `DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`), PRIMARY KEY (`EventId`),
KEY `Events_Week_MonitorId_idx` (`MonitorId`), KEY `Events_Week_MonitorId_idx` (`MonitorId`),
KEY `Events_Week_StartTime_idx` (`StartTime`) KEY `Events_Week_StartDateTime_idx` (`StartDateTime`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;
DROP TABLE IF EXISTS `Events_Month`; DROP TABLE IF EXISTS `Events_Month`;
CREATE TABLE `Events_Month` ( CREATE TABLE `Events_Month` (
`EventId` BIGINT unsigned NOT NULL, `EventId` BIGINT unsigned NOT NULL,
`MonitorId` int(10) unsigned NOT NULL, `MonitorId` int(10) unsigned NOT NULL,
`StartTime` datetime default NULL, `StartDateTime` datetime default NULL,
`DiskSpace` bigint default NULL, `DiskSpace` bigint default NULL,
PRIMARY KEY (`EventId`), PRIMARY KEY (`EventId`),
KEY `Events_Month_MonitorId_idx` (`MonitorId`), KEY `Events_Month_MonitorId_idx` (`MonitorId`),
KEY `Events_Month_StartTime_idx` (`StartTime`) KEY `Events_Month_StartDateTime_idx` (`StartDateTime`)
) ENGINE=@ZM_MYSQL_ENGINE@; ) ENGINE=@ZM_MYSQL_ENGINE@;

View File

@ -68,8 +68,8 @@ $serial = $primary_key = 'Id';
SecondaryStorageId SecondaryStorageId
Name Name
Cause Cause
StartTime StartDateTime
EndTime EndDateTime
Width Width
Height Height
Length Length
@ -111,8 +111,8 @@ sub Time {
$_[0]{Time} = $_[1]; $_[0]{Time} = $_[1];
} }
if ( ! defined $_[0]{Time} ) { if ( ! defined $_[0]{Time} ) {
if ( $_[0]{StartTime} ) { if ( $_[0]{StartDateTime} ) {
$_[0]{Time} = Date::Parse::str2time( $_[0]{StartTime} ); $_[0]{Time} = Date::Parse::str2time( $_[0]{StartDateTime} );
} }
} }
return $_[0]{Time}; return $_[0]{Time};
@ -364,11 +364,11 @@ sub delete {
my $in_zmaudit = ( $0 =~ 'zmaudit.pl$'); my $in_zmaudit = ( $0 =~ 'zmaudit.pl$');
if ( ! $in_zmaudit ) { if ( ! $in_zmaudit ) {
if ( ! ( $event->{Id} and $event->{MonitorId} and $event->{StartTime} ) ) { if ( ! ( $event->{Id} and $event->{MonitorId} and $event->{StartDateTime} ) ) {
# zmfilter shouldn't delete anything in an odd situation. zmaudit will though. # zmfilter shouldn't delete anything in an odd situation. zmaudit will though.
my ( $caller, undef, $line ) = caller; my ( $caller, undef, $line ) = caller;
Warning("$0 Can't Delete event $event->{Id} from Monitor $event->{MonitorId} StartTime:". Warning("$0 Can't Delete event $event->{Id} from Monitor $event->{MonitorId} StartDateTime:".
(defined($event->{StartTime})?$event->{StartTime}:'undef')." from $caller:$line"); (defined($event->{StartDateTime})?$event->{StartDateTime}:'undef')." from $caller:$line");
return; return;
} }
if ( !($event->Storage()->Path() and -e $event->Storage()->Path()) ) { if ( !($event->Storage()->Path() and -e $event->Storage()->Path()) ) {
@ -379,7 +379,7 @@ sub delete {
if ( $$event{Id} ) { if ( $$event{Id} ) {
# Need to have an event Id if we are to delete from the db. # Need to have an event Id if we are to delete from the db.
Info("Deleting event $event->{Id} from Monitor $event->{MonitorId} StartTime:$event->{StartTime} from ".$event->Path()); Info("Deleting event $event->{Id} from Monitor $event->{MonitorId} StartDateTime:$event->{StartDateTime} from ".$event->Path());
$ZoneMinder::Database::dbh->ping(); $ZoneMinder::Database::dbh->ping();
my $in_transaction = $ZoneMinder::Database::dbh->{AutoCommit} ? 0 : 1; my $in_transaction = $ZoneMinder::Database::dbh->{AutoCommit} ? 0 : 1;
@ -820,9 +820,9 @@ sub recover_timestamps {
my $duration = $last_timestamp - $first_timestamp; my $duration = $last_timestamp - $first_timestamp;
$Event->Length($duration); $Event->Length($duration);
$Event->StartTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp) ); $Event->StartDateTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp) );
$Event->EndTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $last_timestamp) ); $Event->EndDateTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $last_timestamp) );
Debug("From capture Jpegs have duration $duration = $last_timestamp - $first_timestamp : $$Event{StartTime} to $$Event{EndTime}"); Debug("From capture Jpegs have duration $duration = $last_timestamp - $first_timestamp : $$Event{StartDateTime} to $$Event{EndDateTime}");
$ZoneMinder::Database::dbh->begin_work(); $ZoneMinder::Database::dbh->begin_work();
foreach my $jpg ( @capture_jpgs ) { foreach my $jpg ( @capture_jpgs ) {
my ( $id ) = $jpg =~ /^(\d+)\-capture\.jpg$/; my ( $id ) = $jpg =~ /^(\d+)\-capture\.jpg$/;
@ -858,8 +858,8 @@ sub recover_timestamps {
} }
my $seconds = ($h*60*60)+($m*60)+$s; my $seconds = ($h*60*60)+($m*60)+$s;
$Event->Length($seconds.'.'.$u); $Event->Length($seconds.'.'.$u);
$Event->StartTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp) ); $Event->StartDateTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp) );
$Event->EndTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp+$seconds) ); $Event->EndDateTime( Date::Format::time2str('%Y-%m-%d %H:%M:%S', $first_timestamp+$seconds) );
} }
if ( @mp4_files ) { if ( @mp4_files ) {
$Event->DefaultVideo($mp4_files[0]); $Event->DefaultVideo($mp4_files[0]);

View File

@ -149,7 +149,7 @@ sub Sql {
my $filter_expr = ZoneMinder::General::jsonDecode($self->{Query_json}); my $filter_expr = ZoneMinder::General::jsonDecode($self->{Query_json});
my $sql = 'SELECT E.*, my $sql = 'SELECT E.*,
unix_timestamp(E.StartTime) as Time, unix_timestamp(E.StartDateTime) as Time,
M.Name as MonitorName, M.Name as MonitorName,
M.DefaultRate, M.DefaultRate,
M.DefaultScale M.DefaultScale
@ -184,27 +184,25 @@ sub Sql {
$self->{Sql} .= $Config{ZM_SERVER_ID}; $self->{Sql} .= $Config{ZM_SERVER_ID};
# StartTime options # StartTime options
} elsif ( $term->{attr} eq 'DateTime' ) { } elsif ( $term->{attr} eq 'DateTime' ) {
$self->{Sql} .= 'E.StartTime'; $self->{Sql} .= 'E.StartDateTime';
} elsif ( $term->{attr} eq 'StartDateTime' ) {
$self->{Sql} .= 'E.StartTime';
} elsif ( $term->{attr} eq 'Date' ) { } elsif ( $term->{attr} eq 'Date' ) {
$self->{Sql} .= 'to_days( E.StartTime )'; $self->{Sql} .= 'to_days( E.StartDateTime )';
} elsif ( $term->{attr} eq 'StartDate' ) { } elsif ( $term->{attr} eq 'StartDate' ) {
$self->{Sql} .= 'to_days( E.StartTime )'; $self->{Sql} .= 'to_days( E.StartDateTime )';
} elsif ( $term->{attr} eq 'Time' or $term->{attr} eq 'StartTime' ) { } elsif ( $term->{attr} eq 'Time' or $term->{attr} eq 'StartTime' ) {
$self->{Sql} .= 'extract( hour_second from E.StartTime )'; $self->{Sql} .= 'extract( hour_second from E.StartDateTime )';
} elsif ( $term->{attr} eq 'Weekday' or $term->{attr} eq 'StartWeekday' ) { } elsif ( $term->{attr} eq 'Weekday' or $term->{attr} eq 'StartWeekday' ) {
$self->{Sql} .= 'weekday( E.StartTime )'; $self->{Sql} .= 'weekday( E.StartDateTime )';
# EndTIme options # EndTIme options
} elsif ( $term->{attr} eq 'EndDateTime' ) { } elsif ( $term->{attr} eq 'EndDateTime' ) {
$self->{Sql} .= 'E.EndTime'; $self->{Sql} .= 'E.EndDateTime';
} elsif ( $term->{attr} eq 'EndDate' ) { } elsif ( $term->{attr} eq 'EndDate' ) {
$self->{Sql} .= 'to_days( E.EndTime )'; $self->{Sql} .= 'to_days( E.EndDateTime )';
} elsif ( $term->{attr} eq 'EndTime' ) { } elsif ( $term->{attr} eq 'EndDateTime' ) {
$self->{Sql} .= 'extract( hour_second from E.EndTime )'; $self->{Sql} .= 'extract( hour_second from E.EndDateTime )';
} elsif ( $term->{attr} eq 'EndWeekday' ) { } elsif ( $term->{attr} eq 'EndWeekday' ) {
$self->{Sql} .= "weekday( E.EndTime )"; $self->{Sql} .= "weekday( E.EndDateTime )";
} elsif ( $term->{attr} eq 'ExistsInFileSystem' ) { } elsif ( $term->{attr} eq 'ExistsInFileSystem' ) {
push @{$self->{PostSQLConditions}}, $term; push @{$self->{PostSQLConditions}}, $term;
$self->{Sql} .= 'TRUE /* ExistsInFileSystem */'; $self->{Sql} .= 'TRUE /* ExistsInFileSystem */';
@ -368,7 +366,7 @@ sub Sql {
$sql .= ' AND ( '.join(' or ', @auto_terms).' )'; $sql .= ' AND ( '.join(' or ', @auto_terms).' )';
} }
if ( !$filter_expr->{sort_field} ) { if ( !$filter_expr->{sort_field} ) {
$filter_expr->{sort_field} = 'StartTime'; $filter_expr->{sort_field} = 'StartDateTime';
$filter_expr->{sort_asc} = 0; $filter_expr->{sort_asc} = 0;
} }
my $sort_column = ''; my $sort_column = '';
@ -378,10 +376,14 @@ sub Sql {
$sort_column = 'M.Name'; $sort_column = 'M.Name';
} elsif ( $filter_expr->{sort_field} eq 'Name' ) { } elsif ( $filter_expr->{sort_field} eq 'Name' ) {
$sort_column = 'E.Name'; $sort_column = 'E.Name';
} elsif ( $filter_expr->{sort_field} eq 'StartDateTime' ) {
$sort_column = 'E.StartDateTime';
} elsif ( $filter_expr->{sort_field} eq 'StartTime' ) { } elsif ( $filter_expr->{sort_field} eq 'StartTime' ) {
$sort_column = 'E.StartTime'; $sort_column = 'E.StartDateTime';
} elsif ( $filter_expr->{sort_field} eq 'EndTime' ) { } elsif ( $filter_expr->{sort_field} eq 'EndTime' ) {
$sort_column = 'E.EndTime'; $sort_column = 'E.EndDateTime';
} elsif ( $filter_expr->{sort_field} eq 'EndDateTime' ) {
$sort_column = 'E.EndDateTime';
} elsif ( $filter_expr->{sort_field} eq 'Secs' ) { } elsif ( $filter_expr->{sort_field} eq 'Secs' ) {
$sort_column = 'E.Length'; $sort_column = 'E.Length';
} elsif ( $filter_expr->{sort_field} eq 'Frames' ) { } elsif ( $filter_expr->{sort_field} eq 'Frames' ) {
@ -397,7 +399,7 @@ sub Sql {
} elsif ( $filter_expr->{sort_field} eq 'DiskSpace' ) { } elsif ( $filter_expr->{sort_field} eq 'DiskSpace' ) {
$sort_column = 'E.DiskSpace'; $sort_column = 'E.DiskSpace';
} else { } else {
$sort_column = 'E.StartTime'; $sort_column = 'E.StartDateTime';
} }
my $sort_order = $filter_expr->{sort_asc} ? 'ASC' : 'DESC'; my $sort_order = $filter_expr->{sort_asc} ? 'ASC' : 'DESC';
$sql .= ' ORDER BY '.$sort_column.' '.$sort_order; $sql .= ' ORDER BY '.$sort_column.' '.$sort_order;

View File

@ -262,21 +262,21 @@ sub createEvent {
} }
$frame->{Type} = $frame->{Score}>0?'Alarm':'Normal' unless( $frame->{Type} ); $frame->{Type} = $frame->{Score}>0?'Alarm':'Normal' unless( $frame->{Type} );
$frame->{Delta} = $lastTimestamp?($frame->{TimeStamp}-$lastTimestamp):0.0; $frame->{Delta} = $lastTimestamp?($frame->{TimeStamp}-$lastTimestamp):0.0;
$event->{StartTime} = $frame->{TimeStamp} unless ( $event->{StartTime} ); $event->{StartDateTime} = $frame->{TimeStamp} unless ( $event->{StartDateTime} );
$event->{TotScore} += $frame->{Score}; $event->{TotScore} += $frame->{Score};
$event->{MaxScore} = $frame->{Score} if ( $frame->{Score} > $event->{MaxScore} ); $event->{MaxScore} = $frame->{Score} if ( $frame->{Score} > $event->{MaxScore} );
$event->{AlarmFrames}++ if ( $frame->{Type} eq 'Alarm' ); $event->{AlarmFrames}++ if ( $frame->{Type} eq 'Alarm' );
$event->{EndTime} = $frame->{TimeStamp}; $event->{EndDateTime} = $frame->{TimeStamp};
$lastTimestamp = $frame->{TimeStamp}; $lastTimestamp = $frame->{TimeStamp};
} }
$event->{Width} = $event->{monitor}->{Width} unless( $event->{Width} ); $event->{Width} = $event->{monitor}->{Width} unless( $event->{Width} );
$event->{Height} = $event->{monitor}->{Height} unless( $event->{Height} ); $event->{Height} = $event->{monitor}->{Height} unless( $event->{Height} );
$event->{AvgScore} = $event->{TotScore}/int($event->{AlarmFrames}); $event->{AvgScore} = $event->{TotScore}/int($event->{AlarmFrames});
$event->{Length} = $event->{EndTime} - $event->{StartTime}; $event->{Length} = $event->{EndDateTime} - $event->{StartDateTime};
my %formats = ( my %formats = (
StartTime => 'from_unixtime(?)', StartDateTime => 'from_unixtime(?)',
EndTime => 'from_unixtime(?)', EndDateTime => 'from_unixtime(?)',
); );
my ( @fields, @formats, @values ); my ( @fields, @formats, @values );
@ -297,7 +297,7 @@ sub createEvent {
$event->{Id} = $dbh->{mysql_insertid}; $event->{Id} = $dbh->{mysql_insertid};
Info( "Created event ".$event->{Id} ); Info( "Created event ".$event->{Id} );
if ( $event->{EndTime} ) { if ( $event->{EndDateTime} ) {
$event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id} $event->{Name} = $event->{monitor}->{EventPrefix}.$event->{Id}
if ( $event->{Name} eq 'New Event' ); if ( $event->{Name} eq 'New Event' );
my $sql = "update Events set Name = ? where Id = ?"; my $sql = "update Events set Name = ? where Id = ?";
@ -383,8 +383,8 @@ sub updateEvent {
if ( $event->{Name} eq 'New Event' ); if ( $event->{Name} eq 'New Event' );
my %formats = ( my %formats = (
StartTime => 'from_unixtime(?)', StartDateTime => 'from_unixtime(?)',
EndTime => 'from_unixtime(?)', EndDateTime => 'from_unixtime(?)',
); );
my ( @values, @sets ); my ( @values, @sets );

View File

@ -205,7 +205,7 @@ MAIN: while( $loop ) {
my $monitorSelectSth = $dbh->prepare_cached( $monitorSelectSql ) my $monitorSelectSth = $dbh->prepare_cached( $monitorSelectSql )
or Fatal( "Can't prepare '$monitorSelectSql': ".$dbh->errstr() ); or Fatal( "Can't prepare '$monitorSelectSql': ".$dbh->errstr() );
my $eventSelectSql = 'SELECT `Id`, (unix_timestamp() - unix_timestamp(`StartTime`)) AS Age my $eventSelectSql = 'SELECT `Id`, (unix_timestamp() - unix_timestamp(`StartDateTime`)) AS Age
FROM `Events` WHERE `MonitorId` = ?'.(@Storage_Areas ? ' AND `StorageId` IN ('.join(',',map { '?'} @Storage_Areas).')' : '' ). ' ORDER BY `Id`'; FROM `Events` WHERE `MonitorId` = ?'.(@Storage_Areas ? ' AND `StorageId` IN ('.join(',',map { '?'} @Storage_Areas).')' : '' ). ' ORDER BY `Id`';
my $eventSelectSth = $dbh->prepare_cached( $eventSelectSql ) my $eventSelectSth = $dbh->prepare_cached( $eventSelectSql )
or Fatal( "Can't prepare '$eventSelectSql': ".$dbh->errstr() ); or Fatal( "Can't prepare '$eventSelectSql': ".$dbh->errstr() );
@ -397,13 +397,13 @@ MAIN: while( $loop ) {
my ( undef, $year, $month, $day ) = split('/', $day_dir); my ( undef, $year, $month, $day ) = split('/', $day_dir);
$year += 2000; $year += 2000;
my ( $hour, $minute, $second ) = split('/', $event_dir); my ( $hour, $minute, $second ) = split('/', $event_dir);
my $StartTime =sprintf('%.4d-%.2d-%.2d %.2d:%.2d:%.2d', $year, $month, $day, $hour, $minute, $second); my $StartDateTime =sprintf('%.4d-%.2d-%.2d %.2d:%.2d:%.2d', $year, $month, $day, $hour, $minute, $second);
my $Event = ZoneMinder::Event->find_one( my $Event = ZoneMinder::Event->find_one(
MonitorId=>$monitor_dir, MonitorId=>$monitor_dir,
StartTime=>$StartTime, StartDateTime=>$StartDateTime,
); );
if ( $Event ) { if ( $Event ) {
Debug("Found event matching starttime on monitor $monitor_dir at $StartTime: " . $Event->to_string()); Debug("Found event matching StartDateTime on monitor $monitor_dir at $StartDateTime: " . $Event->to_string());
next; next;
} }
aud_print("Deleting event directories with no event id information at $day_dir/$event_dir"); aud_print("Deleting event directories with no event id information at $day_dir/$event_dir");
@ -440,7 +440,7 @@ MAIN: while( $loop ) {
$Event->Path(); $Event->Path();
$Event->age(); $Event->age();
Debug("Have event $$Event{Id} at $$Event{Path}"); Debug("Have event $$Event{Id} at $$Event{Path}");
$Event->StartTime(POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($Event->Path())))); $Event->StartDateTime(POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($Event->Path()))));
} # end foreach event } # end foreach event
} }
@ -592,7 +592,7 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
Warning("Event $$Event{Id} is Archived. Taking no further action on it."); Warning("Event $$Event{Id} is Archived. Taking no further action on it.");
next; next;
} }
if ( !$Event->StartTime() ) { if ( !$Event->StartDateTime() ) {
aud_print("Event $$Event{Id} has no start time."); aud_print("Event $$Event{Id} has no start time.");
if ( confirm() ) { if ( confirm() ) {
$Event->delete(); $Event->delete();
@ -600,7 +600,7 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
} }
next; next;
} }
if ( ! $Event->EndTime() ) { if ( ! $Event->EndDateTime() ) {
if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) { if ( $age > $Config{ZM_AUDIT_MIN_AGE} ) {
aud_print("Event $$Event{Id} has no end time and is $age seconds old. Deleting it."); aud_print("Event $$Event{Id} has no end time and is $age seconds old. Deleting it.");
if ( confirm() ) { if ( confirm() ) {
@ -639,9 +639,9 @@ EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
Info("Updating storage area on event $$Event{Id} from $$Event{StorageId} to $$fs_events{$db_event}{StorageId}"); Info("Updating storage area on event $$Event{Id} from $$Event{StorageId} to $$fs_events{$db_event}{StorageId}");
$Event->StorageId($$fs_events{$db_event}->StorageId()); $Event->StorageId($$fs_events{$db_event}->StorageId());
} }
if ( ! $Event->StartTime() ) { if ( ! $Event->StartDateTime() ) {
Info("Updating StartTime on event $$Event{Id} from $$Event{StartTime} to $$fs_events{$db_event}{StartTime}"); Info("Updating StartDateTime on event $$Event{Id} from $$Event{StartDateTime} to $$fs_events{$db_event}{StartDateTime}");
$Event->StartTime($$fs_events{$db_event}->StartTime()); $Event->StartDateTime($$fs_events{$db_event}->StartDateTime());
} }
$Event->save(); $Event->save();
@ -683,12 +683,12 @@ if ( $level > 1 ) {
# Remove empty events (with no frames) # Remove empty events (with no frames)
$cleaned = 0; $cleaned = 0;
Debug("Checking for Events with no Frames"); Debug("Checking for Events with no Frames");
my $selectEmptyEventsSql = 'SELECT `E`.`Id` AS `Id`, `E`.`StartTime`, `F`.`EventId` FROM `Events` AS E LEFT JOIN `Frames` AS F ON (`E`.`Id` = `F`.`EventId`) my $selectEmptyEventsSql = 'SELECT `E`.`Id` AS `Id`, `E`.`StartDateTime`, `F`.`EventId` FROM `Events` AS E LEFT JOIN `Frames` AS F ON (`E`.`Id` = `F`.`EventId`)
WHERE isnull(`F`.`EventId`) AND now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second > `E`.`StartTime`'; WHERE isnull(`F`.`EventId`) AND now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second > `E`.`StartDateTime`';
if ( my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) ) { if ( my $selectEmptyEventsSth = $dbh->prepare_cached( $selectEmptyEventsSql ) ) {
if ( $res = $selectEmptyEventsSth->execute() ) { if ( $res = $selectEmptyEventsSth->execute() ) {
while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) { while( my $event = $selectEmptyEventsSth->fetchrow_hashref() ) {
aud_print("Found empty event with no frame records '$event->{Id}' at $$event{StartTime}"); aud_print("Found empty event with no frame records '$event->{Id}' at $$event{StartDateTime}");
if ( confirm() ) { if ( confirm() ) {
if ( $res = $deleteEventSth->execute($event->{Id}) ) { if ( $res = $deleteEventSth->execute($event->{Id}) ) {
$cleaned = 1; $cleaned = 1;
@ -750,7 +750,7 @@ if ( $level > 1 ) {
#"SELECT E.Id, ANY_VALUE(E.MonitorId), #"SELECT E.Id, ANY_VALUE(E.MonitorId),
# #
#max(F.TimeStamp) as EndTime, #max(F.TimeStamp) as EndTime,
#unix_timestamp(max(F.TimeStamp)) - unix_timestamp(E.StartTime) as Length, #unix_timestamp(max(F.TimeStamp)) - unix_timestamp(E.StartDateTime) as Length,
#max(F.FrameId) as Frames, #max(F.FrameId) as Frames,
#count(if(F.Score>0,1,NULL)) as AlarmFrames, #count(if(F.Score>0,1,NULL)) as AlarmFrames,
#sum(F.Score) as TotScore, #sum(F.Score) as TotScore,
@ -760,11 +760,11 @@ if ( $level > 1 ) {
#WHERE isnull(E.Frames) or isnull(E.EndTime) #WHERE isnull(E.Frames) or isnull(E.EndTime)
#GROUP BY E.Id HAVING EndTime < (now() - interval ".$Config{ZM_AUDIT_MIN_AGE}.' second)' #GROUP BY E.Id HAVING EndTime < (now() - interval ".$Config{ZM_AUDIT_MIN_AGE}.' second)'
#; #;
'SELECT *, unix_timestamp(`StartTime`) AS `TimeStamp` FROM `Events` WHERE `EndTime` IS NULL AND `StartTime` < (now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second)'.($monitor_id?' AND MonitorId=?':''); 'SELECT *, unix_timestamp(`StartDateTime`) AS `TimeStamp` FROM `Events` WHERE `EndDateTime` IS NULL AND `StartDateTime` < (now() - interval '.$Config{ZM_AUDIT_MIN_AGE}.' second)'.($monitor_id?' AND MonitorId=?':'');
my $selectFrameDataSql = ' my $selectFrameDataSql = '
SELECT SELECT
max(`TimeStamp`) AS `EndTime`, max(`TimeStamp`) AS `EndDateTime`,
unix_timestamp(max(`TimeStamp`)) AS `EndTimeStamp`, unix_timestamp(max(`TimeStamp`)) AS `EndTimeStamp`,
max(`FrameId`) AS `Frames`, max(`FrameId`) AS `Frames`,
count(if(`Score`>0,1,NULL)) AS `AlarmFrames`, count(if(`Score`>0,1,NULL)) AS `AlarmFrames`,
@ -779,7 +779,7 @@ FROM `Frames` WHERE `EventId`=?';
my $updateUnclosedEventsSql = my $updateUnclosedEventsSql =
"UPDATE low_priority `Events` "UPDATE low_priority `Events`
SET `Name` = ?, SET `Name` = ?,
`EndTime` = ?, `EndDateTime` = ?,
`Length` = ?, `Length` = ?,
`Frames` = ?, `Frames` = ?,
`AlarmFrames` = ?, `AlarmFrames` = ?,
@ -794,7 +794,7 @@ FROM `Frames` WHERE `EventId`=?';
$res = $selectUnclosedEventsSth->execute($monitor_id?$monitor_id:()) $res = $selectUnclosedEventsSth->execute($monitor_id?$monitor_id:())
or Fatal("Can't execute: ".$selectUnclosedEventsSth->errstr()); or Fatal("Can't execute: ".$selectUnclosedEventsSth->errstr());
while( my $event = $selectUnclosedEventsSth->fetchrow_hashref() ) { while( my $event = $selectUnclosedEventsSth->fetchrow_hashref() ) {
aud_print("Found open event '$event->{Id}' on Monitor $event->{MonitorId} at $$event{StartTime}"); aud_print("Found open event '$event->{Id}' on Monitor $event->{MonitorId} at $$event{StartDateTime}");
if ( confirm('close', 'closing') ) { if ( confirm('close', 'closing') ) {
if ( ! ( $res = $selectFrameDataSth->execute($event->{Id}) ) ) { if ( ! ( $res = $selectFrameDataSth->execute($event->{Id}) ) ) {
Error("Can't execute: $selectFrameDataSql:".$selectFrameDataSth->errstr()); Error("Can't execute: $selectFrameDataSql:".$selectFrameDataSth->errstr());
@ -808,7 +808,7 @@ FROM `Frames` WHERE `EventId`=?';
$event->{Id}, $event->{Id},
RECOVER_TAG RECOVER_TAG
), ),
$frame->{EndTime}, $frame->{EndDateTime},
$frame->{EndTimeStamp} - $event->{TimeStamp}, $frame->{EndTimeStamp} - $event->{TimeStamp},
$frame->{Frames}, $frame->{Frames},
$frame->{AlarmFrames}, $frame->{AlarmFrames},

View File

@ -704,7 +704,7 @@ sub substituteTags {
$text =~ s/%EN%/$Event->{Name}/g; $text =~ s/%EN%/$Event->{Name}/g;
$text =~ s/%EC%/$Event->{Cause}/g; $text =~ s/%EC%/$Event->{Cause}/g;
$text =~ s/%ED%/$Event->{Notes}/g; $text =~ s/%ED%/$Event->{Notes}/g;
$text =~ s/%ET%/$Event->{StartTime}/g; $text =~ s/%ET%/$Event->{StartDateTime}/g;
$text =~ s/%EVF%/$$Event{DefaultVideo}/g; # Event video filename $text =~ s/%EVF%/$$Event{DefaultVideo}/g; # Event video filename
$text =~ s/%EL%/$Event->{Length}/g; $text =~ s/%EL%/$Event->{Length}/g;
$text =~ s/%EF%/$Event->{Frames}/g; $text =~ s/%EF%/$Event->{Frames}/g;

View File

@ -231,7 +231,7 @@ Debug("@Monitors");
$Event->Height( $Monitor->Height() ); $Event->Height( $Monitor->Height() );
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->recover_timestamps(); $Event->recover_timestamps();
if ( $$Event{StartTime} ) { if ( $$Event{StartDateTime} ) {
$Event->save({}, 1); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() ); Info("Event resurrected as " . $Event->to_string() );
} else { } else {
@ -294,7 +294,7 @@ Debug("@Monitors");
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->DiskSpace( undef ); $Event->DiskSpace( undef );
$Event->recover_timestamps(); $Event->recover_timestamps();
if ( $$Event{StartTime} ) { if ( $$Event{StartDateTime} ) {
$Event->save({}, 1); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() ); Info("Event resurrected as " . $Event->to_string() );
} else { } else {
@ -309,13 +309,13 @@ Debug("@Monitors");
my ( undef, $year, $month, $day ) = split('/', $day_dir); my ( undef, $year, $month, $day ) = split('/', $day_dir);
$year += 2000; $year += 2000;
my ( $hour, $minute, $second ) = split('/', $event_dir); my ( $hour, $minute, $second ) = split('/', $event_dir);
my $StartTime =sprintf('%.4d-%.2d-%.2d %.2d:%.2d:%.2d', $year, $month, $day, $hour, $minute, $second); my $StartDateTime =sprintf('%.4d-%.2d-%.2d %.2d:%.2d:%.2d', $year, $month, $day, $hour, $minute, $second);
my $Event = ZoneMinder::Event->find_one( my $Event = ZoneMinder::Event->find_one(
MonitorId=>$monitor_dir, MonitorId=>$monitor_dir,
StartTime=>$StartTime, StartDateTime=>$StartDateTime,
); );
if ( $Event ) { if ( $Event ) {
Debug("Found event matching starttime on monitor $monitor_dir at $StartTime: " . $Event->to_string()); Debug("Found event matching starttime on monitor $monitor_dir at $StartDateTime: " . $Event->to_string());
next; next;
} }
@ -358,7 +358,7 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->recover_timestamps(); $Event->recover_timestamps();
if ( $$Event{StartTime} ) { if ( $$Event{StartDateTime} ) {
$Event->save({}, 1); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() ); Info("Event resurrected as " . $Event->to_string() );
} else { } else {
@ -400,7 +400,7 @@ Debug("@Monitors");
$Event->Orientation( $Monitor->Orientation() ); $Event->Orientation( $Monitor->Orientation() );
$Event->StorageId( $Storage->Id() ); $Event->StorageId( $Storage->Id() );
$Event->recover_timestamps(); $Event->recover_timestamps();
if ( $$Event{StartTime} ) { if ( $$Event{StartDateTime} ) {
$Event->save({}, 1); $Event->save({}, 1);
Info("Event resurrected as " . $Event->to_string() ); Info("Event resurrected as " . $Event->to_string() );
} else { } else {

View File

@ -43,10 +43,10 @@ while( 1 ) {
} }
} }
$dbh->do('DELETE FROM Events_Hour WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 hour)') or Error($dbh->errstr()); $dbh->do('DELETE FROM Events_Hour WHERE StartDateTime < DATE_SUB(NOW(), INTERVAL 1 hour)') or Error($dbh->errstr());
$dbh->do('DELETE FROM Events_Day WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 day)') or Error($dbh->errstr()); $dbh->do('DELETE FROM Events_Day WHERE StartDateTime < DATE_SUB(NOW(), INTERVAL 1 day)') or Error($dbh->errstr());
$dbh->do('DELETE FROM Events_Week WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 week)') or Error($dbh->errstr()); $dbh->do('DELETE FROM Events_Week WHERE StartDateTime < DATE_SUB(NOW(), INTERVAL 1 week)') or Error($dbh->errstr());
$dbh->do('DELETE FROM Events_Month WHERE StartTime < DATE_SUB(NOW(), INTERVAL 1 month)') or Error($dbh->errstr()); $dbh->do('DELETE FROM Events_Month WHERE StartDateTime < DATE_SUB(NOW(), INTERVAL 1 month)') or Error($dbh->errstr());
# Prune the Logs table if required # Prune the Logs table if required
if ( $Config{ZM_LOG_DATABASE_LIMIT} ) { if ( $Config{ZM_LOG_DATABASE_LIMIT} ) {

View File

@ -201,7 +201,7 @@ if ( $event_id ) {
my $sql = " SELECT (SELECT max(Delta) FROM Frames WHERE EventId=Events.Id)-(SELECT min(Delta) FROM Frames WHERE EventId=Events.Id) as FullLength, my $sql = " SELECT (SELECT max(Delta) FROM Frames WHERE EventId=Events.Id)-(SELECT min(Delta) FROM Frames WHERE EventId=Events.Id) as FullLength,
Events.*, Events.*,
unix_timestamp(Events.StartTime) as Time, unix_timestamp(Events.StartDateTime) as Time,
M.Name as MonitorName, M.Name as MonitorName,
M.Palette M.Palette
FROM Events FROM Events