4
* Custom job to perform updates on tables in busier environments
6
class RenameUserJob extends Job {
11
* @param Title $title Associated title
12
* @param array $params Job parameters
14
public function __construct( $title, $params ) {
15
parent::__construct( 'renameUser', $title, $params );
23
public function run() {
24
$dbw = wfGetDB( DB_MASTER );
25
extract( $this->params );
26
# Conditions like "*_user_text = 'x'
27
$conds = array( $column => $oldname );
28
# If user ID given, add that to condition to avoid rename collisions.
29
if( isset($userID) ) {
30
$conds[$uidColumn] = $userID;
32
# Bound by timestamp if given
33
if( isset($timestampColumn) ) {
34
$conds[] = "$timestampColumn >= '$minTimestamp'";
35
$conds[] = "$timestampColumn <= '$maxTimestamp'";
36
# Otherwise, bound by key (B/C)
37
} else if( isset($uniqueKey) ) {
38
$conds[$uniqueKey] = $keyId;
40
wfDebug( 'RenameUserJob::run - invalid job row given' ); // this shouldn't happen
43
# Update a chuck of rows!
45
array( $column => $newname ),
49
# Special case: revisions may be deleted while renaming...
50
if( $table == 'revision' && isset($timestampColumn) ) {
51
$actual = $dbw->affectedRows();
52
# If some revisions were not renamed, they may have been deleted.
53
# Do a pass on the archive table to get these straglers...
54
if( $actual < $count ) {
55
$dbw->update( 'archive',
56
array( 'ar_user_text' => $newname ),
57
array( 'ar_user_text' => $oldname,
59
// No user,rev_id index, so use timestamp to bound
60
// the rows. This can use the user,timestamp index.
61
"ar_timestamp >= '$minTimestamp'",
62
"ar_timestamp <= '$maxTimestamp'"),
67
# Special case: revisions may be restored while renaming...
68
if( $table == 'archive' && isset($timestampColumn) ) {
69
$actual = $dbw->affectedRows();
70
# If some revisions were not renamed, they may have been restored.
71
# Do a pass on the revision table to get these straglers...
72
if( $actual < $count ) {
73
$dbw->update( 'revision',
74
array( 'rev_user_text' => $newname ),
75
array( 'rev_user_text' => $oldname,
76
'rev_user' => $userID,
77
// No user,rev_id index, so use timestamp to bound
78
// the rows. This can use the user,timestamp index.
79
"rev_timestamp >= '$minTimestamp'",
80
"rev_timestamp <= '$maxTimestamp'"),
b'\\ No newline at end of file'