unique checking for svc_phone like svc_acct, closes: RT#4204 (also a few lines of...
authorivan <ivan>
Sun, 21 Dec 2008 21:39:55 +0000 (21:39 +0000)
committerivan <ivan>
Sun, 21 Dec 2008 21:39:55 +0000 (21:39 +0000)
FS/FS/Upgrade.pm
FS/FS/svc_Common.pm
FS/FS/svc_acct.pm
FS/bin/freeside-upgrade

index 9618d5c..452c5a3 100644 (file)
@@ -84,6 +84,9 @@ sub upgrade_data {
 
   tie my %hash, 'Tie::IxHash', 
 
+    #msgcat
+    'msgcat' => [],
+
     #reason type and reasons
     'reason_type'     => [],
     'reason'          => [],
index 2866bfe..da1cfe1 100644 (file)
@@ -397,7 +397,7 @@ sub replace {
 
   #redundant, but so any duplicate fields are maniuplated as appropriate
   # (svc_phone.phonenum)
-  my $error = $new->check;
+  $error = $new->check;
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
     return $error;
index a4876c5..d59ee5e 100644 (file)
@@ -337,6 +337,8 @@ sub table_info {
 
 sub table { 'svc_acct'; }
 
+sub table_dupcheck_fields { ( 'username', 'domsvc' ); }
+
 sub _fieldhandlers {
   {
     #false laziness with edit/svc_acct.cgi
@@ -499,12 +501,6 @@ sub insert {
     $self->svcpart($cust_svc->svcpart);
   }
 
-  $error = $self->_check_duplicate;
-  if ( $error ) {
-    $dbh->rollback if $oldAutoCommit;
-    return $error;
-  }
-
   my @jobnums;
   $error = $self->SUPER::insert(
     'jobnums'       => \@jobnums,
@@ -817,15 +813,6 @@ sub replace {
 
   }
 
-  if ( $old->username ne $new->username || $old->domsvc != $new->domsvc ) {
-    $new->svcpart( $new->cust_svc->svcpart ) unless $new->svcpart;
-    $error = $new->_check_duplicate;
-    if ( $error ) {
-      $dbh->rollback if $oldAutoCommit;
-      return $error;
-    }
-  }
-
   $error = $new->SUPER::replace($old, @_);
   if ( $error ) {
     $dbh->rollback if $oldAutoCommit;
@@ -1227,7 +1214,7 @@ sub _check_system {
 
 =item _check_duplicate
 
-Internal function to check for duplicates usernames, username@domain pairs and
+Internal method to check for duplicates usernames, username@domain pairs and
 uids.
 
 If the I<global_unique-username> configuration value is set to B<username> or
@@ -1244,20 +1231,7 @@ sub _check_duplicate {
   my $global_unique = $conf->config('global_unique-username') || 'none';
   return '' if $global_unique eq 'disabled';
 
-  warn "$me locking svc_acct table for duplicate search" if $DEBUG;
-  if ( driver_name =~ /^Pg/i ) {
-    dbh->do("LOCK TABLE svc_acct IN SHARE ROW EXCLUSIVE MODE")
-      or die dbh->errstr;
-  } elsif ( driver_name =~ /^mysql/i ) {
-    dbh->do("SELECT * FROM duplicate_lock
-               WHERE lockname = 'svc_acct'
-              FOR UPDATE"
-          ) or die dbh->errstr;
-  } else {
-    die "unknown database ". driver_name.
-        "; don't know how to lock for duplicate search";
-  }
-  warn "$me acquired svc_acct table lock for duplicate search" if $DEBUG;
+  $self->lock_table;
 
   my $part_svc = qsearchs('part_svc', { 'svcpart' => $self->svcpart } );
   unless ( $part_svc ) {
index f3c4461..0b5758d 100755 (executable)
@@ -77,21 +77,26 @@ print "\n" if $DRY_RUN;
 
 if ( $dbh->{Driver}->{Name} =~ /^mysql/i && ! $opt_s ) {
 
-  my $sth = $dbh->prepare(
-    "SELECT COUNT(*) FROM duplicate_lock WHERE lockname = 'svc_acct'"
-  ) or die $dbh->errstr;
+  foreach my $table (qw( svc_acct svc_phone )) {
 
-  $sth->execute or die $sth->errstr;
-
-  unless ( $sth->fetchrow_arrayref->[0] ) {
-
-    $sth = $dbh->prepare(
-      "INSERT INTO duplicate_lock ( lockname ) VALUES ( 'svc_acct' )"
+    my $sth = $dbh->prepare(
+      "SELECT COUNT(*) FROM duplicate_lock WHERE lockname = '$table'"
     ) or die $dbh->errstr;
 
     $sth->execute or die $sth->errstr;
 
+    unless ( $sth->fetchrow_arrayref->[0] ) {
+
+      $sth = $dbh->prepare(
+        "INSERT INTO duplicate_lock ( lockname ) VALUES ( '$table' )"
+      ) or die $dbh->errstr;
+
+      $sth->execute or die $sth->errstr;
+
+    }
+
   }
+
 }
 
 $dbh->commit or die $dbh->errstr;