r24197 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r24196‎ | r24197 | r24198 >
Date:14:45, 17 July 2007
Author:brion
Status:old
Tags:
Comment:
Could swear I committed this yesterday... move CU installer func out of a standalone script into an inc file so it doesn't creep me out to run it from an extension function
Modified paths:
  • /trunk/extensions/CheckUser/CheckUser.php (modified) (history)
  • /trunk/extensions/CheckUser/install.inc (added) (history)
  • /trunk/extensions/CheckUser/install.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CheckUser/CheckUser.php
@@ -161,12 +161,20 @@
162162 function efCheckUserSchemaUpdates() {
163163 global $wgDBtype, $wgExtNewIndexes;
164164
165 - # Run install.php
166 - require( dirname(__FILE__) . '/install.php' );
 165+ # Run install.inc as necessary
 166+ $base = dirname(__FILE__);
167167
 168+ $db = wfGetDB( DB_MASTER );
 169+ if( $db->tableExists( 'cu_changes' ) ) {
 170+ echo "...cu_changes already exists.\n";
 171+ } else {
 172+ require_once "$base/install.inc";
 173+ create_cu_changes( $db );
 174+ }
 175+
168176 if ($wgDBtype == 'mysql') {
169177 $wgExtNewIndexes[] = array('cu_changes',
170 - 'cuc_user_time', dirname(__FILE__) . '/archives/patch-cu_changes_indexes.sql');
 178+ 'cuc_user_time', "$base/archives/patch-cu_changes_indexes.sql" );
171179 }
172180 return true;
173181 }
Index: trunk/extensions/CheckUser/install.php
@@ -4,10 +4,9 @@
55 * Makes the required database changes for the CheckUser extension
66 */
77
8 -define( 'BATCH_SIZE', 100 );
 8+require_once dirname( __FILE__ ) . '/../../maintenance/commandLine.inc';
 9+require_once dirname( __FILE__ ) . '/install.inc';
