r99511 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r99510‎ | r99511 | r99512 >
Date:18:03, 11 October 2011
Author:wikinaut
Status:deferred
Tags:
Comment:
follow-up r97447 . removed redundant updater code which duplicated core logic; now using addExtensionUpdate, dropIndex and addIndex; adding two small sql patch files which are only needed when old database field index needs changes; harmonizing the patch file names. Relies on r99510 wherein addIndex and dropIndex were changed from protected to public functions as suggested by \^demon
Modified paths:
  • /trunk/extensions/OpenID/OpenID.hooks.php (modified) (history)
  • /trunk/extensions/OpenID/OpenID.php (modified) (history)
  • /trunk/extensions/OpenID/README.OpenID-mediawiki-extension (modified) (history)
  • /trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql (added) (history)
  • /trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql (added) (history)
  • /trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql (added) (history)
  • /trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql (deleted) (history)

Diff [purge]

Index: trunk/extensions/OpenID/README.OpenID-mediawiki-extension
@@ -1,5 +1,5 @@
22 MediaWiki OpenID extension README.OpenID-mediawiki-extension file
3 -version 0.939-beta 20110922
 3+version 0.940-beta 20111011
44
55 Homepage and manual http://www.mediawiki.org/wiki/Extension:OpenID
66
@@ -467,6 +467,7 @@
468468 into that account now
469469
470470 == CHANGES ==
 471+* 0.940 changed database schema updater; tested for MySQL
