[freeside-commits] freeside/FS/FS svc_acct.pm, 1.268, 1.269 svc_Common.pm, 1.51, 1.52 svc_domain.pm, 1.56, 1.57 svc_forward.pm, 1.21, 1.22 svc_www.pm, 1.16, 1.17

Ivan,,, ivan at wavetail.420.am
Wed Oct 28 12:04:55 PDT 2009


Update of /home/cvs/cvsroot/freeside/FS/FS
In directory wavetail.420.am:/tmp/cvs-serv6790

Modified Files:
	svc_acct.pm svc_Common.pm svc_domain.pm svc_forward.pm 
	svc_www.pm 
Log Message:
fix problems using inventory for UID (and other fields controlled by check in svc_acct and also svc_www, svc_domain and svc_forward), RT#6366

Index: svc_Common.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_Common.pm,v
retrieving revision 1.51
retrieving revision 1.52
diff -u -d -r1.51 -r1.52
--- svc_Common.pm	4 Aug 2009 22:04:51 -0000	1.51
+++ svc_Common.pm	28 Oct 2009 19:04:53 -0000	1.52
@@ -255,9 +255,11 @@
     $self->svcpart($cust_svc->svcpart);
   }
 
-  my $error =    $self->set_auto_inventory
+  my $error =    $self->preinsert_hook_first
+              || $self->set_auto_inventory
               || $self->check
               || $self->_check_duplicate
+              || $self->preinsert_hook
               || $self->SUPER::insert;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -324,7 +326,9 @@
 }
 
 #fallbacks
+sub preinsert_hook_first { ''; }
 sub _check_duplcate { ''; }
+sub preinsert_hook { ''; }
 sub table_dupcheck_fields { (); }
 
 =item delete [ , OPTION => VALUE ... ]

Index: svc_forward.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_forward.pm,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -d -r1.21 -r1.22
--- svc_forward.pm	1 Aug 2007 22:24:37 -0000	1.21
+++ svc_forward.pm	28 Oct 2009 19:04:53 -0000	1.22
@@ -158,9 +158,6 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  $error = $self->check;
-  return $error if $error;
-
   $error = $self->SUPER::insert(@_);
   if ($error) {
     $dbh->rollback if $oldAutoCommit;

Index: svc_acct.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_acct.pm,v
retrieving revision 1.268
retrieving revision 1.269
diff -u -d -r1.268 -r1.269
--- svc_acct.pm	5 Oct 2009 23:36:08 -0000	1.268
+++ svc_acct.pm	28 Oct 2009 19:04:53 -0000	1.269
@@ -528,42 +528,8 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  my $error = $self->check;
-  return $error if $error;
-
-  if ( $self->svcnum && qsearchs('cust_svc',{'svcnum'=>$self->svcnum}) ) {
-    my $cust_svc = qsearchs('cust_svc',{'svcnum'=>$self->svcnum});
-    unless ( $cust_svc ) {
-      $dbh->rollback if $oldAutoCommit;
-      return "no cust_svc record found for svcnum ". $self->svcnum;
-    }
-    $self->pkgnum($cust_svc->pkgnum);
-    $self->svcpart($cust_svc->svcpart);
-  }
-
-  # set usage fields and thresholds if unset but set in a package def
-  if ( $self->pkgnum ) {
-    my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
-    my $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
-    if ( $part_pkg && $part_pkg->can('usage_valuehash') ) {
-
-      my %values = $part_pkg->usage_valuehash;
-      my $multiplier = $conf->exists('svc_acct-usage_threshold') 
-                         ? 1 - $conf->config('svc_acct-usage_threshold')/100
-                         : 0.20; #doesn't matter
-
-      foreach ( keys %values ) {
-        next if $self->getfield($_);
-        $self->setfield( $_, $values{$_} );
-        $self->setfield( $_. '_threshold', int( $values{$_} * $multiplier ) )
-          if $conf->exists('svc_acct-usage_threshold');
-      }
-
-    }
-  }
-
   my @jobnums;
-  $error = $self->SUPER::insert(
+  my $error = $self->SUPER::insert(
     'jobnums'       => \@jobnums,
     'child_objects' => $self->child_objects,
     %options,
@@ -692,6 +658,31 @@
   ''; #no error
 }
 
+# set usage fields and thresholds if unset but set in a package def
+sub preinsert_hook_first {
+  my $self = shift;
+
+  return '' unless $self->pkgnum;
+
+  my $cust_pkg = qsearchs( 'cust_pkg', { 'pkgnum' => $self->pkgnum } );
+  my $part_pkg = $cust_pkg->part_pkg if $cust_pkg;
+  return '' unless $part_pkg && $part_pkg->can('usage_valuehash');
+
+  my %values = $part_pkg->usage_valuehash;
+  my $multiplier = $conf->exists('svc_acct-usage_threshold') 
+                     ? 1 - $conf->config('svc_acct-usage_threshold')/100
+                     : 0.20; #doesn't matter
+
+  foreach ( keys %values ) {
+    next if $self->getfield($_);
+    $self->setfield( $_, $values{$_} );
+    $self->setfield( $_. '_threshold', int( $values{$_} * $multiplier ) )
+      if $conf->exists('svc_acct-usage_threshold');
+  }
+
+  ''; #no error
+}
+
 =item delete
 
 Deletes this account from the database.  If there is an error, returns the

Index: svc_domain.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_domain.pm,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -d -r1.56 -r1.57
--- svc_domain.pm	14 Jul 2009 19:05:05 -0000	1.56
+++ svc_domain.pm	28 Oct 2009 19:04:53 -0000	1.57
@@ -181,13 +181,6 @@
   local $FS::UID::AutoCommit = 0;
   my $dbh = dbh;
 
-  $error = $self->check;
-  return $error if $error;
-
-  return "Domain in use (here)"
-    if qsearchs( 'svc_domain', { 'domain' => $self->domain } );
-
-
   $error = $self->SUPER::insert(@_);
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -392,6 +385,18 @@
 
 }
 
+sub _check_duplicate {
+  my $self = shift;
+
+  $self->lock_table;
+
+  if ( qsearchs( 'svc_domain', { 'domain' => $self->domain } ) ) {
+    return "Domain in use (here)";
+  } else {
+    return '';
+  }
+}
+
 =item domain_record
 
 =cut

Index: svc_www.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_www.pm,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -d -r1.16 -r1.17
--- svc_www.pm	1 Aug 2007 22:24:37 -0000	1.16
+++ svc_www.pm	28 Oct 2009 19:04:53 -0000	1.17
@@ -113,57 +113,31 @@
 jobnums), all provisioning jobs will have a dependancy on the supplied
 jobnum(s) (they will not run until the specific job(s) complete(s)).
 
