X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2Fexport_svc.pm;h=5ef50b648d40d70129652127f2398205065f2aeb;hb=13f21e01ac9faa50c07f64c20cbceae0ae50790c;hp=0370f5f0b6298675f7d5b44aec9ec740d0cd92f0;hpb=5e05724a635a22776f1b973f5d7e77989da4e048;p=freeside.git diff --git a/FS/FS/export_svc.pm b/FS/FS/export_svc.pm index 0370f5f0b..5ef50b648 100644 --- a/FS/FS/export_svc.pm +++ b/FS/FS/export_svc.pm @@ -1,12 +1,9 @@ package FS::export_svc; +use base qw(FS::Record); use strict; -use vars qw( @ISA ); -use FS::Record qw( qsearch qsearchs dbh ); -use FS::part_export; -use FS::part_svc; - -@ISA = qw(FS::Record); +use FS::Record qw( dbh qsearch ); #qsearchs ); +use FS::svc_export_machine; =head1 NAME @@ -209,6 +206,19 @@ sub insert { } #end of duplicate check, whew $error = $self->SUPER::insert; + + my $part_export = $self->part_export; + if ( !$error and $part_export->default_machine ) { + foreach my $cust_svc ( $self->part_svc->cust_svc ) { + my $svc_export_machine = FS::svc_export_machine->new({ + 'exportnum' => $self->exportnum, + 'svcnum' => $cust_svc->svcnum, + 'machinenum' => $part_export->default_machine, + }); + $error ||= $svc_export_machine->insert; + } + } + if ( $error ) { $dbh->rollback if $oldAutoCommit; return $error; @@ -251,7 +261,23 @@ Delete this record from the database. =cut -# the delete method can be inherited from FS::Record +sub delete { + my $self = shift; + my $dbh = dbh; + my $oldAutoCommit = $FS::UID::AutoCommit; + local $FS::UID::AutoCommit = 0; + + my $error = $self->SUPER::delete; + foreach ($self->svc_export_machine) { + $error ||= $_->delete; + } + if ( $error ) { + $dbh->rollback if $oldAutoCommit; + return $error; + } + $dbh->commit or die $dbh->errstr if $oldAutoCommit; +} + =item replace OLD_RECORD @@ -289,22 +315,26 @@ sub check { Returns the FS::part_export object (see L). -=cut - -sub part_export { - my $self = shift; - qsearchs( 'part_export', { 'exportnum' => $self->exportnum } ); -} - =item part_svc Returns the FS::part_svc object (see L). +=item svc_export_machine + +Returns all export hostname records (L) for this +combination of svcpart and exportnum. + =cut -sub part_svc { +sub svc_export_machine { my $self = shift; - qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } ); + qsearch({ + 'table' => 'svc_export_machine', + 'select' => 'svc_export_machine.*', + 'addl_from' => 'JOIN cust_svc USING (svcnum)', + 'hashref' => { 'exportnum' => $self->exportnum }, + 'extra_sql' => ' AND cust_svc.svcpart = '.$self->svcpart, + }); } =back