From 1fe4c2f04162ea5082ded078ee9c1b8b4a86c4af Mon Sep 17 00:00:00 2001 From: ivan Date: Thu, 26 Feb 2004 03:32:16 +0000 Subject: [PATCH] allow replace with no arguments --- FS/FS/Record.pm | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) 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; -- 2.11.0