Code cleanup: normalize case for intval(), strval(), floatval() calls.
[lhc/web/wiklou.git] / maintenance / rebuildrecentchanges.inc
1 <?php
2 /**
3 * Rebuild recent changes table.
4 *
5 * @todo document
6 * @package MediaWiki
7 * @subpackage Maintenance
8 */
9
10 /** */
11 function rebuildRecentChangesTablePass1()
12 {
13 $fname = 'rebuildRecentChangesTablePass1';
14 $dbw =& wfGetDB( DB_MASTER );
15 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
16
17 $dbw->delete( 'recentchanges', '*' );
18
19 print( "Loading from CUR table...\n" );
20
21 $dbw->insertSelect( 'recentchanges', 'cur',
22 array(
23 'rc_timestamp' => 'cur_timestamp',
24 'rc_cur_time' => 'cur_timestamp',
25 'rc_user' => 'cur_user',
26 'rc_user_text' => 'cur_user_text',
27 'rc_namespace' => 'cur_namespace',
28 'rc_title' => 'cur_title',
29 'rc_comment' => 'cur_comment',
30 'rc_minor' => 'cur_minor_edit',
31 'rc_bot' => 0,
32 'rc_new' => 'cur_is_new',
33 'rc_cur_id' => 'cur_id',
34 'rc_this_oldid' => 0,
35 'rc_last_oldid' => 0,
36 'rc_type' => $dbw->conditional( 'cur_is_new != 0', RC_NEW, RC_EDIT ),
37 ), '*', $fname, array( 'ORDER BY' => 'cur_timestamp DESC', 'LIMIT' => 5000 )
38 );
39
40 print( "Loading from OLD table...\n" );
41
42 $sql = "INSERT INTO $recentchanges (rc_timestamp,rc_cur_time,rc_user," .
43 "rc_user_text,rc_namespace,rc_title,rc_comment,rc_minor,rc_bot,rc_new," .
44 "rc_cur_id,rc_this_oldid,rc_last_oldid,rc_type) SELECT old_timestamp,cur_timestamp," .
45 "old_user,old_user_text,old_namespace,old_title,old_comment," .
46 "old_minor_edit,0,0,cur_id,old_id,0,0 FROM $old,$cur " .
47 "WHERE old_namespace=cur_namespace AND old_title=cur_title ORDER BY old_timestamp DESC " .
48 "LIMIT 5000";
49 $dbw->query( $sql );
50
51 $sql = "SELECT rc_timestamp FROM $recentchanges " .
52 "ORDER BY rc_timestamp DESC";
53 $sql = $dbw->limitResult($sql, 1, 5000 );
54 $res = $dbw->query( $sql );
55 $obj = $dbw->fetchObject( $res );
56 if( $obj ) {
57 $ts = $obj->rc_timestamp;
58
59 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$ts}'";
60 $dbw->query( $sql );
61 }
62 }
63
64 function rebuildRecentChangesTablePass2()
65 {
66 $dbw =& wfGetDB( DB_MASTER );
67 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
68
69 $ns = $id = $count = 0;
70 $title = $ct = "";
71
72 print( "Updating links...\n" );
73
74 # Fill in the rc_last_oldid field, which points to the previous edit
75 #
76 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
77 "ORDER BY rc_cur_id,rc_timestamp";
78 $res = $dbw->query( $sql, DB_MASTER );
79
80 $lastCurId = 0;
81 $lastOldId = 0;
82 while ( $obj = $dbw->fetchObject( $res ) ) {
83 $new = 0;
84 if( $obj->rc_cur_id != $lastCurId ) {
85 # Switch! Look up the previous last edit, if any
86 $lastCurId = intval( $obj->rc_cur_id );
87 $emit = $obj->rc_timestamp;
88 $sql2 = "SELECT old_id FROM $old,$cur " .
89 "WHERE old_namespace=cur_namespace AND old_title=cur_title AND cur_id={$lastCurId} ".
90 "AND old_timestamp<'{$emit}' ORDER BY old_timestamp DESC LIMIT 1";
91 $res2 = $dbw->query( $sql2 );
92 if( $row = $dbw->fetchObject( $res2 ) ) {
93 $lastOldId = intval( $row->old_id );
94 } else {
95 # No previous edit
96 $lastOldId = 0;
97 $new = 1;
98 }
99 $dbw->freeResult( $res2 );
100 }
101 if( $lastCurId == 0 ) {
102 print "Uhhh, something wrong? No curid\n";
103 } else {
104 $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
105 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
106 $dbw->query( $sql3 );
107 $lastOldId = intval( $obj->rc_this_oldid );
108 }
109 }
110 $dbw->freeResult( $res );
111 }
112
113 ?>