28require_once __DIR__ .
'/Maintenance.php';
38 parent::__construct();
39 $this->
addDescription(
'Reassign edits from one user to another' );
40 $this->
addOption(
"force",
"Reassign even if the target user doesn't exist" );
41 $this->
addOption(
"norc",
"Don't update the recent changes table" );
42 $this->
addOption(
"report",
"Print out details of what would be changed, but don't update it" );
43 $this->
addArg(
'from',
'Old user to take edits from' );
44 $this->
addArg(
'to',
'New user to give edits to' );
49 # Set up the users involved
53 # If the target doesn't exist, and --force is not set, stop here
54 if ( $to->getId() || $this->hasOption(
'force' ) ) {
58 # If reporting, and there were items, advise the user to run without --report
60 $this->
output(
"Run the script again without --report to update.\n" );
63 $ton = $to->getName();
64 $this->
error(
"User '{$ton}' not found." );
83 $this->
output(
"Checking current edits..." );
84 $revQueryInfo = ActorMigration::newMigration()->getWhere( $dbw,
'rev_user', $from );
86 [
'revision' ] + $revQueryInfo[
'tables'],
88 $revQueryInfo[
'conds'],
91 $revQueryInfo[
'joins']
93 $row = $dbw->fetchObject(
$res );
95 $this->
output(
"found {$cur}.\n" );
97 $this->
output(
"Checking deleted edits..." );
98 $arQueryInfo = ActorMigration::newMigration()->getWhere( $dbw,
'ar_user', $from,
false );
100 [
'archive' ] + $arQueryInfo[
'tables'],
102 $arQueryInfo[
'conds'],
105 $arQueryInfo[
'joins']
107 $row = $dbw->fetchObject(
$res );
109 $this->
output(
"found {$del}.\n" );
111 # Don't count recent changes if we're not supposed to
113 $this->
output(
"Checking recent changes..." );
114 $rcQueryInfo = ActorMigration::newMigration()->getWhere( $dbw,
'rc_user', $from,
false );
116 [
'recentchanges' ] + $rcQueryInfo[
'tables'],
118 $rcQueryInfo[
'conds'],
121 $rcQueryInfo[
'joins']
123 $row = $dbw->fetchObject(
$res );
125 $this->
output(
"found {$rec}.\n" );
130 $total = $cur + $del + $rec;
131 $this->
output(
"\nTotal entries to change: {$total}\n" );
136 $this->
output(
"\nReassigning current edits..." );
138 'revision_actor_temp',
139 [
'revactor_actor' => $to->getActorId( $dbw ) ],
140 [
'revactor_actor' => $from->getActorId() ],
143 $this->
output(
"done.\nReassigning deleted edits..." );
144 $dbw->update(
'archive',
145 [
'ar_actor' => $to->getActorId( $dbw ) ],
146 [ $arQueryInfo[
'conds'] ], __METHOD__ );
147 $this->
output(
"done.\n" );
148 # Update recent changes if required
150 $this->
output(
"Updating recent changes..." );
151 $dbw->update(
'recentchanges',
152 [
'rc_actor' => $to->getActorId( $dbw ) ],
154 [ $rcQueryInfo[
'conds'] ], __METHOD__ );
155 $this->
output(
"done.\n" );
159 # If $from is an IP, delete any relevant rows from the
160 # ip_changes. No update needed, as $to cannot be an IP.
161 if ( !$from->isRegistered() ) {
162 $this->
output(
"Deleting ip_changes..." );
166 'ipc_hex' => IPUtils::toHex( $from->getName() )
170 $this->
output(
"done.\n" );
186 if ( User::isIP( $username ) ) {
187 $user = User::newFromName( $username,
false );
190 $user = User::newFromName( $username );
const RUN_MAINTENANCE_IF_MAIN
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true)
Add some args that are needed.
beginTransaction(IDatabase $dbw, $fname)
Begin a transcation on a DB.
commitTransaction(IDatabase $dbw, $fname)
Commit the transcation on a DB handle and wait for replica DBs to catch up.
output( $out, $channel=null)
Throw some output to the user.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option was set.
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that reassigns edits from a user or IP address to another user.
execute()
Do the actual work.
__construct()
Default constructor.
initialiseUser( $username)
Initialise the user object.
doReassignEdits(&$from, &$to, $rc=false, $report=false)
Reassign edits from one user to another.