Merge branch 'zmaudit_check_other_storageareas' into storageareas

This commit is contained in:
Isaac Connor 2018-11-26 15:09:14 -05:00
commit 3f4e918b9e
2 changed files with 23 additions and 6 deletions

View File

@ -450,9 +450,23 @@ sub delete_files {
}
} # end sub delete_files
sub StorageId {
my $event = shift;
if ( @_ ) {
$$event{StorageId} = shift;
delete $$event{Storage};
delete $$event{Path};
}
return $$event{StorageId};
}
sub Storage {
if ( @_ > 1 ) {
$_[0]{Storage} = $_[1];
if ( $_[0]{Storage} ) {
$_[0]{StorageId} = $_[0]{Storage}->Id();
delete $_[0]{Path};
}
}
if ( ! $_[0]{Storage} ) {
$_[0]{Storage} = new ZoneMinder::Storage($_[0]{StorageId});

View File

@ -176,8 +176,10 @@ MAIN: while( $loop ) {
} # end while can't connect to the db
my @Storage_Areas;
my @all_Storage_Areas = ZoneMinder::Storage->find();
if ( defined $storage_id ) {
@Storage_Areas = ZoneMinder::Storage->find( Id=>$storage_id );
@Storage_Areas = map { $$_{Id} == $storage_id ? $_ : () } @all_Storage_Areas;
if ( !@Storage_Areas ) {
Error("No Storage Area found with Id $storage_id");
Term();
@ -403,7 +405,7 @@ MAIN: while( $loop ) {
$$Event{RelativePath} = $event_dir;
$Event->MonitorId( $monitor_dir );
$Event->StorageId( $Storage->Id() );
$Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($$Event{Path})) ) );
$Event->StartTime( POSIX::strftime('%Y-%m-%d %H:%M:%S', gmtime(time_of_youngest_file($Event->Path())) ) );
} # end foreach event
}
@ -523,7 +525,7 @@ MAIN: while( $loop ) {
# If we found the monitor in the file system
my $fs_events = $fs_monitors->{$db_monitor};
while ( my ( $db_event, $age ) = each( %$db_events ) ) {
EVENT: while ( my ( $db_event, $age ) = each( %$db_events ) ) {
if ( ! ($fs_events and defined( $fs_events->{$db_event} ) ) ) {
Debug("Don't have an fs event for $db_event");
my $Event = ZoneMinder::Event->find_one( Id=>$db_event );
@ -533,14 +535,15 @@ MAIN: while( $loop ) {
}
Debug("Event $db_event is not in fs. Should have been at ".$Event->Path());
# Check for existence in other Storage Areas
foreach my $Storage ( ZoneMinder::Storage->find( ( $$Event{StorageId} ? ( 'Id !='=>$$Event{StorageId} ) : () ) ) ) {
foreach my $Storage ( @all_Storage_Areas ) {
next if $$Storage{Id} == $$Event{StorageId};
my $path = $Storage->Path().'/'.$Event->RelativePath();
if ( -e $path ) {
Info("Event $$Event{Id} found at $path instead of $$Event{Path}");
if ( confirm('update', 'updating') ) {
$Event->save({StorageId=>$$Storage{Id}});
$Event->Path(undef);# Refresh Path
last;
next EVENT;
}
} else {
Debug("$$Event{Id} Not found at $path");