From 4f5948cba07d484e6ed845175b9342306efd2768 Mon Sep 17 00:00:00 2001 From: Isaac Connor Date: Mon, 12 Oct 2020 10:53:53 -0400 Subject: [PATCH] Implement Unarchive action --- scripts/ZoneMinder/lib/ZoneMinder/Filter.pm | 4 ++++ scripts/zmfilter.pl.in | 14 +++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm index 125732234..7c45f7d0f 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Filter.pm @@ -58,6 +58,7 @@ Id Name Query_json AutoArchive +AutoUnarchive AutoVideo AutoUpload AutoEmail @@ -348,6 +349,9 @@ sub Sql { if ( $self->{AutoArchive} ) { push @auto_terms, 'E.Archived = 0'; } + if ( $self->{AutoUnarchive} ) { + push @auto_terms, 'E.Archived = 1'; + } # Don't do this, it prevents re-generation and concatenation. # If the file already exists, then the video won't be re-recreated if ( $self->{AutoVideo} ) { diff --git a/scripts/zmfilter.pl.in b/scripts/zmfilter.pl.in index 5ff316078..9a93c8953 100644 --- a/scripts/zmfilter.pl.in +++ b/scripts/zmfilter.pl.in @@ -98,6 +98,7 @@ use constant EVENT_PATH => ($Config{ZM_DIR_EVENTS}=~m|/|) ; logInit($filter_id?(id=>'zmfilter_'.$filter_id):()); + sub HupHandler { # This idea at this time is to just exit, freeing up the memory. # zmfilter.pl will be respawned by zmdc. @@ -236,6 +237,7 @@ sub getFilters { $sql .= ' `Background` = 1 AND'; } $sql .= '( `AutoArchive` = 1 + or `AutoUnarchive` = 1 or `AutoVideo` = 1 or `AutoUpload` = 1 or `AutoEmail` = 1 @@ -282,6 +284,7 @@ sub checkFilter { join(', ', ($filter->{AutoDelete}?'delete':()), ($filter->{AutoArchive}?'archive':()), + ($filter->{AutoUnarchive}?'unarchive':()), ($filter->{AutoVideo}?'video':()), ($filter->{AutoUpload}?'upload':()), ($filter->{AutoEmail}?'email':()), @@ -299,7 +302,7 @@ sub checkFilter { last if $zm_terminate; my $Event = new ZoneMinder::Event($$event{Id}, $event); - Debug("Checking event $Event->{Id}"); + Debug('Checking event '.$Event->{Id}); my $delete_ok = !undef; $dbh->ping(); if ( $filter->{AutoArchive} ) { @@ -311,6 +314,15 @@ sub checkFilter { my $res = $sth->execute($Event->{Id}) or Error("Unable to execute '$sql': ".$dbh->errstr()); } + if ( $filter->{AutoUnarchive} ) { + Info("Unarchiving event $Event->{Id}"); + # Do it individually to avoid locking up the table for new events + my $sql = 'UPDATE `Events` SET `Archived` = 0 WHERE `Id` = ?'; + my $sth = $dbh->prepare_cached($sql) + or Fatal("Unable to prepare '$sql': ".$dbh->errstr()); + my $res = $sth->execute($Event->{Id}) + or Error("Unable to execute '$sql': ".$dbh->errstr()); + } if ( $Config{ZM_OPT_FFMPEG} && $filter->{AutoVideo} ) { if ( !$Event->{Videoed} ) { $delete_ok = undef if !generateVideo($filter, $Event);