[freeside-commits] freeside/FS/FS svc_acct.pm, 1.217.2.31, 1.217.2.32 svc_Common.pm, 1.39.2.8, 1.39.2.9 svc_domain.pm, 1.48.2.1, 1.48.2.2 svc_forward.pm, 1.20, 1.20.2.1 svc_www.pm, 1.14.2.1, 1.14.2.2

Ivan,,, ivan at wavetail.420.am
Wed Oct 28 12:06:27 PDT 2009


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

Modified Files:
      Tag: FREESIDE_1_7_BRANCH
	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.39.2.8
retrieving revision 1.39.2.9
diff -u -d -r1.39.2.8 -r1.39.2.9
--- svc_Common.pm	4 Aug 2009 22:05:00 -0000	1.39.2.8
+++ svc_Common.pm	28 Oct 2009 19:06:24 -0000	1.39.2.9
@@ -251,8 +251,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;
@@ -316,6 +319,11 @@
   '';
 }
 
+#fallbacks
+sub preinsert_hook_first { ''; }
+sub _check_duplcate { ''; }
+sub preinsert_hook { ''; }
+
 =item delete
 
 Deletes this account from the database.  If there is an error, returns the

Index: svc_forward.pm
===================================================================
RCS file: /home/cvs/cvsroot/freeside/FS/FS/svc_forward.pm,v
retrieving revision 1.20
retrieving revision 1.20.2.1
diff -u -d -r1.20 -r1.20.2.1
--- svc_forward.pm	29 Dec 2006 08:51:32 -0000	1.20
+++ svc_forward.pm	28 Oct 2009 19:06:24 -0000	1.20.2.1
@@ -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.217.2.31
retrieving revision 1.217.2.32
diff -u -d -r1.217.2.31 -r1.217.2.32
--- svc_acct.pm	5 Aug 2009 02:27:36 -0000	1.217.2.31
+++ svc_acct.pm	28 Oct 2009 19:06:24 -0000	1.217.2.32
@@ -531,48 +531,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);
-  }
-
-  $error = $self->_check_duplicate;
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
-  }
-
-  # 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,
@@ -682,6 +642,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.48.2.1
retrieving revision 1.48.2.2
diff -u -d -r1.48.2.1 -r1.48.2.2
--- svc_domain.pm	15 May 2009 19:43:05 -0000	1.48.2.1
+++ svc_domain.pm	28 Oct 2009 19:06:24 -0000	1.48.2.2
@@ -179,13 +179,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;
@@ -382,6 +375,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.14.2.1
retrieving revision 1.14.2.2
diff -u -d -r1.14.2.1 -r1.14.2.2
--- svc_www.pm	24 Apr 2007 00:22:54 -0000	1.14.2.1
+++ svc_www.pm	28 Oct 2009 19:06:24 -0000	1.14.2.2
@@ -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