summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorivan <ivan>2008-12-21 21:39:55 +0000
committerivan <ivan>2008-12-21 21:39:55 +0000
commitb333223b0223e560a877e1d5f4c433b5ef6da54f (patch)
tree9d1bf46631621a962a68a6ac5f8fb384930a27a4
parent48bade3f01a672f235d61a29ad0d0b792fc80eab (diff)
unique checking for svc_phone like svc_acct, closes: RT#4204 (also a few lines of the new per-agent config snuck in Conf.pm from RT#3989)
-rw-r--r--FS/FS/Upgrade.pm3
-rw-r--r--FS/FS/svc_Common.pm2
-rw-r--r--FS/FS/svc_acct.pm34
-rwxr-xr-xFS/bin/freeside-upgrade23
4 files changed, 22 insertions, 40 deletions
diff --git a/FS/FS/Upgrade.pm b/FS/FS/Upgrade.pm
index 9618d5ca4..452c5a300 100644
--- a/FS/FS/Upgrade.pm
+++ b/FS/FS/Upgrade.pm
@@ -84,6 +84,9 @@ sub upgrade_data {
tie my %hash, 'Tie::IxHash',
+ #msgcat
+ 'msgcat' => [],
+
#reason type and reasons
'reason_type' => [],
'reason' => [],
diff --git a/FS/FS/svc_Common.pm b/FS/FS/svc_Common.pm
index 2866bfea4..da1cfe135 100644
--- a/FS/FS/svc_Common.pm
+++ b/FS/FS/svc_Common.pm
@@ -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;
diff --git a/FS/FS/svc_acct.pm b/FS/FS/svc_acct.pm
index a4876c5a5..d59ee5ee3 100644
--- a/FS/FS/svc_acct.pm
+++ b/FS/FS/svc_acct.pm
@@ -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 ) {
diff --git a/FS/bin/freeside-upgrade b/FS/bin/freeside-upgrade
index f3c446169..0b5758d8e 100755
--- a/FS/bin/freeside-upgrade
+++ b/FS/bin/freeside-upgrade
@@ -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;