Do no commit on error as it releases locks. Add better storage loading error handling

This commit is contained in:
Isaac Connor 2021-10-25 09:44:20 -04:00
parent a258567c16
commit 522f8dd5ba
1 changed files with 11 additions and 9 deletions

View File

@ -358,25 +358,27 @@ sub checkFilter {
} }
} # end if AutoDelete } # end if AutoDelete
if ( $filter->{AutoMove} ) { if ($filter->{AutoMove}) {
my $NewStorage = new ZoneMinder::Storage($filter->{AutoMoveTo}); my $NewStorage = ZoneMinder::Storage->find_one(Id=>$filter->{AutoMoveTo});
Info("Moving event $Event->{Id} to datastore $filter->{AutoMoveTo}"); if ($NewStorage) {
$_ = $Event->MoveTo($NewStorage); Info("Moving event $Event->{Id} to datastore $filter->{AutoMoveTo}");
Error($_) if $_; $_ = $Event->MoveTo($NewStorage);
Error($_) if $_;
} else {
Error("No storage area found for move to operation. AutoMoveTo was $$filter{AutoMoveTo}");
}
} }
if ( $filter->{AutoCopy} ) { if ($filter->{AutoCopy}) {
# Copy To is different from MoveTo in that it JUST copies the files # Copy To is different from MoveTo in that it JUST copies the files
# So we still need to update the Event object with the new SecondaryStorageId # So we still need to update the Event object with the new SecondaryStorageId
my $NewStorage = ZoneMinder::Storage->find_one(Id=>$filter->{AutoCopyTo}); my $NewStorage = ZoneMinder::Storage->find_one(Id=>$filter->{AutoCopyTo});
if ( $NewStorage ) { if ( $NewStorage ) {
Info("Copying event $Event->{Id} to datastore $filter->{AutoCopyTo}"); Info("Copying event $Event->{Id} to datastore $filter->{AutoCopyTo}");
$_ = $Event->CopyTo($NewStorage); $_ = $Event->CopyTo($NewStorage);
if ( $_ ) { if ($_) {
$ZoneMinder::Database::dbh->commit();
Error($_); Error($_);
} else { } else {
$Event->save({SecondaryStorageId=>$$NewStorage{Id}}); $Event->save({SecondaryStorageId=>$$NewStorage{Id}});
$ZoneMinder::Database::dbh->commit();
} }
} else { } else {
Error("No storage area found for copy to operation. AutoCopyTo was $$filter{AutoCopyTo}"); Error("No storage area found for copy to operation. AutoCopyTo was $$filter{AutoCopyTo}");