471472 * 0.939 function name changes
472473 * 0.938 list uoi_user_registration timestamp if present in openid-preference tab
473474 * 0.937 added uoi_user_registration timestamp field (bug30623)
Index: trunk/extensions/OpenID/OpenID.hooks.php
@@ -323,66 +323,55 @@
324324 }
325325
326326 public static function onLoadExtensionSchemaUpdates( $updater = null ) {
327 - $base = dirname( __FILE__ ) . '/patches';
328 - if ( $updater === null ) { // < 1.17
329 - global $wgDBtype, $wgUpdates, $wgExtNewTables;
330 - if ( $wgDBtype == 'mysql' ) {
331 - $wgExtNewTables[] = array( 'user_openid', "$base/openid_table.sql" );
332 - $wgUpdates['mysql'][] = array( array( __CLASS__, 'makeUoiUserNotUnique' ) );
333 - $wgUpdates['mysql'][] = array( array( __CLASS__, 'addUoiUserRegistration' ) );
334 - } elseif ( $wgDBtype == 'postgres' ) {
335 - $wgExtNewTables[] = array( 'user_openid', "$base/openid_table.pg.sql" );
336 - # This doesn't work since MediaWiki doesn't use $wgUpdates when
337 - # updating a PostgreSQL database
338 - # $wgUpdates['postgres'][] = array( array( __CLASS__, 'makeUoiUserNotUnique' ) );
339 - }
340 - } else {
341 - $dbPatch = "$base/" . ( $updater->getDB()->getType() == 'postgres' ?
342 - 'openid_table.pg.sql' : 'openid_table.sql' );
343 - $updater->addExtensionUpdate( array( 'addTable', 'user_openid', $dbPatch, true ) );
344 - if ( $updater->getDB()->getType() == 'mysql' ) {
345 - $updater->addExtensionUpdate( array( array( __CLASS__, 'makeUoiUserNotUnique' ) ) );
346 - $updater->addExtensionUpdate( array( array( __CLASS__, 'addUoiUserRegistration' ) ) );
347 - }
348 - }
349 -
350 - return true;
351 - }
352 -
353 - public static function makeUoiUserNotUnique( $updater = null ) {
354327 if ( $updater === null ) {
355 - $db = wfGetDB( DB_MASTER );
356 - } else {
357 - $db = $updater->getDB();
358 - }
359 - if ( !$db->tableExists( 'user_openid' ) )
360 - return;
 328+ // <= 1.16 support - but OpenID does not work with such old MW versions
 329+ global $wgExtNewTables, $wgExtNewFields;
 330+ $wgExtNewTables[] = array(
 331+ 'user_openid',
 332+ dirname( __FILE__ ) . '/patches/openid_table.sql'
 333+ );
361334
362 - $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
363 - if ( !$info->isMultipleKey() ) {
364 - echo( "Making uoi_user field not unique..." );
365 - $db->sourceFile( dirname( __FILE__ ) . '/patches/patch-uoi_user-not-unique.sql' );
366 - echo( " done.\n" );
367 - } else {
368 - echo( "...uoi_user field is already not unique.\n" );
369 - }
370 - }
371 - public static function addUoiUserRegistration( $updater = null ) {
372 - if ( $updater === null ) {
 335+ # if index of older OpenID version is unique then upgrade and make index non unique
373336 $db = wfGetDB( DB_MASTER );
 337+ $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
 338+ if ( !$info->isMultipleKey() ) {
 339+ echo( "Making uoi_user field non UNIQUE...\n" );
 340+ $db->sourceFile( dirname( __FILE__ ) . '/patches/patch-uoi_user-not-unique.sql' );
 341+ echo( " done.\n" );
 342+ } else {
 343+ echo( "...uoi_user field is already non UNIQUE.\n" );
 344+ }
 345+
 346+ # uoi_user_registration field was added in OpenID version 0.937
 347+ $wgExtNewFields[] = array(
 348+ 'user_openid',
 349+ 'uoi_user_registration',
 350+ dirname( __FILE__ ) . '/patches/patch-add_uoi_user_registration.sql'
 351+ );
374352 } else {
 353+ // >= 1.17 support
 354+ $updater->addExtensionUpdate( array( 'addTable', 'user_openid',
 355+ dirname( __FILE__ ) . '/patches/openid_table.sql', true ) );
 356+
 357+ # if index of older OpenID version is unique then upgrade and make index non unique
375358 $db = $updater->getDB();
 359+ $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
 360+ if ( !$info->isMultipleKey() ) {
 361+ echo( "Making uoi_user field non UNIQUE...\n" );
 362+ $updater->dropIndex( 'user_openid', 'uoi_user',
 363+ dirname( __FILE__ ) . '/patches/patch-drop_non_multiple_key_index_uoi_user.sql', true );
 364+ $updater->addIndex( 'user_openid', 'user_openid_user',
 365+ dirname( __FILE__ ) . '/patches/patch-add_multiple_key_index_user_openid_user.sql', true );
 366+ echo( "...done.\n" );
 367+ } else {
 368+ echo( "...uoi_user field is already non UNIQUE.\n" );
 369+ }
 370+
 371+ # uoi_user_registration field was added in OpenID version 0.937
 372+ $updater->addExtensionUpdate( array( 'addField', 'user_openid', 'uoi_user_registration',
 373+ dirname( __FILE__ ) . '/patches/patch-add_uoi_user_registration.sql', true ) );
376374 }
377 - if ( !$db->tableExists( 'user_openid' ) )
378 - return;
379 -
380 - if ( !$db->fieldExists( 'user_openid', 'uoi_user_registration' ) ) {
381 - echo( "Adding uoi_user_registration field..." );
382 - $db->sourceFile( dirname( __FILE__ ) . '/patches/patch-uoi_user_registration-not-present.sql' );
383 - echo( " done.\n" );
384 - } else {
385 - echo( "...uoi_user_registration field present.\n" );
386 - }
 375+ return true;
387376 }
388377
389378 private static function loginStyle() {
Index: trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql
@@ -1,4 +0,0 @@
2 -ALTER TABLE /*_*/user_openid ADD uoi_user_registration BINARY(14);
Index: trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
@@ -0,0 +1,5 @@
 2+--
 3+-- SQL schema update for OpenID extension to add a non unique uoi_user index
 4+--
 5+
 6+CREATE INDEX /*i*/user_openid_user ON /*_*/user_openid(uoi_user);
Property changes on: trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
___________________________________________________________________
Added: svn:eol-style
17 + native
Index: trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql
@@ -0,0 +1,4 @@
 2+--
 3+-- SQL schema update for OpenID extension to add the uoi_user_registration field
 4+--
 5+ALTER TABLE /*_*/user_openid ADD uoi_user_registration BINARY(14);
Property changes on: trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql
___________________________________________________________________
Added: svn:eol-style
16 + native
Index: trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql
@@ -0,0 +1,5 @@
 2+--
 3+-- SQL schema update for OpenID extension to drop uoi_user field because it is unique
 4+--
 5+
 6+ALTER TABLE /*_*/user_openid DROP INDEX uoi_user;
Property changes on: trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql
___________________________________________________________________
Added: svn:eol-style
17 + native
Index: trunk/extensions/OpenID/OpenID.php
@@ -27,7 +27,7 @@
2828 exit( 1 );
2929 }
3030
31 -define( 'MEDIAWIKI_OPENID_VERSION', '0.939-beta 20110922' );
 31+define( 'MEDIAWIKI_OPENID_VERSION', '0.940-beta 20111011' );
3232
3333 $path = dirname( __FILE__ );
3434 set_include_path( implode( PATH_SEPARATOR, array( $path ) ) . PATH_SEPARATOR . get_include_path() );

Follow-up revisions

RevisionCommit summaryAuthorDate
r99529follow-up r99511 r97447 and not using dropIndex and addIndex directly any mor...wikinaut18:39, 11 October 2011

Past revisions this follows-up on

RevisionCommit summaryAuthorDate
r97447v0.937 added uoi_user_registration timestamp when a new OpenID identity is ad...wikinaut23:55, 18 September 2011
r99510chg protected to public function addIndex and dropIndex . This is i.a. needed...wikinaut17:52, 11 October 2011

Status & tagging log