910
10 -require_once( dirname( __FILE__ ) . '/../../maintenance/commandLine.inc' );
11 -
1211 $db =& wfGetDB( DB_MASTER );
1312 if ( $db->tableExists( 'cu_changes' ) && !isset( $options['force'] ) ) {
1413 echo "...cu_changes already exists.\n";
@@ -15,70 +14,3 @@
1615 $cutoff = isset( $options['cutoff'] ) ? wfTimestamp( TS_MW, $options['cutoff'] ) : null;
1716 create_cu_changes( $db, $cutoff );
1817 }
19 -
20 -function create_cu_changes( $db, $cutoff = null ) {
21 - global $wgDBtype;
22 - if( !$db->tableExists( 'cu_changes' ) ) {
23 - $sourcefile = $wgDBtype === 'postgres' ? '/cu_changes.pg.sql' : '/cu_changes.sql';
24 - $db->sourceFile( dirname( __FILE__ ) . $sourcefile );
25 - }
26 -
27 - echo "...cu_changes table added.\n";
28 - // Check if the table is empty
29 - $rcRows = $db->selectField( 'recentchanges', 'COUNT(*)', false, __FUNCTION__ );
30 - if ( !$rcRows ) {
31 - echo "recent_changes is empty; nothing to add.\n";
32 - exit( 1 );
33 - }
34 -
35 - if( $cutoff ) {
36 - // Something leftover... clear old entries to minimize dupes
37 - $encCutoff = $db->addQuotes( $db->timestamp( $cutoff ) );
38 - $db->delete( 'cu_changes',
39 - array( "cuc_timestamp < $encCutoff" ),
40 - __METHOD__ );
41 - $cutoffCond = "AND rc_timestamp < $encCutoff";
42 - } else {
43 - $cutoffCond = "";
44 - }
45 -
46 - $start = $db->selectField( 'recentchanges', 'MIN(rc_id)', false, __FUNCTION__ );
47 - $end = $db->selectField( 'recentchanges', 'MAX(rc_id)', false, __FUNCTION__ );
48 - $blockStart = $start;
49 - $blockEnd = $start + BATCH_SIZE - 1;
50 -
51 - $db->begin();
52 - while ( $blockStart <= $end ) {
53 - $cond = "rc_id BETWEEN $blockStart AND $blockEnd $cutoffCond";
54 - $res = $db->select( 'recentchanges', '*', $cond, __FUNCTION__ );
55 - $batch = array();
56 - while ( $row = $db->fetchObject( $res ) ) {
57 - $batch[] = array(
58 - 'cuc_timestamp' => $row->rc_timestamp,
59 - 'cuc_user' => $row->rc_user,
60 - 'cuc_user_text' => $row->rc_user_text,
61 - 'cuc_namespace' => $row->rc_namespace,
62 - 'cuc_title' => $row->rc_title,
63 - 'cuc_comment' => $row->rc_comment,
64 - 'cuc_minor' => $row->rc_minor,
65 - 'cuc_page_id' => $row->rc_cur_id,
66 - 'cuc_this_oldid' => $row->rc_this_oldid,
67 - 'cuc_last_oldid' => $row->rc_last_oldid,
68 - 'cuc_type' => $row->rc_type,
69 - 'cuc_ip' => $row->rc_ip,
70 - 'cuc_ip_hex' => IP::toHex( $row->rc_ip ),
71 - );
72 - }
73 - if ( count( $batch ) ) {
74 - $db->insert( 'cu_changes', $batch, __FUNCTION__ );
75 - }
76 - $blockStart += BATCH_SIZE;
77 - $blockEnd += BATCH_SIZE;
78 - wfWaitForSlaves( 5 );
79 - }
80 - $db->commit();
81 -
82 - echo "...cu_changes table added and populated.\n";
83 -}
84 -
85 -
Index: trunk/extensions/CheckUser/install.inc
@@ -0,0 +1,68 @@
 2+<?php
 3+
 4+define( 'BATCH_SIZE', 100 );
 5+
 6+function create_cu_changes( $db, $cutoff = null ) {
 7+ global $wgDBtype;
 8+ if( !$db->tableExists( 'cu_changes' ) ) {
 9+ $sourcefile = $wgDBtype === 'postgres' ? '/cu_changes.pg.sql' : '/cu_changes.sql';
 10+ $db->sourceFile( dirname( __FILE__ ) . $sourcefile );
 11+ }
 12+
 13+ echo "...cu_changes table added.\n";
 14+ // Check if the table is empty
 15+ $rcRows = $db->selectField( 'recentchanges', 'COUNT(*)', false, __FUNCTION__ );
 16+ if ( !$rcRows ) {
 17+ echo "recent_changes is empty; nothing to add.\n";
 18+ exit( 1 );
 19+ }
 20+
 21+ if( $cutoff ) {
 22+ // Something leftover... clear old entries to minimize dupes
 23+ $encCutoff = $db->addQuotes( $db->timestamp( $cutoff ) );
 24+ $db->delete( 'cu_changes',
 25+ array( "cuc_timestamp < $encCutoff" ),
 26+ __METHOD__ );
 27+ $cutoffCond = "AND rc_timestamp < $encCutoff";
 28+ } else {
 29+ $cutoffCond = "";
 30+ }
 31+
 32+ $start = $db->selectField( 'recentchanges', 'MIN(rc_id)', false, __FUNCTION__ );
 33+ $end = $db->selectField( 'recentchanges', 'MAX(rc_id)', false, __FUNCTION__ );
 34+ $blockStart = $start;
 35+ $blockEnd = $start + BATCH_SIZE - 1;
 36+
 37+ $db->begin();
 38+ while ( $blockStart <= $end ) {
 39+ $cond = "rc_id BETWEEN $blockStart AND $blockEnd $cutoffCond";
 40+ $res = $db->select( 'recentchanges', '*', $cond, __FUNCTION__ );
 41+ $batch = array();
 42+ while ( $row = $db->fetchObject( $res ) ) {
 43+ $batch[] = array(
 44+ 'cuc_timestamp' => $row->rc_timestamp,
 45+ 'cuc_user' => $row->rc_user,
 46+ 'cuc_user_text' => $row->rc_user_text,
 47+ 'cuc_namespace' => $row->rc_namespace,
 48+ 'cuc_title' => $row->rc_title,
 49+ 'cuc_comment' => $row->rc_comment,
 50+ 'cuc_minor' => $row->rc_minor,
 51+ 'cuc_page_id' => $row->rc_cur_id,
 52+ 'cuc_this_oldid' => $row->rc_this_oldid,
 53+ 'cuc_last_oldid' => $row->rc_last_oldid,
 54+ 'cuc_type' => $row->rc_type,
 55+ 'cuc_ip' => $row->rc_ip,
 56+ 'cuc_ip_hex' => IP::toHex( $row->rc_ip ),
 57+ );
 58+ }
 59+ if ( count( $batch ) ) {
 60+ $db->insert( 'cu_changes', $batch, __FUNCTION__ );
 61+ }
 62+ $blockStart += BATCH_SIZE;
 63+ $blockEnd += BATCH_SIZE;
 64+ wfWaitForSlaves( 5 );
 65+ }
 66+ $db->commit();
 67+
 68+ echo "...cu_changes table added and populated.\n";
 69+}
Property changes on: trunk/extensions/CheckUser/install.inc
___________________________________________________________________
Added: svn:eol-style
170 + native

Status & tagging log