Go to the documentation of this file.
26 require_once __DIR__ .
'/Maintenance.php';
36 parent::__construct();
37 $this->
addDescription(
'Reassign edits from one user to another' );
38 $this->
addOption(
"force",
"Reassign even if the target user doesn't exist" );
39 $this->
addOption(
"norc",
"Don't update the recent changes table" );
40 $this->
addOption(
"report",
"Print out details of what would be changed, but don't update it" );
41 $this->
addArg(
'from',
'Old user to take edits from' );
42 $this->
addArg(
'to',
'New user to give edits to' );
47 # Set up the users involved
51 # If the target doesn't exist, and --force is not set, stop here
52 if ( $to->getId() || $this->
hasOption(
'force' ) ) {
56 # If reporting, and there were items, advise the user to run without --report
58 $this->
output(
"Run the script again without --report to update.\n" );
61 $ton = $to->getName();
62 $this->
error(
"User '{$ton}' not found." );
81 $this->
output(
"Checking current edits..." );
84 [
'revision' ] + $revQueryInfo[
'tables'],
86 $revQueryInfo[
'conds'],
89 $revQueryInfo[
'joins']
91 $row = $dbw->fetchObject(
$res );
93 $this->
output(
"found {$cur}.\n" );
95 $this->
output(
"Checking deleted edits..." );
98 [
'archive' ] + $arQueryInfo[
'tables'],
100 $arQueryInfo[
'conds'],
103 $arQueryInfo[
'joins']
105 $row = $dbw->fetchObject(
$res );
107 $this->
output(
"found {$del}.\n" );
109 # Don't count recent changes if we're not supposed to
111 $this->
output(
"Checking recent changes..." );
114 [
'recentchanges' ] + $rcQueryInfo[
'tables'],
116 $rcQueryInfo[
'conds'],
119 $rcQueryInfo[
'joins']
121 $row = $dbw->fetchObject(
$res );
123 $this->
output(
"found {$rec}.\n" );
128 $total = $cur + $del + $rec;
129 $this->
output(
"\nTotal entries to change: {$total}\n" );
134 $this->
output(
"\nReassigning current edits..." );
136 'revision_actor_temp',
137 [
'revactor_actor' => $to->getActorId( $dbw ) ],
138 [
'revactor_actor' => $from->getActorId() ],
141 $this->
output(
"done.\nReassigning deleted edits..." );
142 $dbw->update(
'archive',
143 [
'ar_actor' => $to->getActorId( $dbw ) ],
144 [ $arQueryInfo[
'conds'] ], __METHOD__ );
145 $this->
output(
"done.\n" );
146 # Update recent changes if required
148 $this->
output(
"Updating recent changes..." );
149 $dbw->update(
'recentchanges',
150 [
'rc_actor' => $to->getActorId( $dbw ) ],
151 [ $rcQueryInfo[
'conds'] ], __METHOD__ );
152 $this->
output(
"done.\n" );
172 $user->setName( $username );
const RUN_MAINTENANCE_IF_MAIN
Maintenance script that reassigns edits from a user or IP address to another user.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
addDescription( $text)
Set the description text.
static newFromName( $name, $validate='valid')
Static factory method for creation from username.
hasArg( $argId=0)
Does a given argument exist?
doReassignEdits(&$from, &$to, $rc=false, $report=false)
Reassign edits from one user to another.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
static newMigration()
Static constructor.
initialiseUser( $username)
Initialise the user object.
__construct()
Default constructor.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
static isIP( $name)
Does the string match an anonymous IP address?
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
addArg( $arg, $description, $required=true)
Add some args that are needed.
error( $err, $die=0)
Throw an error to the user.
output( $out, $channel=null)
Throw some output to the user.
hasOption( $name)
Checks to see if a particular option exists.
getArg( $argId=0, $default=null)
Get an argument.
The User object encapsulates all of the user-specific settings (user_id, name, rights,...
execute()
Do the actual work.