[ Index ] |
PHP Cross Reference of MediaWiki-1.24.0 |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Custom job to perform updates on tables in busier environments 4 */ 5 class RenameUserJob extends Job { 6 /** 7 * Constructor 8 * 9 * @param Title $title Associated title 10 * @param array $params Job parameters 11 * @param int $id 12 */ 13 public function __construct( $title, $params = array(), $id = 0 ) { 14 parent::__construct( 'renameUser', $title, $params, $id ); 15 } 16 17 /** 18 * Execute the job 19 * 20 * @return bool 21 */ 22 public function run() { 23 $dbw = wfGetDB( DB_MASTER ); 24 25 $table = $this->params['table']; 26 $column = $this->params['column']; 27 $oldname = $this->params['oldname']; 28 $userID = isset( $this->params['userID'] ) ? $this->params['userID'] : null; 29 $uidColumn = isset( $this->params['uidColumn'] ) ? $this->params['uidColumn'] : null; 30 $timestampColumn = isset( $this->params['timestampColumn'] ) ? $this->params['timestampColumn'] : null; 31 $minTimestamp = $this->params['minTimestamp']; 32 $maxTimestamp = $this->params['maxTimestamp']; 33 $uniqueKey = isset( $this->params['uniqueKey'] ) ? $this->params['uniqueKey'] : null; 34 $keyId = isset( $this->params['keyId'] ) ? $this->params['keyId'] : null; 35 $newname = $this->params['newname']; 36 $count = $this->params['count']; 37 38 # Conditions like "*_user_text = 'x' 39 $conds = array( $column => $oldname ); 40 # If user ID given, add that to condition to avoid rename collisions. 41 if ( isset( $userID ) ) { 42 $conds[$uidColumn] = $userID; 43 } 44 # Bound by timestamp if given 45 if ( isset( $timestampColumn ) ) { 46 $conds[] = "$timestampColumn >= '$minTimestamp'"; 47 $conds[] = "$timestampColumn <= '$maxTimestamp'"; 48 # Otherwise, bound by key (B/C) 49 } elseif ( isset( $uniqueKey ) ) { 50 $conds[$uniqueKey] = $keyId; 51 } else { 52 wfDebug( 'RenameUserJob::run - invalid job row given' ); // this shouldn't happen 53 return false; 54 } 55 # Update a chuck of rows! 56 $dbw->update( $table, 57 array( $column => $newname ), 58 $conds, 59 __METHOD__ 60 ); 61 # Special case: revisions may be deleted while renaming... 62 if ( $table == 'revision' && isset( $timestampColumn ) ) { 63 $actual = $dbw->affectedRows(); 64 # If some revisions were not renamed, they may have been deleted. 65 # Do a pass on the archive table to get these straglers... 66 if ( $actual < $count ) { 67 $dbw->update( 'archive', 68 array( 'ar_user_text' => $newname ), 69 array( 'ar_user_text' => $oldname, 70 'ar_user' => $userID, 71 // No user,rev_id index, so use timestamp to bound 72 // the rows. This can use the user,timestamp index. 73 "ar_timestamp >= '$minTimestamp'", 74 "ar_timestamp <= '$maxTimestamp'" ), 75 __METHOD__ 76 ); 77 } 78 } 79 # Special case: revisions may be restored while renaming... 80 if ( $table == 'archive' && isset( $timestampColumn ) ) { 81 $actual = $dbw->affectedRows(); 82 # If some revisions were not renamed, they may have been restored. 83 # Do a pass on the revision table to get these straglers... 84 if ( $actual < $count ) { 85 $dbw->update( 'revision', 86 array( 'rev_user_text' => $newname ), 87 array( 'rev_user_text' => $oldname, 88 'rev_user' => $userID, 89 // No user,rev_id index, so use timestamp to bound 90 // the rows. This can use the user,timestamp index. 91 "rev_timestamp >= '$minTimestamp'", 92 "rev_timestamp <= '$maxTimestamp'" ), 93 __METHOD__ 94 ); 95 } 96 } 97 return true; 98 } 99 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 14:03:12 2014 | Cross-referenced by PHPXref 0.7.1 |