r23759 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r23758‎ | r23759 | r23760 >
Date:20:02, 5 July 2007
Author:aaron
Status:old
Tags:
Comment:
*Add extension schema change support
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/install.php (modified) (history)
  • /trunk/phase3/maintenance/updaters.inc (modified) (history)

Diff [purge]

Index: trunk/phase3/maintenance/updaters.inc
@@ -13,6 +13,8 @@
1414 require_once 'convertLinks.inc';
1515 require_once 'userDupes.inc';
1616 require_once 'deleteDefaultMessages.php';
 17+# Extension updates
 18+require_once( "$IP/includes/Hooks.php" );
1719
1820 $wgRenamedTables = array(
1921 # from to patch file
@@ -77,9 +79,15 @@
7880 array( 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ),
7981 array( 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ),
8082 array( 'ipblocks', 'ipb_block_email', 'patch-ipb_emailban.sql' ),
81 - array( 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql'),
 83+ array( 'oldimage', 'oi_metadata', 'patch-oi_metadata.sql'),
8284 );
8385
 86+# For extensions only, should be populated via hooks
 87+# $wgDBtype should be checked to specifiy the proper file
 88+$wgExtNewTables = array(); // table, dir
 89+$wgExtNewFields = array(); // table, column, dir
 90+$wgExtNewIndexes = array(); // table, index, dir
 91+
8492 function rename_table( $from, $to, $patch ) {
8593 global $wgDatabase;
8694 if ( $wgDatabase->tableExists( $from ) ) {
@@ -97,18 +105,22 @@
98106 }
99107 }
100108
101 -function add_table( $name, $patch ) {
 109+function add_table( $name, $patch, $fullpath=false ) {
102110 global $wgDatabase;
103111 if ( $wgDatabase->tableExists( $name ) ) {
104112 echo "...$name table already exists.\n";
105113 } else {
106114 echo "Creating $name table...";
107 - dbsource( archive($patch), $wgDatabase );
 115+ if( $fullpath ) {
 116+ dbsource( $patch, $wgDatabase );
 117+ } else {
 118+ dbsource( archive($patch), $wgDatabase );
 119+ }
108120 echo "ok\n";
109121 }
110122 }
111123
112 -function add_field( $table, $field, $patch ) {
 124+function add_field( $table, $field, $patch, $fullpath=false ) {
113125 global $wgDatabase;
114126 if ( !$wgDatabase->tableExists( $table ) ) {
115127 echo "...$table table does not exist, skipping new field patch\n";
@@ -116,11 +128,30 @@
117129 echo "...have $field field in $table table.\n";
118130 } else {
119131 echo "Adding $field field to table $table...";
120 - dbsource( archive($patch) , $wgDatabase );
 132+ if( $fullpath ) {
 133+ dbsource( $patch, $wgDatabase );
 134+ } else {
 135+ dbsource( archive($patch), $wgDatabase );
 136+ }
121137 echo "ok\n";
122138 }
123139 }
124140
 141+function add_index( $table, $index, $patch, $fullpath=false ) {
 142+ global $wgDatabase;
 143+ if( $wgDatabase->indexExists( $table, $index ) ) {
 144+ echo "...$index key already set.\n";
 145+ } else {
 146+ echo "Adding $index key... ";
 147+ if( $fullpath ) {
 148+ dbsource( $patch, $wgDatabase );
 149+ } else {
 150+ dbsource( archive($patch), $wgDatabase );
 151+ }
 152+ echo "ok\n";
 153+ }
 154+}
 155+
125156 function do_revision_updates() {
126157 global $wgSoftwareRevision;
127158 if ( $wgSoftwareRevision < 1001 ) {
@@ -884,6 +915,8 @@
885916 function do_all_updates( $shared = false, $purge = true ) {
886917 global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase, $wgDBtype, $IP;
887918
 919+ wfRunHooks('LoadExtensionSchemaUpdates');
 920+
888921 $doUser = !$wgSharedDB || $shared;
889922
890923 if ($wgDBtype === 'postgres') {
@@ -909,6 +942,25 @@
910943 }
911944 flush();
912945 }
 946+
 947+ global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes;
 948+ # Add missing extension tables
 949+ foreach ( $wgExtNewTables as $tableRecord ) {
 950+ add_table( $tableRecord[0], $tableRecord[1], true );
 951+ flush();
 952+ }
 953+ # Add missing extension fields
 954+ foreach ( $wgExtNewFields as $fieldRecord ) {
 955+ if ( $fieldRecord[0] != 'user' || $doUser ) {
 956+ add_field( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
 957+ }
 958+ flush();
 959+ }
 960+ # Add missing extension indexes
 961+ foreach ( $wgExtNewIndexes as $fieldRecord ) {
 962+ add_index( $fieldRecord[0], $fieldRecord[1], $fieldRecord[2], true );
 963+ flush();
 964+ }
913965
914966 # Do schema updates which require special handling
915967 do_interwiki_update(); flush();
@@ -1415,6 +1467,37 @@
14161468 } else
14171469 echo "... archive.ar_deleted already exists\n";
14181470
 1471+ global $wgExtNewTables, $wgExtNewFields, $wgExtNewIndexes;
 1472+ # Add missing extension tables
 1473+ foreach ( $wgExtNewTables as $nt ) {
 1474+ if ($wgDatabase->tableExists($nt[0])) {
 1475+ echo "... table $nt[0] already exists\n";
 1476+ continue;
 1477+ }
 1478+
 1479+ echo "... create table $nt[0]\n";
 1480+ dbsource($nt[1]);
 1481+ }
 1482+ # Add missing extension fields
 1483+ foreach ( $wgExtNewFields as $nc ) {
 1484+ $fi = $wgDatabase->fieldInfo($nc[0], $nc[1]);
 1485+ if (!is_null($fi)) {
 1486+ echo "... column $nc[0].$nc[1] already exists\n";
 1487+ continue;
 1488+ }
 1489+
 1490+ echo "... add column $nc[0].$nc[1]\n";
 1491+ $wgDatabase->query("ALTER TABLE $nc[0] ADD $nc[1] $nc[2]");
 1492+ }
 1493+ # Add missing extension indexes
 1494+ foreach ( $wgExtNewIndexes as $ni ) {
 1495+ if (pg_index_exists($ni[0], $ni[1])) {
 1496+ echo "... index $ni[1] on $ni[0] already exists\n";
 1497+ continue;
 1498+ }
 1499+ dbsource($ni[2]);
 1500+ }
 1501+
14191502 return;
14201503 }
14211504
Index: trunk/extensions/CheckUser/CheckUser.php
@@ -38,6 +38,7 @@
3939 $wgHooks['RecentChange_save'][] = 'efUpdateCheckUserData';
4040 $wgHooks['ParserTestTables'][] = 'efCheckUserParserTestTables';
4141 $wgHooks['LoginAuthenticateAudit'][] = 'efCheckUserRecordLogin';
 42+$wgHooks['LoadExtensionSchemaUpdates'][] = 'efCheckUserSchemaUpdates';
4243
4344 /**
4445 * Hook function for RecentChange_save
@@ -261,6 +262,25 @@
262263 return $name;
263264 }
264265
 266+function efCheckUserSchemaUpdates() {
 267+ global $wgDBtype, $wgExtNewFields, $wgExtNewIndexes;
 268+
 269+ # Run install.php
 270+ require( dirname(__FILE__) . '/install.php' );
 271+
 272+ # FIXME: do postgres index changes!
 273+ if ($wgDBtype == 'mysql') {
 274+ $wgExtNewFields[] = array('cu_changes',
 275+ 'cuc_cookie_user', dirname(__FILE__) . '/Archives/patch-cuc_cookie_user.sql');
 276+ $wgExtNewIndexes[] = array('cu_changes',
 277+ 'cuc_user_time', dirname(__FILE__) . '/Archives/patch-cu_changes_indexes.sql');
 278+ } else {
 279+ $wgExtNewFields[] = array('cu_changes',
 280+ 'cuc_cookie_user', dirname(__FILE__) . 'TEXT');
 281+ }
 282+ return true;
 283+}
 284+
265285 /**
266286 * Tell the parser test engine to create a stub cu_changes table,
267287 * or temporary pages won't save correctly during the test run.
Index: trunk/extensions/CheckUser/install.php
@@ -10,23 +10,24 @@
1111
1212 $db =& wfGetDB( DB_MASTER );
1313 if ( $db->tableExists( 'cu_changes' ) && !isset( $options['force'] ) ) {
14 - echo "cu_changes already exists\n";
15 - exit( 1 );
 14+ echo "...cu_changes already exists.\n";
 15+} else {
 16+ $cutoff = isset( $options['cutoff'] ) ? wfTimestamp( TS_MW, $options['cutoff'] ) : null;
 17+ create_cu_changes( $db, $cutoff );
1618 }
1719
18 -$cutoff = isset( $options['cutoff'] ) ? wfTimestamp( TS_MW, $options['cutoff'] ) : null;
19 -create_cu_changes( $db, $cutoff );
20 -
2120 function create_cu_changes( $db, $cutoff = null ) {
2221 global $wgDBtype;
2322 if( !$db->tableExists( 'cu_changes' ) ) {
2423 $sourcefile = $wgDBtype === 'postgres' ? '/cu_changes.pg.sql' : '/cu_changes.sql';
2524 $db->sourceFile( dirname( __FILE__ ) . $sourcefile );
2625 }
 26+
 27+ echo "...cu_changes table added.\n";
2728 // Check if the table is empty
2829 $rcRows = $db->selectField( 'recentchanges', 'COUNT(*)', false, __FUNCTION__ );
2930 if ( !$rcRows ) {
30 - echo "recent_changes is empty; done\n";
 31+ echo "recent_changes is empty; nothing to add.\n";
3132 exit( 1 );
3233 }
3334
@@ -76,6 +77,8 @@
7778 wfWaitForSlaves( 5 );
7879 }
7980 $db->commit();
 81+
 82+ echo "...cu_changes table added and populated.\n";
8083 }
8184
8285

Follow-up revisions

RevisionCommit summaryAuthorDate
r23912Merged revisions 23662-23909 via svnmerge from...david18:11, 9 July 2007

Status & tagging log