From: ivan Date: Thu, 26 Feb 2004 03:32:16 +0000 (+0000) Subject: allow replace with no arguments X-Git-Tag: NET_WHOIS_RAW_0_31~124 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=1fe4c2f04162ea5082ded078ee9c1b8b4a86c4af allow replace with no arguments --- diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index b950e306b..4a3cbe791 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -806,7 +806,24 @@ returns the error, otherwise returns false. =cut sub replace { - my ( $new, $old ) = ( shift, shift ); + my $new = shift; + + my $old; + if ( @_ ) { + $old = shift; + } else { + warn "[debug]$me replace called with no arguments; autoloading old record\n" + if $DEBUG; + my $primary_key = $new->dbdef_table->primary_key; + if ( $primary_key ) { + $old = qsearchs($new->table, { $primary_key => $new->$primary_key() } ) + or croak "can't find ". $new->table. ".$primary_key ". + $new->$primary_key(); + } else { + croak $new->table. " has no primary key; pass old record as argument"; + } + } + warn "[debug]$me $new ->replace $old\n" if $DEBUG; return "Records not in same table!" unless $new->table eq $old->table;