mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2012-01-23 11:35 am

[dw-free] ability to "claim" your OpenID and update imported posts/comments as coming from

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

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

More work on the claimer. I forgot to update picture mappings. Fixed.

Patch by [staff profile] mark.

Files modified:
  • cgi-bin/DW/Worker/ChangePosterId.pm
--------------------------------------------------------------------------------
diff -r 037883470f4e -r a2c860e74f7d cgi-bin/DW/Worker/ChangePosterId.pm
--- a/cgi-bin/DW/Worker/ChangePosterId.pm	Mon Jan 23 10:19:28 2012 +0000
+++ b/cgi-bin/DW/Worker/ChangePosterId.pm	Mon Jan 23 11:37:12 2012 +0000
@@ -38,6 +38,8 @@
         if keys %arg;
     return $job->permanent_failure( 'Makes no sense! The users are the same?!' )
         if $fu->id == $tu->id;
+    return $job->permanent_failure( 'Both users must be dversion 9+ to use this.' )
+        unless $fu->dversion >= 9 && $tu->dversion >= 9;
 
     # Basically, all this job is doing is reparenting comments and posts that
     # have been made by a particular user. We try to be gentle to the database by
@@ -65,8 +67,15 @@
     my ( $dbcm, $fu, $tu ) = @_;
 
     my $total = $dbcm->selectrow_array( 'SELECT COUNT(*) FROM log2 WHERE posterid = ?', undef, $fu->id );
+    die $dbcm->errstr if $dbcm->err;
+    return unless $total > 0;
     title( $fu, $tu, 'entries', 0, $total );
 
+    # we need these ids
+    my $p_id = LJ::get_prop( log => 'picture_mapid' )->{id};
+    die "Unable to load property ID.\n"
+        unless $p_id;
+
     my $ct = 0;
     while ( 1 ) {
         my $rows = $dbcm->selectall_arrayref(
@@ -78,6 +87,8 @@
 
         foreach my $row ( @$rows ) {
             my ( $jid, $jitemid ) = @$row;
+            my $u = LJ::load_userid( $jid );
+            die "Failed to load user object for location.\n" unless $u;
 
             $ct++;
             title( $fu, $tu, 'entries', $ct, $total );
@@ -89,9 +100,35 @@
             );
             die $dbcm->errstr if $dbcm->err;
 
+            # fix the pictures on this post
+            my $mapid = $dbcm->selectrow_array( 'SELECT value FROM logprop2 ' .
+                'WHERE journalid = ? AND jitemid = ? AND propid = ?',
+                undef, $jid, $jitemid, $p_id
+            );
+            die $dbcm->errstr if $dbcm->err;
+
+            # but only if it exists... and it should always be 1+ due to how we use
+            # the usercounters
+            if ( defined $mapid && $mapid > 0 ) {
+                my $kw = $fu->get_keyword_from_mapid( $mapid ) ||
+                    $u->get_keyword_from_mapid( $mapid );
+                if ( $kw ) {
+                    my $newid = $tu->get_mapid_from_keyword( $kw, create => 1 );
+                    die "Failed to allocate new picture_mapid.\n"
+                        unless defined $newid && $newid > 0;
+
+                    $dbcm->do( 'UPDATE logprop2 SET value = ? ' .
+                        'WHERE journalid = ? AND jitemid = ? AND propid = ?',
+                        undef, $newid, $jid, $jitemid, $p_id
+                    );
+                    die $dbcm->errstr if $dbcm->err;
+                }
+            }
+            
             # now nuke the memcache
             LJ::MemCache::delete( [ $jid, "log2:$jid:$jitemid" ] );
             LJ::MemCache::delete( [ $jid, "log2lt:$jid" ] );
+            LJ::MemCache::delete( [ $jid, "logprop:$jid:$jitemid" ] );
         }
     }
 }
@@ -100,8 +137,15 @@
     my ( $dbcm, $fu, $tu ) = @_;
 
     my $total = $dbcm->selectrow_array( 'SELECT COUNT(*) FROM talk2 WHERE posterid = ?', undef, $fu->id );
+    die $dbcm->errstr if $dbcm->err;
+    return unless $total > 0;
     title( $fu, $tu, 'comments', 0, $total );
 
+    # we need these ids
+    my $p_id = LJ::get_prop( talk => 'picture_mapid' )->{id};
+    die "Unable to load property ID.\n"
+        unless $p_id;
+
     my $ct = 0;
     while ( 1 ) {
         my $rows = $dbcm->selectall_arrayref(
@@ -114,6 +158,8 @@
 
         foreach my $row ( @$rows ) {
             my ( $jid, $jtalkid, $nodetype, $nodeid ) = @$row;
+            my $u = LJ::load_userid( $jid );
+            die "Failed to load user object for location.\n" unless $u;
 
             $ct++;
             title( $fu, $tu, 'comments', $ct, $total );
@@ -125,9 +171,35 @@
             );
             die $dbcm->errstr if $dbcm->err;
 
+            # fix the pictures on this comment
+            my $mapid = $dbcm->selectrow_array( 'SELECT value FROM talkprop2 ' .
+                'WHERE journalid = ? AND jtalkid = ? AND tpropid = ?',
+                undef, $jid, $jtalkid, $p_id
+            );
+            die $dbcm->errstr if $dbcm->err;
+
+            # but only if it exists... and it should always be 1+ due to how we use
+            # the usercounters
+            if ( defined $mapid && $mapid > 0 ) {
+                my $kw = $fu->get_keyword_from_mapid( $mapid ) ||
+                    $u->get_keyword_from_mapid( $mapid );
+                if ( $kw ) {
+                    my $newid = $tu->get_mapid_from_keyword( $kw, create => 1 );
+                    die "Failed to allocate new picture_mapid.\n"
+                        unless defined $newid && $newid > 0;
+
+                    $dbcm->do( 'UPDATE talkprop2 SET value = ? ' .
+                        'WHERE journalid = ? AND jtalkid = ? AND tpropid = ?',
+                        undef, $newid, $jid, $jtalkid, $p_id
+                    );
+                    die $dbcm->errstr if $dbcm->err;
+                }
+            }
+            
             # now nuke the memcache
             LJ::MemCache::delete( [ $jid, "talk2:$jid:$nodetype:$nodeid" ] );
             LJ::MemCache::delete( [ $jid, "talk2row:$jid:$jtalkid" ] );
+            LJ::MemCache::delete( [ $jid, "talkprop:$jid:$jtalkid" ] );
         }
     }
 
--------------------------------------------------------------------------------