r89377 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r89376‎ | r89377 | r89378 >
Date:02:05, 3 June 2011
Author:demon
Status:deferred (Comments)
Tags:
Comment:
* Rewrite optionToTable to be like a modern maintenance script
** Since we rely on pref rewrite per r89371, don't check for user_options, just user_properties
Modified paths:
  • /trunk/extensions/OpenID/optionToTable.php (modified) (history)

Diff [purge]

Index: trunk/extensions/OpenID/optionToTable.php
@@ -23,28 +23,40 @@
2424 * @ingroup Extensions
2525 */
2626
27 -require_once( 'commandLine.inc' );
28 -ini_set( "include_path", "/usr/share/php:" . ini_get( "include_path" ) );
29 -
30 -require_once( "$IP/extensions/OpenID/Consumer.php" );
31 -
32 -global $wgSharedDB, $wgDBprefix;
33 -$tableName = "${wgDBprefix}user_openid";
34 -if ( isset( $wgSharedDB ) ) {
35 - $tableName = "`$wgSharedDB`.$tableName";
 27+$IP = getenv( 'MW_INSTALL_PATH' );
 28+if ( $IP === false ) {
 29+ $IP = dirname( __FILE__ ) . '/../..';
3630 }
 31+require( "$IP/maintenance/Maintenance.php" );
3732
38 -$dbr = wfGetDB( DB_SLAVE );
 33+class OpenIDOptionToTable extends Maintenance {
 34+ public function __construct() {
 35+ parent::__construct();
 36+ $this->mDescription = 'Convert user_option-stored urls to the new openID table';
 37+ }
3938
40 -$res = $dbr->select( array( 'user' ),
41 - array( 'user_name' ),
42 - array( 'user_options LIKE "%openid_url%"' ),
43 - 'optionToTable',
44 - array( 'ORDER BY' => 'user_name' ) );
 39+ public function execute() {
 40+ $dbr = wfGetDB( DB_SLAVE );
 41+ if( !$dbr->tableExists( 'user_properties' ) ) {
 42+ $this->error( "The OpenID extension requires at least MediaWiki 1.16.", true );
 43+ }
4544
46 -while ( $res && $row = $dbr->fetchObject( $res ) ) {
47 - $user = User::newFromName( $row->user_name );
48 - print( $user->getName() . ": " . $user->getOption( 'openid_url' ) . "\n" );
49 - OpenIDSetUserUrl( $user, $user->getOption( 'openid_url' ) );
 45+ $this->output( "Checking for legacy user_property rows..." );
 46+ $dbr = wfGetDB( DB_SLAVE );
 47+ $res = $dbr->select( array( 'user_properties' ), array( 'up_user' ),
 48+ array( 'up_property' => 'openid_url' ), __METHOD__ );
 49+ if( $dbr->numRows( $res ) ) {
 50+ foreach( $res as $row ) {
 51+ $user = User::newFromId( $row->up_user );
 52+ $this->output( "\n\tFixing {$user->getName()}" );
 53+ SpecialOpenID::addUserUrl( $user, $user->getOption( 'openid_url' ) );
 54+ }
 55+ $this->output( "done\n" );
 56+ } else {
 57+ $this->output( "none found\n" );
 58+ }
 59+ }
5060 }
51 -$dbr->freeResult( $res );
 61+
 62+$maintClass = 'OpenIDOptionToTable';
 63+require_once( RUN_MAINTENANCE_IF_MAIN );

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r89371Various OpenID cleanups (did them as I went)...demon23:49, 2 June 2011

Comments

#Comment by 😂 (talk | contribs)   01:21, 8 June 2011

Please don't defer OpenID.

#Comment by 😂 (talk | contribs)   17:48, 21 July 2011

I said don't defer OpenID. Can you not read?

#Comment by Aaron Schulz (talk | contribs)   17:49, 21 July 2011

Probably was deferred from a code revision list so the person didn't see the comment here.

Status & tagging log