diff options
Diffstat (limited to 'FS/FS/m2name_Common.pm')
-rw-r--r-- | FS/FS/m2name_Common.pm | 95 |
1 files changed, 0 insertions, 95 deletions
diff --git a/FS/FS/m2name_Common.pm b/FS/FS/m2name_Common.pm deleted file mode 100644 index 7c9637e..0000000 --- a/FS/FS/m2name_Common.pm +++ /dev/null @@ -1,95 +0,0 @@ -package FS::m2name_Common; - -use strict; -use vars qw( @ISA $DEBUG ); -use FS::Schema qw( dbdef ); -use FS::Record qw( qsearch qsearchs ); #dbh ); - -@ISA = qw( FS::Record ); - -$DEBUG = 0; - -=head1 NAME - -FS::m2name_Common - Base class for tables with a related table listing names - -=head1 SYNOPSIS - -use FS::m2name_Common; - -@ISA = qw( FS::m2name_Common ); - -=head1 DESCRIPTION - -FS::m2name_Common is intended as a base class for classes which have a -related table that lists names. - -=head1 METHODS - -=over 4 - -=item process_m2name - -=cut - -sub process_m2name { - my( $self, %opt ) = @_; - - my $self_pkey = $self->dbdef_table->primary_key; - my $link_sourcekey = $opt{'num_col'} || $self_pkey; - - my $link_table = $self->_load_table($opt{'link_table'}); - - my $link_static = $opt{'link_static'} || {}; - - foreach my $name ( @{ $opt{'names_list'} } ) { - - my $obj = qsearchs( $link_table, { - $link_sourcekey => $self->$self_pkey(), - $opt{'name_col'} => $name, - %$link_static, - }); - - if ( $obj && ! $opt{'params'}->{"$link_table.$name"} ) { - - my $d_obj = $obj; #need to save $obj for below. - my $error = $d_obj->delete; - die "error deleting $d_obj for $link_table.$name: $error" if $error; - - } elsif ( $opt{'params'}->{"$link_table.$name"} && ! $obj ) { - - #ok to clobber it now (but bad form nonetheless?) - #$obj = new "FS::$link_table" ( { - $obj = "FS::$link_table"->new( { - $link_sourcekey => $self->$self_pkey(), - $opt{'name_col'} => $name, - %$link_static, - }); - my $error = $obj->insert; - die "error inserting $obj for $link_table.$name: $error" if $error; - } - - } - - ''; -} - -sub _load_table { - my( $self, $table ) = @_; - eval "use FS::$table"; - die $@ if $@; - $table; -} - -=back - -=head1 BUGS - -=head1 SEE ALSO - -L<FS::Record> - -=cut - -1; - |