Implement Unarchive action

pull/3065/head
Isaac Connor 2020-10-12 10:53:53 -04:00
parent 1b2ab6cce9
commit 4f5948cba0
2 changed files with 17 additions and 1 deletions

View File

@ -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} ) {

View File

@ -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);