r107830 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r107829‎ | r107830 | r107831 >
Date:13:27, 2 January 2012
Author:amire80
Status:resolved (Comments)
Tags:
Comment:
Preferences update script for Bug 31917.
Modified paths:
  • /trunk/extensions/Narayam/maintenance (added) (history)
  • /trunk/extensions/Narayam/maintenance/FixNarayamDisablePref.php (added) (history)

Diff [purge]

Index: trunk/extensions/Narayam/maintenance/FixNarayamDisablePref.php
@@ -0,0 +1,57 @@
 2+<?php
 3+
 4+// Standard boilerplate to define $IP
 5+if ( getenv( 'MW_INSTALL_PATH' ) !== false ) {
 6+ $IP = getenv( 'MW_INSTALL_PATH' );
 7+} else {
 8+ $dir = dirname( __FILE__ ); $IP = "$dir/../../..";
 9+}
 10+require_once( "$IP/maintenance/Maintenance.php" );
 11+
 12+class FixNarayamDisablePref extends Maintenance {
 13+ function __construct() {
 14+ parent::__construct();
 15+ }
 16+
 17+ function execute() {
 18+ $dbw = wfGetDB( DB_MASTER );
 19+
 20+ $table = 'user_properties';
 21+ $oldPropName = 'narayamDisable';
 22+ $newPropName = 'narayamEnable';
 23+ echo "Fixing $oldPropName to $newPropName\n";
 24+
 25+ $batchSize = 100;
 26+ $allIds = array();
 27+ while ( true ) {
 28+ $dbw->begin();
 29+ $res = $dbw->select(
 30+ $table,
 31+ array( 'up_user' ),
 32+ array( 'up_property' => $oldPropName, 'up_value' => 1 ),
 33+ __METHOD__,
 34+ array( 'LIMIT' => $batchSize, 'FOR UPDATE' ) );
 35+ if ( !$res->numRows() ) {
 36+ $dbw->commit();
 37+ break;
 38+ }
 39+
 40+ $ids = array();
 41+ foreach ( $res as $row ) {
 42+ $ids[] = $row->up_user;
 43+ }
 44+ $dbw->update(
 45+ $table,
 46+ array( 'up_property' => $newPropName, 'up_value' => 0 ),
 47+ array( 'up_property' => $oldPropName, 'up_user' => $ids ),
 48+ __METHOD__ );
 49+
 50+ wfWaitForSlaves( 10 );
 51+ }
 52+
 53+ echo "Done\n";
 54+ }
 55+}
 56+
 57+$maintClass = 'FixNarayamDisablePref';
 58+require_once( RUN_MAINTENANCE_IF_MAIN );
Property changes on: trunk/extensions/Narayam/maintenance/FixNarayamDisablePref.php
___________________________________________________________________
Added: svn:eol-style
159 + native

Sign-offs

UserFlagDate
Nikerabbitinspected18:16, 2 January 2012

Follow-up revisions

RevisionCommit summaryAuthorDate
r107852Rollow up to r107830. Replacing echo with $this->output() and adding setBatch...amire8021:35, 2 January 2012
r107866Follow up to r107830 - adding commit after update.amire8008:46, 3 January 2012

Comments

#Comment by 😂 (talk | contribs)   15:07, 2 January 2012
  • Use setBatchSize( 100 ) in the constructor so users can specify --batch-size. This will set $this->mBatchSize for you to use.
  • Don't use echo, use the output or error functions as appropriate.
#Comment by Amire80 (talk | contribs)   21:35, 2 January 2012

Addressed in r107852.

#Comment by Siebrand (talk | contribs)   08:29, 3 January 2012

Feedback by TimStarling on IRC: You should commit the transaction after the $dbw->update() before the wfWaitForSlaves. Other than that, it should work.

#Comment by Amire80 (talk | contribs)   08:48, 3 January 2012

Addressed in r107866 and r107867.

Status & tagging log