X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fpart_export.pm;h=4b60953cf902e5300620032c55a79127e4ce855d;hb=3c54c844c665ed108c7892a154fd3972fab1f3e5;hp=588606dc12c68bbc58626fe5ee9f443cd4f5b6fe;hpb=cc647ae934abe5c9d9a5fc12f020adfc566349d9;p=freeside.git diff --git a/FS/FS/part_export.pm b/FS/FS/part_export.pm index 588606dc1..4b60953cf 100644 --- a/FS/FS/part_export.pm +++ b/FS/FS/part_export.pm @@ -4,8 +4,8 @@ use strict; use vars qw( @ISA @EXPORT_OK $DEBUG %exports ); use Exporter; use Tie::IxHash; +use base qw( FS::option_Common FS::m2m_Common ); # m2m for 'export_nas' use FS::Record qw( qsearch qsearchs dbh ); -use FS::option_Common; use FS::part_svc; use FS::part_export_option; use FS::export_svc; @@ -13,7 +13,6 @@ use FS::export_svc; #for export modules, though they should probably just use it themselves use FS::queue; -@ISA = qw( FS::option_Common ); @EXPORT_OK = qw(export_info); $DEBUG = 0; @@ -50,6 +49,8 @@ fields are currently supported: =item exportnum - primary key +=item exportname - Descriptive name + =item machine - Machine name =item exporttype - Export type @@ -127,7 +128,12 @@ sub delete { local $FS::UID::AutoCommit = 0; my $dbh = dbh; - my $error = $self->SUPER::delete; + # clean up export_nas records + my $error = $self->process_m2m( + 'link_table' => 'export_nas', + 'target_table' => 'nas', + 'params' => [], + ) || $self->SUPER::delete; if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -159,6 +165,7 @@ sub check { my $self = shift; my $error = $self->ut_numbern('exportnum') + || $self->ut_textn('exportname') || $self->ut_domain('machine') || $self->ut_alpha('exporttype') ; @@ -174,6 +181,17 @@ sub check { $self->SUPER::check; } +=item label + +Returns a label for this export, "exportname||exportype (machine)". + +=cut + +sub label { + my $self = shift; + ($self->exportname || $self->exporttype ). ' ('. $self->machine. ')'; +} + #=item part_svc # #Returns the service definition (see L) for this export. @@ -387,6 +405,18 @@ or hidden by default). =cut +=item weight + +Returns the 'weight' element from the export's %info hash, or 0 if there is +no weight defined. + +=cut + +sub weight { + my $self = shift; + export_info()->{$self->exporttype}->{'weight'} || 0; +} + =back =head1 SUBROUTINES @@ -417,6 +447,34 @@ sub export_info { my $r = { map { %{$exports{$_}} } keys %exports }; } + +sub _upgrade_data { #class method + my ($class, %opts) = @_; + + my @part_export_option = qsearch('part_export_option', { 'optionname' => 'overlimit_groups' }); + foreach my $opt ( @part_export_option ) { + next if $opt->optionvalue =~ /^[\d\s]+$/ || !$opt->optionvalue; + my @groupnames = split(' ',$opt->optionvalue); + my @groupnums; + my $error = ''; + foreach my $groupname ( @groupnames ) { + my $g = qsearchs('radius_group', { 'groupname' => $groupname } ); + unless ( $g ) { + $g = new FS::radius_group { + 'groupname' => $groupname, + 'description' => $groupname, + }; + $error = $g->insert; + die $error if $error; + } + push @groupnums, $g->groupnum; + } + $opt->optionvalue(join(' ',@groupnums)); + $error = $opt->replace; + die $error if $error; + } +} + #=item exporttype2svcdb EXPORTTYPE # #Returns the applicable I for an I. @@ -448,7 +506,7 @@ foreach my $INC ( @INC ) { } unless ( keys %$info ) { warn "no %info hash found in FS::part_export::$mod, skipping\n" - unless $mod =~ /^(passwdfile|null)$/; #hack but what the heck + unless $mod =~ /^(passwdfile|null|.+_Common)$/; #hack but what the heck next; } warn "got export info from FS::part_export::$mod: $info\n" if $DEBUG;