From 3bda877eb55e07400f7327a09b07a094e5b44cc0 Mon Sep 17 00:00:00 2001 From: Rob Church Date: Thu, 26 Jan 2006 21:41:40 +0000 Subject: [PATCH] Maintenance script to reassign edits from one user to another --- RELEASE-NOTES | 1 + maintenance/reassignEdits.inc | 83 +++++++++++++++++++++++++++++++++++ maintenance/reassignEdits.php | 42 ++++++++++++++++++ 3 files changed, 126 insertions(+) create mode 100644 maintenance/reassignEdits.inc create mode 100644 maintenance/reassignEdits.php diff --git a/RELEASE-NOTES b/RELEASE-NOTES index c3fd72c5b3..5b50d8a19e 100644 --- a/RELEASE-NOTES +++ b/RELEASE-NOTES @@ -135,6 +135,7 @@ Maintenance: * Maintenance script to delete unused text records * Maintenance script to delete non-current revisions * Maintenance script to wipe a page and all revisions from the database +* Maintenance script to reassign edits from one user to another i18n / Languages: * Partial support for Basque language (from wikipedia and meta) diff --git a/maintenance/reassignEdits.inc b/maintenance/reassignEdits.inc new file mode 100644 index 0000000000..af4c601487 --- /dev/null +++ b/maintenance/reassignEdits.inc @@ -0,0 +1,83 @@ + + */ + +function ReassignEdits( $from, $to ) { + + # This stuff needs to come off the master, wrapped in a transaction + $dbw =& wfGetDB( DB_MASTER ); + $dbw->begin(); + + $tbl_arc = $dbw->tableName( 'archive' ); + $tbl_rev = $dbw->tableName( 'revision' ); + + $from_txt = $from['text']; + $to_id = $to['id']; + $to_txt = $to['text']; + + echo( "Searching for current revisions..." ); + $res = $dbw->query( "SELECT rev_id FROM $tbl_rev WHERE rev_user_text = \"$from_txt\"" ); + while( $row = $dbw->fetchObject( $res ) ) { + $cur[] = $row->rev_id; + } + $ccount = count( $cur ); + echo( "found $ccount.\n" ); + + echo( "Searching for deleted revisions..." ); + $res = $dbw->query( "SELECT ar_rev_id FROM $tbl_arc WHERE ar_user_text = \"$from_txt\"" ); + while( $row = $dbw->fetchObject( $res ) ){ + $old[] = $row->ar_rev_id; + } + $ocount = count( $old ); + echo( "found $ocount.\n" ); + + if( $ccount > 0 || $ocount > 0 ) { + echo( "Reassigning edits to $to_txt..." ); + } + + if( $ccount > 0 ) { + $set = implode( ', ', $cur ); + $res = $dbw->query( "UPDATE $tbl_rev SET rev_user = $to_id, rev_user_text = \"$to_txt\" WHERE rev_id IN ( $set )" ); + } + + if( $ocount > 0 ) { + $set = implode( ', ', $old ); + $res = $dbw->query( "UPDATE $tbl_arc SET ar_user = $to_id, ar_user_text = \"$to_txt\" WHERE ar_rev_id IN ( $set )" ); + } + + if( $ccount > 0 || $ocount > 0 ) { + echo( "done.\n" ); + } + + $dbw->commit(); + return( true ); + +} + +function GetUserDetails( $spec ) { + + # IP addresses are quick to handle + if( User::isIP( $spec ) ) { + return( array( 'id' => 0, 'text' => $spec, 'valid' => true ) ); + } + + # Need to check the user exists and get ID and canonical username + $user = User::newFromName( $spec ); + if( $user->getID() ) { + # We have them + return( array( 'id' => $user->getID(), 'text' => $user->getName(), 'valid' => true ) ); + } else { + # No such user + return( array( 'id' => 0, 'text' => $spec, 'valid' => false ) ); + } + +} + + +?> diff --git a/maintenance/reassignEdits.php b/maintenance/reassignEdits.php new file mode 100644 index 0000000000..751d200480 --- /dev/null +++ b/maintenance/reassignEdits.php @@ -0,0 +1,42 @@ + + */ + +$options = array( 'force' ); +require_once( 'commandLine.inc' ); +require_once( 'reassignEdits.inc' ); + +echo( "Reassign Edits\n\n" ); + +if( @$args[0] && @$args[1] ) { + + $from = GetUserDetails( $args[0] ); + $to = GetUserDetails( $args[1] ); + $tor = $args[1]; + + if( $to['valid'] || @$options['force'] ) { + ReassignEdits( $from, $to ); + } else { + echo( "User \"$tor\" not found.\n" ); + } + +} else { + ShowUsage(); +} + +/** Show script usage information */ +function ShowUsage() { + echo( "Reassign edits from one user to another.\n\n" ); + echo( "Usage: php reassignEdits.php [--force]\n\n" ); + echo( " : Name of the user to assign edits from\n" ); + echo( " : Name of the user to assign edits to\n" ); + echo( " --force : Reassign even if the target user doesn't exist\n\n" ); +} + +?> \ No newline at end of file -- 2.20.1