-
 =cut
 
-sub insert {
+sub preinsert_hook {
   my $self = shift;
 
-  my $error = $self->check;
-  return $error if $error;
-
-  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;
-
-  #if ( $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/ ) {
-  if ( $self->recnum =~ /^([\w\-]+|\@)\.(\d+)$/ ) {
-    my( $reczone, $domain_svcnum ) = ( $1, $2 );
-    unless ( $apacheip ) {
-      $dbh->rollback if $oldAutoCommit;
-      return "Configuration option apacheip not set; can't autocreate A record";
-             #"for $reczone". $svc_domain->domain;
-    }
-    my $domain_record = new FS::domain_record {
-      'svcnum'  => $domain_svcnum,
-      'reczone' => $reczone,
-      'recaf'   => 'IN',
-      'rectype' => 'A',
-      'recdata' => $apacheip,
-    };
-    $error = $domain_record->insert;
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return $error;
-    }
-    $self->recnum($domain_record->recnum);
-  }
+  #return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(([\w\.\-]+\.)+\w+)$/;
+  return '' unless $self->recnum =~ /^([\w\-]+|\@)\.(\d+)$/;
 
-  $error = $self->SUPER::insert(@_);
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
+  my( $reczone, $domain_svcnum ) = ( $1, $2 );
+  unless ( $apacheip ) {
+    return "Configuration option apacheip not set; can't autocreate A record";
+           #"for $reczone". $svc_domain->domain;
   }
+  my $domain_record = new FS::domain_record {
+    'svcnum'  => $domain_svcnum,
+    'reczone' => $reczone,
+    'recaf'   => 'IN',
+    'rectype' => 'A',
+    'recdata' => $apacheip,
+  };
+  my $error = $domain_record->insert;
+  return $error if $error;
 
-  $dbh->commit or die $dbh->errstr if $oldAutoCommit;
-  '';
+  $self->recnum($domain_record->recnum);
+  return '';
 }
 
 =item delete



More information about the freeside-commits mailing list