
interchange-cvs at icdevgroup
May 20, 2009, 4:37 PM
Post #2 of 2
(343 views)
Permalink
|
User: pajamian Date: 2009-05-20 23:37:27 GMT Modified: . WHATSNEW-5.7 Modified: code/UI_Tag user_merge.tag Log: New user_merge specialsub is run from the [user-merge] usertag. Arguments passed to the sub are: ($from_user, $from_urec, $to_user, $to_urec, $udb, $tdb) with the following values: $from_user - The username of the user being merged from. $from_urec - Hashref of columns in the userdb table for the user being merged from. $to_user - The username of the user being merged to. $to_urec - Hashref of columns in the userdb table for the user being merged to. Any changes made to this hashref will be recorded back into the userdb for this user. $udb - $db object for the userdb table. $tdb - $db object for the transactions table. The return value should be false to indicate that normal processing of the merge should continue as normal for this from user (continue on to merge carts and transactions) or true to indicate that no further processing should be done for this user (do not merge the carts or transactions). A false return value will also cause any changes to $to_urec to be recorded into the userdb for the to user at the conclusion of the merge. Note that if there are multiple from users then this specialsub will be run for each of the from users. Example: SpecialSub user_merge user_merge_sub Sub user_merge_sub <<EOS sub { my ($from_user, $from_urec, $to_user, $to_urec, $udb, $tdb) = @_; # Copy first and last name over from from user: $to_urec->{fname} = $from_urec->{fname}; $to_urec->{lname} = $from_urec->{lname}; # False return value tells the [user-merge] tag to save the new $to_urec # structure off as well as to continue with normal processing of the # merge. return; } EOS Revision Changes Path 2.45 interchange/WHATSNEW-5.7 rev 2.45, prev_rev 2.44 Index: WHATSNEW-5.7 =================================================================== RCS file: /var/cvs/interchange/WHATSNEW-5.7,v retrieving revision 2.44 retrieving revision 2.45 diff -u -r2.44 -r2.45 --- WHATSNEW-5.7 20 May 2009 22:13:32 -0000 2.44 +++ WHATSNEW-5.7 20 May 2009 23:37:27 -0000 2.45 @@ -169,6 +169,9 @@ * Allow file removal with uploadhelper widget (#180). +* New user_merge specialsub is run from the [user-merge] tag when two users are + merged. + Standard demo ------------- 1.4 interchange/code/UI_Tag/user_merge.tag rev 1.4, prev_rev 1.3 Index: user_merge.tag =================================================================== RCS file: /var/cvs/interchange/code/UI_Tag/user_merge.tag,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- user_merge.tag 21 Jan 2008 19:22:55 -0000 1.3 +++ user_merge.tag 20 May 2009 23:37:27 -0000 1.4 @@ -1,11 +1,11 @@ -# Copyright 2005-2007 Interchange Development Group and others +# Copyright 2005-2009 Interchange Development Group and others # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. See the LICENSE file for details. # -# $Id: user_merge.tag,v 1.3 2008-01-21 19:22:55 mheins Exp $ +# $Id: user_merge.tag,v 1.4 2009-05-20 23:37:27 pajamian Exp $ UserTag user-merge Order from to UserTag user-merge addAttr @@ -134,10 +134,33 @@ my $logfile = $opt->{logfile} || 'logs/merged_users.log'; my $done_one; + my $save_rec; for my $user (@users) { $Tag->log({ type => 'text', file => $logfile, body => $Tag->time() . "\n" } ) unless $done_one++; + + my $from_urec = $udb->row_hash($user); + + # If there's a user_merge specialsub run it here + if (my $subname = $Vend::Cfg->{SpecialSub}{user_merge}) { + my $sub = $Vend::Cfg->{Sub}{$subname} || $Global::GlobalSub->{$subname}; + my $status; + eval { $status = $sub->($user, $from_urec, $to_user, $urec, $udb, $tdb) }; + if ($@) { + ::logError("Error running %s subroutine %s: %s", 'user_merge', $subname, $@); + } + + elsif ($status) { + # Skip further processing of this user + next; + } + + else { + $save_rec = 1; + } + } + for(@ttab) { $sth{$_}->execute($to_user, $user) or $err->("%s update failed: %s", $_, $dbh{$_}->errstr); @@ -147,12 +170,11 @@ push @record, $o; } - my $urec = $udb->row_hash($user); - my $chash = string_to_ref($urec->{carts}); + my $chash = string_to_ref($from_urec->{carts}); if(ref $chash) { for(keys %$chash) { if($cart_hash->{$_}) { - $Tag->log({ type => 'text', file => $logfile, body => "unable to merge cart=$_ (already exists). Contents=$urec->{carts}\n"} ); + $Tag->log({ type => 'text', file => $logfile, body => "unable to merge cart=$_ (already exists). Contents=$from_urec->{carts}\n"} ); } else { $cart_hash->{$_} = $chash->{$_}; @@ -160,7 +182,7 @@ } } } - my $ustring = ::uneval($urec); + my $ustring = ::uneval($from_urec); $Tag->log({ type => 'text', file => $logfile, body => "delete user $user=$ustring\n"} ); $udb->delete_record($user) unless $opt->{no_delete}; @@ -168,8 +190,20 @@ } if($carts_changed) { - $udb->set_field($to, 'carts', ::uneval($cart_hash)); + if ($save_rec) { + $urec->{carts} = ::uneval($cart_hash); + } + + else { + $udb->set_field($to, 'carts', ::uneval($cart_hash)); + } } + + if ($save_rec) { + delete $urec->{$udb->[$Vend::Table::DBI::KEY]}; + $udb->set_slice($to, $urec); + } + push @record, ''; $Tag->log({ type => 'text', file => $logfile, body => join("\n", @record)} ); _______________________________________________ interchange-cvs mailing list interchange-cvs [at] icdevgroup http://www.icdevgroup.org/mailman/listinfo/interchange-cvs
|