Index: trunk/phase3/maintenance/updaters.inc |
— | — | @@ -13,6 +13,8 @@ |
14 | 14 | require_once 'convertLinks.inc'; |
15 | 15 | require_once 'userDupes.inc'; |
16 | 16 | require_once 'deleteDefaultMessages.php'; |
| 17 | +# Extension updates |
| 18 | +require_once( "$IP/includes/Hooks.php" ); |
17 | 19 | |
18 | 20 | $wgRenamedTables = array( |
19 | 21 | # from to patch file |
— | — | @@ -77,9 +79,15 @@ |
78 | 80 | array( 'revision', 'rev_parent_id', 'patch-rev_parent_id.sql' ), |
79 | 81 | array( 'page_restrictions', 'pr_id', 'patch-page_restrictions_sortkey.sql' ), |
80 | 82 | 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'), |
82 | 84 | ); |
83 | 85 | |
| 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 | + |
84 | 92 | function rename_table( $from, $to, $patch ) { |
85 | 93 | global $wgDatabase; |
86 | 94 | if ( $wgDatabase->tableExists( $from ) ) { |
— | — | @@ -97,18 +105,22 @@ |
98 | 106 | } |
99 | 107 | } |
100 | 108 | |
101 | | -function add_table( $name, $patch ) { |
| 109 | +function add_table( $name, $patch, $fullpath=false ) { |
102 | 110 | global $wgDatabase; |
103 | 111 | if ( $wgDatabase->tableExists( $name ) ) { |
104 | 112 | echo "...$name table already exists.\n"; |
105 | 113 | } else { |
106 | 114 | echo "Creating $name table..."; |
107 | | - dbsource( archive($patch), $wgDatabase ); |
| 115 | + if( $fullpath ) { |
| 116 | + dbsource( $patch, $wgDatabase ); |
| 117 | + } else { |
| 118 | + dbsource( archive($patch), $wgDatabase ); |
| 119 | + } |
108 | 120 | echo "ok\n"; |
109 | 121 | } |
110 | 122 | } |
111 | 123 | |
112 | | -function add_field( $table, $field, $patch ) { |
| 124 | +function add_field( $table, $field, $patch, $fullpath=false ) { |
113 | 125 | global $wgDatabase; |
114 | 126 | if ( !$wgDatabase->tableExists( $table ) ) { |
115 | 127 | echo "...$table table does not exist, skipping new field patch\n"; |
— | — | @@ -116,11 +128,30 @@ |
117 | 129 | echo "...have $field field in $table table.\n"; |
118 | 130 | } else { |
119 | 131 | 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 | + } |
121 | 137 | echo "ok\n"; |
122 | 138 | } |
123 | 139 | } |
124 | 140 | |
| 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 | + |
125 | 156 | function do_revision_updates() { |
126 | 157 | global $wgSoftwareRevision; |
127 | 158 | if ( $wgSoftwareRevision < 1001 ) { |
— | — | @@ -884,6 +915,8 @@ |
885 | 916 | function do_all_updates( $shared = false, $purge = true ) { |
886 | 917 | global $wgNewTables, $wgNewFields, $wgRenamedTables, $wgSharedDB, $wgDatabase, $wgDBtype, $IP; |
887 | 918 | |
| 919 | + wfRunHooks('LoadExtensionSchemaUpdates'); |
| 920 | + |
888 | 921 | $doUser = !$wgSharedDB || $shared; |
889 | 922 | |
890 | 923 | if ($wgDBtype === 'postgres') { |
— | — | @@ -909,6 +942,25 @@ |
910 | 943 | } |
911 | 944 | flush(); |
912 | 945 | } |
| 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 | + } |
913 | 965 | |
914 | 966 | # Do schema updates which require special handling |
915 | 967 | do_interwiki_update(); flush(); |
— | — | @@ -1415,6 +1467,37 @@ |
1416 | 1468 | } else |
1417 | 1469 | echo "... archive.ar_deleted already exists\n"; |
1418 | 1470 | |
| 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 | + |
1419 | 1502 | return; |
1420 | 1503 | } |
1421 | 1504 | |
Index: trunk/extensions/CheckUser/CheckUser.php |
— | — | @@ -38,6 +38,7 @@ |
39 | 39 | $wgHooks['RecentChange_save'][] = 'efUpdateCheckUserData'; |
40 | 40 | $wgHooks['ParserTestTables'][] = 'efCheckUserParserTestTables'; |
41 | 41 | $wgHooks['LoginAuthenticateAudit'][] = 'efCheckUserRecordLogin'; |
| 42 | +$wgHooks['LoadExtensionSchemaUpdates'][] = 'efCheckUserSchemaUpdates'; |
42 | 43 | |
43 | 44 | /** |
44 | 45 | * Hook function for RecentChange_save |
— | — | @@ -261,6 +262,25 @@ |
262 | 263 | return $name; |
263 | 264 | } |
264 | 265 | |
| 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 | + |
265 | 285 | /** |
266 | 286 | * Tell the parser test engine to create a stub cu_changes table, |
267 | 287 | * or temporary pages won't save correctly during the test run. |
Index: trunk/extensions/CheckUser/install.php |
— | — | @@ -10,23 +10,24 @@ |
11 | 11 | |
12 | 12 | $db =& wfGetDB( DB_MASTER ); |
13 | 13 | 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 ); |
16 | 18 | } |
17 | 19 | |
18 | | -$cutoff = isset( $options['cutoff'] ) ? wfTimestamp( TS_MW, $options['cutoff'] ) : null; |
19 | | -create_cu_changes( $db, $cutoff ); |
20 | | - |
21 | 20 | function create_cu_changes( $db, $cutoff = null ) { |
22 | 21 | global $wgDBtype; |
23 | 22 | if( !$db->tableExists( 'cu_changes' ) ) { |
24 | 23 | $sourcefile = $wgDBtype === 'postgres' ? '/cu_changes.pg.sql' : '/cu_changes.sql'; |
25 | 24 | $db->sourceFile( dirname( __FILE__ ) . $sourcefile ); |
26 | 25 | } |
| 26 | + |
| 27 | + echo "...cu_changes table added.\n"; |
27 | 28 | // Check if the table is empty |
28 | 29 | $rcRows = $db->selectField( 'recentchanges', 'COUNT(*)', false, __FUNCTION__ ); |
29 | 30 | if ( !$rcRows ) { |
30 | | - echo "recent_changes is empty; done\n"; |
| 31 | + echo "recent_changes is empty; nothing to add.\n"; |
31 | 32 | exit( 1 ); |
32 | 33 | } |
33 | 34 | |
— | — | @@ -76,6 +77,8 @@ |
77 | 78 | wfWaitForSlaves( 5 ); |
78 | 79 | } |
79 | 80 | $db->commit(); |
| 81 | + |
| 82 | + echo "...cu_changes table added and populated.\n"; |
80 | 83 | } |
81 | 84 | |
82 | 85 | |