[ljcom] r12498: LJSUP-12464: revoking rename results in ...
Committer: wisest-owl
LJSUP-12464: revoking rename results in error messageU trunk/cgi-bin/LJ/Pay/Payment/PayItem/RenameAction.pm
Modified: trunk/cgi-bin/LJ/Pay/Payment/PayItem/RenameAction.pm
===================================================================
--- trunk/cgi-bin/LJ/Pay/Payment/PayItem/RenameAction.pm 2012-08-20 12:02:59 UTC (rev 12497)
+++ trunk/cgi-bin/LJ/Pay/Payment/PayItem/RenameAction.pm 2012-08-20 12:58:05 UTC (rev 12498)
@@ -162,7 +162,7 @@
'wrap' => 1,
'charset' => 'utf-8',
'subject' => 'Rename Account Failure',
- 'body' => ("Failure processing user <" . $from_name . "> to user <" . $dest_name . ">" .
+ 'body' => ("Failure processing user <" . $from_name . "> to user <" . $dest_name . ">" .
"\n\nError: " . $opts->{error} . "\n")
});
LJ::statushistory_add($fromu->{'userid'}, $system->userid, 'rename_failure', "Failure processing user <" . $from_name . "> to user <" . $dest_name . ">. Error: " . $opts->{error} . ".");
@@ -178,7 +178,7 @@
status => 'pend', # ready to deliver, already set on all other items in this cart
);
- $payment->add_item_to_cart($it);
+ $payment->add_item_to_cart($it);
if (LJ::canonical_username($dest_name) eq $fromu->user) {
LJ::statushistory_add($fromu->{'userid'}, $system->userid, 'rename_failure', "Rename Account Identical (Line ".__LINE__.") <" . $from_name . "> to user <" . $dest_name . ">.");
@@ -235,7 +235,80 @@
sub _revoke_item {
my $self = shift;
- return 0; # cannot revert applied renaming now
+ my ($source_uid, $dest_name, $opt_delfriends, $opt_delfriendofs, $opt_redir, $opt_domainru) = split(":", $self->{subitem});
+
+ my $cart = LJ::Pay::Payment->load (payid => $self->{'payid'});
+ my $from_username = $cart->payvar_get ("rename:".$self->{'piid'}.":source");
+
+ my $from_u = LJ::load_user ($from_username);
+ my $to_u = LJ::load_user ($dest_name);
+
+ my $from = $from_u->username;
+ my $to = $to_u->username;
+
+ _err ("Can't revoke to '$from_username'. Username already taken by another user.")
+ unless $from_u->is_deleted || $from_u->is_expunged || $from_u->is_renamed;
+
+ my $dbh = LJ::get_db_writer();
+
+ my $actual_rename = sub {
+ my ($from, $to) = @_;
+ foreach my $table (qw(user useridmap overrides style)) {
+ $dbh->do("UPDATE $table SET user=? WHERE user=?",
+ undef, $to, $from);
+ return 1 if $dbh->err;
+ }
+ return 0;
+ };
+
+ ## 1. Back rename to previous username
+ for my $i (1..3) {
+ my $swap_name = LJ::User::Rename::get_unused_name ($to);
+ my $err = $actual_rename->($from, $swap_name);
+ last unless $err; # ok
+ }
+ $actual_rename->($to, $from);
+
+ ## 2. Friends and friends-of are not touch.
+
+ ## 3. Clear memcache for old and new usernames
+ LJ::memcache_kill($to_u, "userid");
+ LJ::memcache_kill($from_u, "userid");
+ LJ::MemCache::delete("uidof:".$from);
+ LJ::MemCache::delete("uidof:".$to);
+
+ # tell all web machines to clear their caches for this userid/name mapping
+ LJ::procnotify_add("rename_user", { 'userid' => $to_u->{'userid'},
+ 'user' => $to_u->{'user'} });
+
+ LJ::run_hooks("account_changed", { userid => $to_u->id() });
+
+ ## delete from renames table
+ $dbh->do("DELETE FROM renames WHERE userid=? AND fromuser=? AND touser=?",
+ undef, $to_u->{'userid'}, $from, $to
+ );
+
+ my $alias_changed = $dbh->do("UPDATE email_aliases SET alias=? WHERE alias=?",
+ undef, "$from\@$LJ::USER_DOMAIN",
+ "$to\@$LJ::USER_DOMAIN");
+
+ ## mark to delete current (new) user
+ LJ::update_user($from_u, { journaltype => $from_u->{journaltype}, raw => "name='[renamed acct]', statusvis='D', statusvisdate=NOW()" });
+
+ if ($to_u->{journaltype} ne 'P' || $opt_redir) {
+
+ ## clear prop 'renamedto'
+ $from_u->set_prop ('renamedto', undef);
+
+ if ($alias_changed > 0) {
+ $dbh->do("INSERT INTO email_aliases VALUES (?,?)", undef,
+ "$to_u->{'user'}\@$LJ::USER_DOMAIN",
+ $to_u->email_raw
+ );
+ }
+ }
+
+ return 1;
}
1;
