4 * Makes the required database updates for rev_parent_id
5 * to be of any use. It can be used for some simple tracking
6 * and to find new page edits by users.
9 define( 'BATCH_SIZE', 500 );
11 require_once 'commandLine.inc';
13 $db =& wfGetDB( DB_MASTER
);
14 if ( !$db->tableExists( 'revision' ) ) {
15 echo "revision table does not exist\n";
19 populate_rev_parent_id( $db );
21 function populate_rev_parent_id( $db ) {
22 echo "Populating rev_parent_id column\n";
23 $start = $db->selectField( 'revision', 'MIN(rev_id)', false, __FUNCTION__
);
24 $end = $db->selectField( 'revision', 'MAX(rev_id)', false, __FUNCTION__
);
26 $blockEnd = $start + BATCH_SIZE
- 1;
28 while( $blockEnd <= $end ) {
29 $cond = "rev_id BETWEEN $blockStart AND $blockEnd";
30 $res = $db->select( 'revision', array('rev_id','rev_page'), $cond, __FUNCTION__
);
31 # Go through and update rev_parent_id from these rows.
32 # Assume that the previous revision of the title was
33 # the original previous revision of the title when the
35 foreach( $res as $row ) {
36 $previousID = $db->selectField( 'revision', 'rev_id',
37 array( 'rev_page' => $row->rev_page
, "rev_id < '{$row->rev_id}'" ),
39 array( 'ORDER BY' => 'rev_id DESC' ) );
41 $db->update( 'revision',
42 array( 'rev_parent_id' => intval($previousID) ),
43 array( 'rev_id' => $row->rev_id
),
47 $blockStart +
= BATCH_SIZE
;
48 $blockEnd +
= BATCH_SIZE
;
51 $logged = $db->insert( 'updatelog',
52 array( 'ul_key' => 'populate rev_parent_id' ),
56 echo "rev_parent_id population complete ... {$count} rows\n";
59 echo "Could not insert rev_parent_id population row.\n";