http://www.mediawiki.org/wiki/Special:Code/MediaWiki/99511

Revision: 99511
Author:   wikinaut
Date:     2011-10-11 18:03:35 +0000 (Tue, 11 Oct 2011)
Log Message:
-----------
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
    trunk/extensions/OpenID/OpenID.php
    trunk/extensions/OpenID/README.OpenID-mediawiki-extension

Added Paths:
-----------
    
trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
    trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql
    
trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql

Removed Paths:
-------------
    trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql

Modified: trunk/extensions/OpenID/OpenID.hooks.php
===================================================================
--- trunk/extensions/OpenID/OpenID.hooks.php    2011-10-11 17:52:38 UTC (rev 
99510)
+++ trunk/extensions/OpenID/OpenID.hooks.php    2011-10-11 18:03:35 UTC (rev 
99511)
@@ -323,66 +323,55 @@
        }
 
        public static function onLoadExtensionSchemaUpdates( $updater = null ) {
-               $base = dirname( __FILE__ ) . '/patches';
-               if ( $updater === null ) { // < 1.17
-                       global $wgDBtype, $wgUpdates, $wgExtNewTables;
-                       if ( $wgDBtype == 'mysql' ) {
-                               $wgExtNewTables[] = array( 'user_openid', 
"$base/openid_table.sql" );
-                               $wgUpdates['mysql'][] = array( array( 
__CLASS__, 'makeUoiUserNotUnique' ) );
-                               $wgUpdates['mysql'][] = array( array( 
__CLASS__, 'addUoiUserRegistration' ) );
-                       } elseif ( $wgDBtype == 'postgres' ) {
-                               $wgExtNewTables[] = array( 'user_openid', 
"$base/openid_table.pg.sql" );
-                               # This doesn't work since MediaWiki doesn't use 
$wgUpdates when
-                               # updating a PostgreSQL database
-                               # $wgUpdates['postgres'][] = array( array( 
__CLASS__, 'makeUoiUserNotUnique' ) );
-                       }
-               } else {
-                       $dbPatch = "$base/" . ( $updater->getDB()->getType() == 
'postgres' ?
-                               'openid_table.pg.sql' : 'openid_table.sql' );
-                       $updater->addExtensionUpdate( array( 'addTable', 
'user_openid', $dbPatch, true ) );
-                       if ( $updater->getDB()->getType() == 'mysql' ) {
-                               $updater->addExtensionUpdate( array( array( 
__CLASS__, 'makeUoiUserNotUnique' ) ) );
-                               $updater->addExtensionUpdate( array( array( 
__CLASS__, 'addUoiUserRegistration' ) ) );
-                       }
-               }
-
-               return true;
-       }
-
-       public static function makeUoiUserNotUnique( $updater = null ) {
                if ( $updater === null ) {
-                       $db = wfGetDB( DB_MASTER );
-               } else {
-                       $db = $updater->getDB();
-               }
-               if ( !$db->tableExists( 'user_openid' ) )
-                       return;
+                       // <= 1.16 support - but OpenID does not work with such 
old MW versions
+                       global $wgExtNewTables, $wgExtNewFields;
+                       $wgExtNewTables[] = array(
+                               'user_openid',
+                               dirname( __FILE__ ) . 
'/patches/openid_table.sql'
+                       );
 
-               $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
-               if ( !$info->isMultipleKey() ) {
-                       echo( "Making uoi_user field not unique..." );
-                       $db->sourceFile( dirname( __FILE__ ) . 
'/patches/patch-uoi_user-not-unique.sql' );
-                       echo( " done.\n" );
-               } else {
-                       echo( "...uoi_user field is already not unique.\n" );
-               }
-       }
-       public static function addUoiUserRegistration( $updater = null ) {
-               if ( $updater === null ) {
+                       # if index of older OpenID version is unique then 
upgrade and make index non unique
                        $db = wfGetDB( DB_MASTER );
+                       $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
+                       if ( !$info->isMultipleKey() ) {
+                               echo( "Making uoi_user field non UNIQUE...\n" );
+                               $db->sourceFile( dirname( __FILE__ ) . 
'/patches/patch-uoi_user-not-unique.sql' );
+                               echo( " done.\n" );
+                       } else {
+                               echo( "...uoi_user field is already non 
UNIQUE.\n" );
+                       }
+                       
+                       # uoi_user_registration field was added in OpenID 
version 0.937
+                       $wgExtNewFields[] = array(
+                               'user_openid',
+                               'uoi_user_registration',
+                               dirname( __FILE__ ) . 
'/patches/patch-add_uoi_user_registration.sql'
+                       );
                } else {
+                       // >= 1.17 support
+                       $updater->addExtensionUpdate( array( 'addTable', 
'user_openid',
+                               dirname( __FILE__ ) . 
'/patches/openid_table.sql', true ) );
+
+                       # if index of older OpenID version is unique then 
upgrade and make index non unique
                        $db = $updater->getDB();
+                       $info = $db->fieldInfo( 'user_openid', 'uoi_user' );
+                       if ( !$info->isMultipleKey() ) {
+                               echo( "Making uoi_user field non UNIQUE...\n" );
+                               $updater->dropIndex( 'user_openid', 'uoi_user',
+                                       dirname( __FILE__ ) . 
'/patches/patch-drop_non_multiple_key_index_uoi_user.sql', true );
+                               $updater->addIndex( 'user_openid', 
'user_openid_user',
+                                       dirname( __FILE__ ) . 
'/patches/patch-add_multiple_key_index_user_openid_user.sql', true );
+                               echo( "...done.\n" );
+                       } else {
+                               echo( "...uoi_user field is already non 
UNIQUE.\n" );
+                       }
+                       
+                       # uoi_user_registration field was added in OpenID 
version 0.937
+                       $updater->addExtensionUpdate( array( 'addField', 
'user_openid', 'uoi_user_registration',
+                               dirname( __FILE__ ) . 
'/patches/patch-add_uoi_user_registration.sql', true ) );                 
                }
-               if ( !$db->tableExists( 'user_openid' ) )
-                       return;
-
-               if ( !$db->fieldExists( 'user_openid', 'uoi_user_registration' 
) ) {
-                       echo( "Adding uoi_user_registration field..." );
-                       $db->sourceFile( dirname( __FILE__ ) . 
'/patches/patch-uoi_user_registration-not-present.sql' );
-                       echo( " done.\n" );
-               } else {
-                       echo( "...uoi_user_registration field present.\n" );
-               }
+               return true;
        }
 
        private static function loginStyle() {

Modified: trunk/extensions/OpenID/OpenID.php
===================================================================
--- trunk/extensions/OpenID/OpenID.php  2011-10-11 17:52:38 UTC (rev 99510)
+++ trunk/extensions/OpenID/OpenID.php  2011-10-11 18:03:35 UTC (rev 99511)
@@ -27,7 +27,7 @@
        exit( 1 );
 }
 
-define( 'MEDIAWIKI_OPENID_VERSION', '0.939-beta 20110922' );
+define( 'MEDIAWIKI_OPENID_VERSION', '0.940-beta 20111011' );
 
 $path = dirname( __FILE__ );
 set_include_path( implode( PATH_SEPARATOR, array( $path ) ) . PATH_SEPARATOR . 
get_include_path() );

Modified: trunk/extensions/OpenID/README.OpenID-mediawiki-extension
===================================================================
--- trunk/extensions/OpenID/README.OpenID-mediawiki-extension   2011-10-11 
17:52:38 UTC (rev 99510)
+++ trunk/extensions/OpenID/README.OpenID-mediawiki-extension   2011-10-11 
18:03:35 UTC (rev 99511)
@@ -1,5 +1,5 @@
 MediaWiki OpenID extension README.OpenID-mediawiki-extension file
-version 0.939-beta 20110922
+version 0.940-beta 20111011
 
 Homepage and manual http://www.mediawiki.org/wiki/Extension:OpenID
 
@@ -467,6 +467,7 @@
   into that account now
 
 == CHANGES ==
+* 0.940 changed database schema updater; tested for MySQL
 * 0.939 function name changes
 * 0.938 list uoi_user_registration timestamp if present in openid-preference 
tab
 * 0.937 added uoi_user_registration timestamp field (bug30623)

Added: 
trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
===================================================================
--- 
trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
                           (rev 0)
+++ 
trunk/extensions/OpenID/patches/patch-add_multiple_key_index_user_openid_user.sql
   2011-10-11 18:03:35 UTC (rev 99511)
@@ -0,0 +1,5 @@
+--
+-- SQL schema update for OpenID extension to add a non unique uoi_user index
+--
+
+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
   + native

Added: trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql
===================================================================
--- trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql         
                (rev 0)
+++ trunk/extensions/OpenID/patches/patch-add_uoi_user_registration.sql 
2011-10-11 18:03:35 UTC (rev 99511)
@@ -0,0 +1,4 @@
+--
+-- SQL schema update for OpenID extension to add the uoi_user_registration 
field
+--
+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
   + native

Added: 
trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql
===================================================================
--- 
trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql  
                            (rev 0)
+++ 
trunk/extensions/OpenID/patches/patch-drop_non_multiple_key_index_uoi_user.sql  
    2011-10-11 18:03:35 UTC (rev 99511)
@@ -0,0 +1,5 @@
+--
+-- SQL schema update for OpenID extension to drop uoi_user field because it is 
unique
+--
+
+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
   + native

Deleted: 
trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql
===================================================================
--- trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql 
2011-10-11 17:52:38 UTC (rev 99510)
+++ trunk/extensions/OpenID/patches/patch-uoi_user_registration-not-present.sql 
2011-10-11 18:03:35 UTC (rev 99511)
@@ -1,4 +0,0 @@
---
--- SQL schema update for OpenID extension to add the uoi_user_registration 
field
---
-ALTER TABLE /*_*/user_openid ADD uoi_user_registration BINARY(14);


_______________________________________________
MediaWiki-CVS mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs

Reply via email to