[freeside-commits] freeside/FS/FS/part_export prizm.pm, 1.3.2.6, 1.3.2.7
Jeff Finucane,420,,
jeff at wavetail.420.am
Thu Jan 24 18:55:24 PST 2008
Update of /home/cvs/cvsroot/freeside/FS/FS/part_export
In directory wavetail:/tmp/cvs-serv28905
Modified Files:
Tag: FREESIDE_1_7_BRANCH
prizm.pm
Log Message:
add an always BAM option and be explicit about transactions
Index: prizm.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/part_export/prizm.pm,v
retrieving revision 1.3.2.6
retrieving revision 1.3.2.7
diff -u -d -r1.3.2.6 -r1.3.2.7
--- prizm.pm 26 Dec 2007 22:52:23 -0000 1.3.2.6
+++ prizm.pm 25 Jan 2008 02:55:21 -0000 1.3.2.7
@@ -2,7 +2,7 @@
use vars qw(@ISA %info %options $DEBUG);
use Tie::IxHash;
-use FS::Record qw(fields);
+use FS::Record qw(fields dbh);
use FS::part_export;
@ISA = qw(FS::part_export);
@@ -13,6 +13,7 @@
'user' => { label => 'Northbound username', default=>'nbi' },
'password' => { label => 'Password', default => '' },
'ems' => { label => 'Full EMS', type => 'checkbox' },
+ 'always_bam' => { label => 'Always activate/suspend authentication', type => 'checkbox' },
'element_name_length' => { label => 'Size of siteName (best left blank)' },
;
@@ -289,6 +290,10 @@
sub _export_delete {
my( $self, $svc ) = ( shift, shift );
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
my $cust_pkg = $svc->cust_svc->cust_pkg;
my $depend = [];
@@ -298,7 +303,7 @@
'svcnum' => $svc->svcnum,
'job' => 'FS::part_export::prizm::queued_prizm_command',
};
- $queue->insert(
+ my $error = $queue->insert(
( map { $self->option($_) }
qw( url user password ) ),
'CustomerIfService',
@@ -307,10 +312,27 @@
$cust_pkg->custnum,
0,
$svc->mac_addr,
- ) && push @$depend, $queue->jobnum;
+ );
+
+ if ($error) {
+ $dbh->rollback if $oldAutoCommit;
+ return $error;
+ }
+
+ push @$depend, $queue->jobnum;
}
- $self->queue_statuschange('deleteElement', $depend, $svc, 1);
+ my $err_or_queue =
+ $self->queue_statuschange('deleteElement', $depend, $svc, 1);
+
+ unless (ref($err_or_queue)) {
+ $dbh->rollback if $oldAutoCommit;
+ return $err_or_queue;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
}
sub _export_replace {
@@ -379,14 +401,66 @@
sub _export_suspend {
my( $self, $svc ) = ( shift, shift );
+ my $depend = [];
my $ems = $self->option('ems') ? 1 : 0;
- $self->queue_statuschange('suspendNetworkElements', [], $svc, 1, $ems);
+ my $err_or_queue = '';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ $err_or_queue =
+ $self->queue_statuschange('suspendNetworkElements', [], $svc, 1, $ems);
+ unless (ref($err_or_queue)) {
+ $dbh->rollback if $oldAutoCommit;
+ return $err_or_queue;
+ }
+ push @$depend, $err_or_queue->jobnum;
+
+ if ($ems && $self->option('always_bam')) {
+ $err_or_queue =
+ $self->queue_statuschange('suspendNetworkElements', $depend, $svc, 1, 0);
+ unless (ref($err_or_queue)) {
+ $dbh->rollback if $oldAutoCommit;
+ return $err_or_queue;
+ }
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
}
sub _export_unsuspend {
my( $self, $svc ) = ( shift, shift );
+ my $depend = [];
my $ems = $self->option('ems') ? 1 : 0;
- $self->queue_statuschange('activateNetworkElements', [], $svc, 1, $ems);
+ my $err_or_queue = '';
+
+ my $oldAutoCommit = $FS::UID::AutoCommit;
+ local $FS::UID::AutoCommit = 0;
+ my $dbh = dbh;
+
+ if ($ems && $self->option('always_bam')) {
+ $err_or_queue =
+ $self->queue_statuschange('activateNetworkElements', [], $svc, 1, 0);
+ unless (ref($err_or_queue)) {
+ $dbh->rollback if $oldAutoCommit;
+ return $err_or_queue;
+ }
+ push @$depend, $err_or_queue->jobnum;
+ }
+
+ $err_or_queue =
+ $self->queue_statuschange('activateNetworkElements', $depend, $svc, 1, $ems);
+ unless (ref($err_or_queue)) {
+ $dbh->rollback if $oldAutoCommit;
+ return $err_or_queue;
+ }
+
+ $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+
+ '';
}
sub queue_statuschange {
@@ -398,7 +472,7 @@
'svcnum' => $svc->svcnum,
'job' => 'FS::part_export::prizm::statuschange',
};
- $queue->insert(
+ my $error = $queue->insert(
( map { $self->option($_) }
qw( url user password ) ),
$method,
@@ -406,12 +480,13 @@
@args,
);
- if ($queue->jobnum) { # successful insertion
+ unless ($error) { # successful insertion
foreach my $job ( @$jobs ) {
- $queue->depend_insert($job);
+ $error ||= $queue->depend_insert($job);
}
}
+ $error or $queue;
}
sub statuschange { # subroutine
More information about the freeside-commits
mailing list