summaryrefslogtreecommitdiff
path: root/FS/FS/Record.pm
diff options
context:
space:
mode:
authorivan <ivan>2008-12-21 21:33:28 +0000
committerivan <ivan>2008-12-21 21:33:28 +0000
commit48bade3f01a672f235d61a29ad0d0b792fc80eab (patch)
tree175a6d060f647f9411d2634b109bbbb8ec5bbb1e /FS/FS/Record.pm
parent93d2608554affca0d1e49ab1469328960c75848e (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)
Diffstat (limited to 'FS/FS/Record.pm')
-rw-r--r--FS/FS/Record.pm44
1 files changed, 44 insertions, 0 deletions
diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm
index 1f0b140..acec945 100644
--- a/FS/FS/Record.pm
+++ b/FS/FS/Record.pm
@@ -766,6 +766,50 @@ sub select_for_update {
} );
}
+=item lock_table
+
+Locks this table with a database-driver specific lock method. This is used
+as a mutex in order to do a duplicate search.
+
+For PostgreSQL, does "LOCK TABLE tablename IN SHARE ROW EXCLUSIVE MODE".
+
+For MySQL, does a SELECT FOR UPDATE on the duplicate_lock table.
+
+Errors are fatal; no useful return value.
+
+Note: To use this method for new tables other than svc_acct and svc_phone,
+edit freeside-upgrade and add those tables to the duplicate_lock list.
+
+=cut
+
+sub lock_table {
+ my $self = shift;
+ my $table = $self->table;
+
+ warn "$me locking $table table\n" if $DEBUG;
+
+ if ( driver_name =~ /^Pg/i ) {
+
+ dbh->do("LOCK TABLE $table IN SHARE ROW EXCLUSIVE MODE")
+ or die dbh->errstr;
+
+ } elsif ( driver_name =~ /^mysql/i ) {
+
+ dbh->do("SELECT * FROM duplicate_lock
+ WHERE lockname = '$table'
+ FOR UPDATE"
+ ) or die dbh->errstr;
+
+ } else {
+
+ die "unknown database ". driver_name. "; don't know how to lock table";
+
+ }
+
+ warn "$me acquired $table table lock\n" if $DEBUG;
+
+}
+
=item insert
Inserts this record to the database. If there is an error, returns the error,