diff --git a/db/Object_Types.sql b/db/Object_Types.sql new file mode 100644 index 000000000..7b2334e85 --- /dev/null +++ b/db/Object_Types.sql @@ -0,0 +1,6 @@ +CREATE TABLE Object_Types ( + Id int(10) NOT NULL AUTO_INCREMENT, + Name varchar(32) UNIQUE, + Human TEXT, + PRIMARY KEY (Id) +); diff --git a/db/zm_create.sql.in b/db/zm_create.sql.in index bfdd6236a..ea8257b75 100644 --- a/db/zm_create.sql.in +++ b/db/zm_create.sql.in @@ -1256,6 +1256,7 @@ CREATE TABLE `Events_Tags` ( CONSTRAINT `Events_Tags_ibfk_2` FOREIGN KEY (`EventId`) REFERENCES `Events` (`Id`) ON DELETE CASCADE ) ENGINE=@ZM_MYSQL_ENGINE@; +source @PKGDATADIR@/db/Object_Types.sql -- We generally don't alter triggers, we drop and re-create them, so let's keep them in a separate file that we can just source in update scripts. source @PKGDATADIR@/db/triggers.sql diff --git a/distros/redhat/zoneminder.spec b/distros/redhat/zoneminder.spec index af8eae1b1..bf5e7988e 100644 --- a/distros/redhat/zoneminder.spec +++ b/distros/redhat/zoneminder.spec @@ -18,7 +18,7 @@ %global zmtargetdistro %{?rhel:el%{rhel}}%{!?rhel:fc%{fedora}} Name: zoneminder -Version: 1.37.56 +Version: 1.37.57 Release: 2%{?dist} Summary: A camera monitoring and analysis tool Group: System Environment/Daemons diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm index 7aaae4d53..da5b6a873 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/Object.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/Object.pm @@ -22,7 +22,6 @@ # This module contains the common definitions and functions used by the rest # of the ZoneMinder scripts # - package ZoneMinder::Object; use 5.006; @@ -32,6 +31,7 @@ use Time::HiRes qw{ gettimeofday tv_interval }; use Carp qw( cluck ); require ZoneMinder::Base; +require ZoneMinder::Object_Type; our @ISA = qw(ZoneMinder::Base); @@ -361,7 +361,7 @@ sub set { if ( $params ) { foreach my $field ( keys %{$params} ) { - $log->debug("field: $field, ".def_or_undef($$self{$field}).' =? param: '.def_or_undef($$params{$field})) if $debug; + $log->debug("field: $field, ".def_or_undef($$self{$field}).' =? param: '.def_or_undef($$params{$field})) if $debug or DEBUG_ALL; if ( ( ! defined $$self{$field} ) or ($$self{$field} ne $params->{$field}) ) { # Only make changes to fields that have changed if ( defined $fields{$field} ) { @@ -886,6 +886,62 @@ sub clone { return $new; } # end sub clone +sub Object_Type { + if ( $_[0]{object_type_id} ) { + $_[0]{Object_Type} = new ZoneMinder::Object_Type( $_[0]{object_type_id} ); + } else { + $_[0]{Object_Type} = ZoneMinder::Object_Type->find_one( name=>ref $_[0] ); + $_[0]{Object_Type} = new ZoneMinder::Object_Type() if ! $_[0]{Object_Type}; + } # end if + return $_[0]{Object_Type}; +} # end sub Object_Type + +sub object_type { + if ( @_ > 1 ) { + my $Type = ZoneMinder::Object_Type->find_one( name => $_[1] ); + if ( ! $Type ) { + $Type = new ZoneMinder::Object_Type(); + $Type->save({ Name=>$_[1], Human=>$_[1] }); + } # end if + $_[0]{object_type} = $Type->Name(); + $_[0]{object_type_id} = $Type->Id(); + } # end if + if ( ! $_[0]{object_type} ) { + $_[0]{object_type} = new ZoneMinder::Object_Type( $_[0]{object_type_id} )->Name(); + } # end if + return $_[0]{object_type}; +} # end sub object_type + +sub Object { + my $self = shift; + if ( @_ ) { + $self->object_type( ref $_[0] ); + $$self{object_id} = $_[0]{id}; + $$self{Object} = $_[0]; + } # end if + my $type = $self->object_type(); + if ( !$type ) { + Error('No type in Object::Object'. $self->to_string()) if ref $self ne 'ZoneMinder::Log'; + return undef; + } # end if + my ( $module ) = $type =~ /ZoneMinder::(.*)/; + if ( $module ) { + eval { + require "ZoneMinder/$module.pm"; + }; + if ( ! $$self{Object} ) { + $_ = $type->new($$self{object_id}); + Debug( 'Returning object of type ' . ref $_ ) if $debug; + $$self{Object} = $_; + } + return $$self{Object}; + } else { + Error("Unvalid object $type"); + return new ZoneMinder::Object(); + } +} # end sub Object + + sub AUTOLOAD { my $type = ref($_[0]); Carp::cluck("No type in autoload") if ! $type; diff --git a/scripts/ZoneMinder/lib/ZoneMinder/Object_Type.pm b/scripts/ZoneMinder/lib/ZoneMinder/Object_Type.pm new file mode 100644 index 000000000..33eda22dc --- /dev/null +++ b/scripts/ZoneMinder/lib/ZoneMinder/Object_Type.pm @@ -0,0 +1,49 @@ +use strict; +package ZoneMinder::Object_Type; +our @ISA = qw( ZoneMinder::Object ); + +use vars qw( $debug $table %fields %transforms %defaults $primary_key ); + +$debug = 0; +$table = 'Object_Types'; +$primary_key = 'id'; +%fields = ( + Id => 'Id', + Name => 'Name', + Human => 'Human', +); +%defaults = ( +); +%transforms = ( + Name => [ 's/^\s+//', 's/\s+$//', 's/\s\s+/ /g' ], + Human => [ 's/^\s+//', 's/\s+$//', 's/\s\s+/ /g', 's/^ZoneMinder:://' ], +); + +sub Object { + if ( $_[0]{Name} ) { + my $name = $_[0]{Name}; + $name =~ s/::/\//g; + eval { + require $name.'.pm'; + }; + $ZoneMinder::log->error("failed requiring $name $@") if $@; + return $_[0]{Name}->new($_[1]); + } + my ($caller, undef, $line) = caller; + $ZoneMinder::log->error("Unknown object from $caller:$line"); + return new ZoneMinder::Object(); +} # end sub Object + +sub Human { + if ( @_ > 1 ) { + $_[0]{Human} = $_[1]; + } + if ( ! $_[0]{Human} ) { + $_[0]{Human} = $_[0]{Name}; + $_[0]{Human} =~ s/^ZoneMinder:://; + } + return $_[0]{Human}; +} + +1; +__END__ diff --git a/version.txt b/version.txt index dd59fb63b..9459b808d 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -1.37.56 +1.37.57