Phpdoc comments and place holder. Part of the subpackage "maintenance", archives...
[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' => 'IF(cur_is_new,' . RC_NEW . ',' . RC_EDIT . ')'
37 ), '*', $fname, array( 'ORDER BY' => 'inverse_timestamp', '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) 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 FROM $old,$cur " .
47 "WHERE old_namespace=cur_namespace AND old_title=cur_title ORDER BY $old.inverse_timestamp " .
48 "LIMIT 5000";
49 $dbw->query( $sql );
50
51 $sql = "SELECT rc_timestamp FROM $recentchanges " .
52 "ORDER BY rc_timestamp DESC LIMIT 5000,1";
53 $res = $dbw->query( $sql );
54 $obj = $dbw->fetchObject( $res );
55 $ts = $obj->rc_timestamp;
56
57 $sql = "DELETE FROM $recentchanges WHERE rc_timestamp < '{$ts}'";
58 $dbw->query( $sql );
59 }
60
61 function rebuildRecentChangesTablePass2()
62 {
63 $dbw =& wfGetDB( DB_MASTER );
64 extract( $dbw->tableNames( 'recentchanges', 'cur', 'old' ) );
65
66 $ns = $id = $count = 0;
67 $title = $ct = "";
68
69 print( "Updating links...\n" );
70
71 # Fill in the rc_last_oldid field, which points to the previous edit
72 #
73 $sql = "SELECT rc_cur_id,rc_this_oldid,rc_timestamp FROM $recentchanges " .
74 "ORDER BY rc_cur_id,rc_timestamp";
75 $res = $dbw->query( $sql, DB_MASTER );
76
77 $lastCurId = 0;
78 $lastOldId = 0;
79 while ( $obj = $dbw->fetchObject( $res ) ) {
80 $new = 0;
81 if( $obj->rc_cur_id != $lastCurId ) {
82 # Switch! Look up the previous last edit, if any
83 $lastCurId = IntVal( $obj->rc_cur_id );
84 $emit = wfInvertTimestamp( $obj->rc_timestamp );
85 $sql2 = "SELECT old_id FROM $old,$cur " .
86 "WHERE old_namespace=cur_namespace AND old_title=cur_title AND cur_id={$lastCurId} ".
87 "AND $old.inverse_timestamp>'{$emit}' ORDER BY $old.inverse_timestamp LIMIT 1";
88 $res2 = $dbw->query( $sql2 );
89 if( $row = $dbw->fetchObject( $res2 ) ) {
90 $lastOldId = IntVal( $row->old_id );
91 } else {
92 # No previous edit
93 $lastOldId = 0;
94 $new = 1;
95 }
96 $dbw->freeResult( $res2 );
97 }
98 if( $lastCurId == 0 ) {
99 print "Uhhh, something wrong? No curid\n";
100 } else {
101 $sql3 = "UPDATE $recentchanges SET rc_last_oldid=$lastOldId,rc_new=$new,rc_type=$new " .
102 "WHERE rc_cur_id={$lastCurId} AND rc_this_oldid={$obj->rc_this_oldid}";
103 $dbw->query( $sql3 );
104 $lastOldId = IntVal( $obj->rc_this_oldid );
105 }
106 }
107 $dbw->freeResult( $res );
108 }
109
110 ?>