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
if ( $filter->{AutoMove} ) {
my $NewStorage = new ZoneMinder::Storage($filter->{AutoMoveTo});
Info("Moving event $Event->{Id} to datastore $filter->{AutoMoveTo}");
$_ = $Event->MoveTo($NewStorage);
Error($_) if $_;
if ($filter->{AutoMove}) {
my $NewStorage = ZoneMinder::Storage->find_one(Id=>$filter->{AutoMoveTo});
if ($NewStorage) {
Info("Moving event $Event->{Id} to datastore $filter->{AutoMoveTo}");
$_ = $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
# So we still need to update the Event object with the new SecondaryStorageId
my $NewStorage = ZoneMinder::Storage->find_one(Id=>$filter->{AutoCopyTo});
if ( $NewStorage ) {
Info("Copying event $Event->{Id} to datastore $filter->{AutoCopyTo}");
$_ = $Event->CopyTo($NewStorage);
if ( $_ ) {
$ZoneMinder::Database::dbh->commit();
if ($_) {
Error($_);
} else {
$Event->save({SecondaryStorageId=>$$NewStorage{Id}});
$ZoneMinder::Database::dbh->commit();
}
} else {
Error("No storage area found for copy to operation. AutoCopyTo was $$filter{AutoCopyTo}");