summaryrefslogtreecommitdiff
path: root/FS/FS/export_svc.pm
diff options
context:
space:
mode:
authorMark Wells <mark@freeside.biz>2013-04-16 21:12:17 -0700
committerMark Wells <mark@freeside.biz>2013-04-16 21:12:17 -0700
commit90d53f2bfaac6b65afb211e81c1f9aa160da9e1c (patch)
treec932a2145e6fff19d44a938d86a90f5872462a10 /FS/FS/export_svc.pm
parent458154df5fb1ebf983458007e266da130b706ef7 (diff)
for exports with per-service machine selection, make sure there is always a machine selected, #17194, #22524
Diffstat (limited to 'FS/FS/export_svc.pm')
-rw-r--r--FS/FS/export_svc.pm50
1 files changed, 49 insertions, 1 deletions
diff --git a/FS/FS/export_svc.pm b/FS/FS/export_svc.pm
index 0370f5f..b08f8f7 100644
--- a/FS/FS/export_svc.pm
+++ b/FS/FS/export_svc.pm
@@ -5,6 +5,7 @@ use vars qw( @ISA );
use FS::Record qw( qsearch qsearchs dbh );
use FS::part_export;
use FS::part_svc;
+use FS::svc_export_machine;
@ISA = qw(FS::Record);
@@ -209,6 +210,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 +265,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
@@ -307,6 +337,24 @@ sub part_svc {
qsearchs( 'part_svc', { 'svcpart' => $self->svcpart } );
}
+=item svc_export_machine
+
+Returns all export hostname records (L<FS::svc_export_machine>) for this
+combination of svcpart and exportnum.
+
+=cut
+
+sub svc_export_machine {
+ my $self = shift;
+ 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
=head1 BUGS