fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-07-13 01:47 pm

[dw-free] It is possible to add a redirect account to your circle.

[commit: http://hg.dwscoalition.org/dw-free/rev/bfd5b6097df3]

http://bugs.dwscoalition.org/show_bug.cgi?id=3570

Do a one-time update to fix existing instances where someone has mistakenly
added a redirecting account instead of the account that the user actually
redirects to.

Patch by [personal profile] fu.

Files modified:
  • bin/upgrading/update-db-general.pl
--------------------------------------------------------------------------------
diff -r bfb6a0650304 -r bfd5b6097df3 bin/upgrading/update-db-general.pl
--- a/bin/upgrading/update-db-general.pl	Wed Jul 13 21:42:18 2011 +0800
+++ b/bin/upgrading/update-db-general.pl	Wed Jul 13 21:46:45 2011 +0800
@@ -3950,6 +3950,49 @@
     unless ( column_type( 'acctcode_promo', 'paid_class' ) =~ /^\Qvarchar(100)\E/ ) {
         do_alter( 'acctcode_promo', "ALTER TABLE acctcode_promo MODIFY COLUMN paid_class varchar(100)" );
     }
+
+    if ( table_relevant( "wt_edges" ) && ! check_dbnote( "fix_redirect_edges" ) ) {
+        warn "fixing edges leading to a redirect account";
+        my $sth = $dbh->prepare(
+                              qq{ SELECT from_userid, to_userid FROM wt_edges INNER JOIN user
+                                    ON user.journaltype="R" AND user.userid=wt_edges.to_userid;
+                                    } );
+        $sth->execute();
+        die $sth->errstr if $sth->err;
+
+        while ( my ( $from_userid, $to_userid ) = $sth->fetchrow_array ) {
+            my $from_u = LJ::load_userid( $from_userid );
+            my $to_u = LJ::load_userid( $to_userid );
+
+            my $redir_u = $to_u->get_renamed_user;
+
+            warn "transferring edge of $from_u->{user}=>$to_u->{user} to $from_u->{user}=>$redir_u->{user}";
+            if ( $from_u->trusts( $to_u ) ) {
+                if ( $from_u->trusts( $redir_u ) ) {
+                    warn "...already trusted";
+                } else {
+                    warn "...adding trust edge";
+                    $from_u->add_edge( $redir_u, trust => { nonotify => 1 } )
+                }
+
+                $from_u->remove_edge( $to_u, trust => { nonotify => 1 } );
+            }
+            if ( $from_u->watches( $to_u ) ) {
+                if ( $from_u->watches( $redir_u ) ) {
+                    warn "...already watched";
+                } else {
+                    warn "...adding trust edge";
+                    $from_u->add_edge( $redir_u, watch => { nonotify => 1 } )
+                }
+
+                $from_u->remove_edge( $to_u, watch => { nonotify => 1 } );
+            }
+        }
+
+        set_dbnote( "fix_redirect_edges", 1 );
+    }
+
+
 });
 
 
--------------------------------------------------------------------------------