[freeside-commits] branch master updated. 20c649e7838f9448e53e0ba1c8e49820f031fc3e

Ivan ivan at 420.am
Wed Jun 12 02:55:18 PDT 2013


The branch, master has been updated
       via  20c649e7838f9448e53e0ba1c8e49820f031fc3e (commit)
      from  160885729789305b2138d3474c07c953c43234f7 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 20c649e7838f9448e53e0ba1c8e49820f031fc3e
Author: Ivan Kohler <ivan at freeside.biz>
Date:   Wed Jun 12 02:55:14 2013 -0700

    export pkg_change hook, RT#22596

diff --git a/FS/FS/cust_pkg.pm b/FS/FS/cust_pkg.pm
index 0980577..1c9d8e1 100644
--- a/FS/FS/cust_pkg.pm
+++ b/FS/FS/cust_pkg.pm
@@ -581,9 +581,12 @@ sub replace {
 
   }
 
-  my $error = $new->SUPER::replace($old,
-                                   $options->{options} ? $options->{options} : ()
-                                  );
+  my $error =  $new->export_pkg_change($old)
+            || $new->SUPER::replace( $old,
+                                     $options->{options}
+                                       ? $options->{options}
+                                       : ()
+                                   );
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
@@ -3308,6 +3311,39 @@ sub reexport {
 
 }
 
+=item export_pkg_change OLD_CUST_PKG
+
+Calls the "pkg_change" export action for all services attached to this package.
+
+=cut
+
+sub export_pkg_change {
+  my( $self, $old )  = ( shift, shift );
+
+  local $SIG{HUP} = 'IGNORE';
+  local $SIG{INT} = 'IGNORE';
+  local $SIG{QUIT} = 'IGNORE';
+  local $SIG{TERM} = 'IGNORE';
+  local $SIG{TSTP} = 'IGNORE';
+  local $SIG{PIPE} = 'IGNORE';
+
+  my $oldAutoCommit = $FS::UID::AutoCommit;
+  local $FS::UID::AutoCommit = 0;
+  my $dbh = dbh;
+
+  foreach my $svc_x ( map $_->svc_x, $self->cust_svc ) {
+    my $error = $svc_x->export('pkg_change', $self, $old);
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error;
+    }
+  }
+
+  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
+  '';
+
+}
+
 =item insert_reason
 
 Associates this package with a (suspension or cancellation) reason (see
diff --git a/FS/FS/cust_svc.pm b/FS/FS/cust_svc.pm
index 94f04e9..6aa254f 100644
--- a/FS/FS/cust_svc.pm
+++ b/FS/FS/cust_svc.pm
@@ -295,6 +295,17 @@ sub replace {
 #    }
 #  }
 
+  #trigger a pkg_change export on pkgnum changes
+  if ( $new->pkgnum != $old->pkgnum ) {
+    my $error = $new->svc_x->export('pkg_change', $new->cust_pkg,
+                                                  $old->cust_pkg,
+                                   );
+    if ( $error ) {
+      $dbh->rollback if $oldAutoCommit;
+      return $error if $error;
+    }
+  }
+
   #my $error = $new->SUPER::replace($old, @_);
   my $error = $new->SUPER::replace($old);
   if ( $error ) {

-----------------------------------------------------------------------

Summary of changes:
 FS/FS/cust_pkg.pm |   42 +++++++++++++++++++++++++++++++++++++++---
 FS/FS/cust_svc.pm |   11 +++++++++++
 2 files changed, 50 insertions(+), 3 deletions(-)




More information about the freeside-commits mailing list