Page MenuHomePhabricator

Merging users fails to merge edit counts.
Closed, ResolvedPublic

Description

When merging two users with https://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete the edits are merged, but the edit count is not updated as a total of all merged edits.

As you can see on http://ddowiki.com/page/Special:Contributions/ShoeMaker where I merged an account that had 12 edits with an account that had only 1 edit, in the top left corner of the page it is still reporting that "This user has made one edit." then goes on to list all 13.


Version: master
Severity: normal

Details

Reference
bz44917

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 22 2014, 1:21 AM
bzimport set Reference to bz44917.

Forgot to note that we are using User Merge and Delete (Version 1.6.31) (r115688) on my wiki and I'm not sure if this may have been fixed in 1.7. If so, please comment as such and close it as resolved.

Let's keep it open. I will check the issue wit the edit counts later.

steve_luxmoore wrote:

G'day all,

Which version I have, no idea. But I've downed the Git Snapshot from http://www.mediawiki.org/wiki/Extension:User_Merge_and_Delete so I only assume I have 1.7.

I got the <insert vulgarity> with it and found the prob. selectField returns (in this case) an int and not an array of ints. Below is a patch. I also updated the "print" statement to output the counts rather than the user ids.

/**
 * Function to add edit count
 *
 * Adds edit count of both users
 *
 * @param $newuserID int ID of user to merge references TO
 * @param $olduserID int ID of user to remove references FROM
 *
 * @return bool Always returns true - throws exceptions on failure.
 *
 * @author Matthew April <Matthew.April@tbs-sct.gc.ca>
 */
private function mergeEditcount( $newuserID, $olduserID ) {
        $dbw = wfGetDB( DB_MASTER );

        # old user edit count
        $oldEdits = $dbw->selectField( 'user',
                        'user_editcount',
                        array( 'user_id' => $olduserID ),
                        __METHOD__
                  );

        # new user edit count
        $newEdits = $dbw->selectField( 'user',
                        'user_editcount',
                        array( 'user_id' => $newuserID ),
                        __METHOD__
                  );

        # add edits
        $totalEdits = $oldEdits + $newEdits;

        # don't run querys if neither user has any edits
        if ( $totalEdits > 0 ) {
                # update new user with total edits
                $dbw->update( 'user',
                        array( 'user_editcount' => $totalEdits ),
                        array( 'user_id' => $newuserID ),
                        __METHOD__
                );

                # clear old users edits
                $dbw->update( 'user',
                        array( 'user_editcount' => 0 ),
                        array( 'user_id' => $olduserID ),
                        __METHOD__
                );
        }

        $this->getOutput()->addHTML( $this->msg( 'usermerge-editcount-success', $oldEdits, $newEdits )->escaped() . "<br />\n" );

        return true;
}

Cheers,
Idiot Boy Incorporated

Hi iboyinc. Can you put a patch in Gerrit (our Git code review system) please?

steve_luxmoore wrote:

Git Diff of my updates.

Had a surrenderable amount of troubles git-ting behind the corp proxy and so have attached a file containing output of git diff of the changes I made. I hope this helps any and all.

Attached:

(In reply to comment #1)

Forgot to note that we are using User Merge and Delete (Version 1.6.31)
(r115688) on my wiki and I'm not sure if this may have been fixed in 1.7. If
so, please comment as such and close it as resolved.

I looked to extension's version 1.7 in git https://gerrit.wikimedia.org/r/gitweb?p=mediawiki/extensions/UserMerge.git;a=blob;f=UserMerge_body.php;h=10a0167c2967557a4aca483de1eb43876fe26ed8;hb=b14eba4f2709cdb18ccbfefec8be462ed37360a3 , and this seems pretty much the same code, i.e. I close this bug here, because it is solved. Please update your mediawiki extensions (always) to the latest versions.

Your database select statements ( $oldedits = selectFields ) are however more elegant than the present version in git, and perhaps I upgrade them using your syntax (later).

For the time being: please can you confirm here, that the code in git is working ?

I close the bug now, because the problem is - according to me - solved the git version of the extension.

If you think, that this is not the case, please feel free to reopen the bug.

steve_luxmoore wrote:

The difference was that in the current Git version, [old,new]Edit was equated to the first item in the array result. This is a bug as SelectField returns a value, not an array.

I confirm that the changes I made, as detailed in the 4th comment and in the attached git diff, work.

Cheers,
Idiot Boy Supremo

steve_luxmoore wrote:

The other solution to get the current HEAD to work is to change SelectField to SelectFields.

Related URL: https://gerrit.wikimedia.org/r/66139 (Gerrit Change Ic837e2f84ad793d6f48b508d16919332812be6ac)

T. Gries: If you move the bug number from the first line to the last line, there will be automatic notifications by Gerrit into the corresponding bug report. See http://www.mediawiki.org/wiki/Gerrit/Commit_message_guidelines

(In reply to comment #13)

If you move the bug number from the first line to the last line,
there will be automatic notifications by Gerrit into the corresponding bug
report. See http://www.mediawiki.org/wiki/Gerrit/Commit_message_guidelines

okay, thanks for letting me know. I will use this concept for future commits.