* Support for table name prefixes throughout the code. No support yet for converting...
[lhc/web/wiklou.git] / maintenance / compressOld.inc
1 <?php
2
3 function compressOldPages( $start = 0 ) {
4 $fname = 'compressOldPages';
5
6 $chunksize = 50;
7 print "Starting from old_id $start...\n";
8 $dbw =& wfGetDB( DB_MASTER );
9 $old = $dbw->tableName( 'old' );
10 do {
11 $end = $start + $chunksize;
12 $res = dbw->select( 'old', array( 'old_id','old_flags','old_namespace','old_title','old_text' ),
13 "old_id>=$start", $fname, array( 'ORDER BY' => 'old_id', 'LIMIT' => $chunksize, 'FOR UPDATE' ) );
14 if( $dbw->numRows( $res ) == 0 ) {
15 break;
16 }
17 $last = $start;
18 while( $row = $dbw->fetchObject( $res ) ) {
19 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
20 compressPage( $row );
21 $last = $row->old_id;
22 }
23 $dbw->freeResult( $res );
24 $start = $last + 1; # Deletion may leave long empty stretches
25 print "$start...\n";
26 } while( true );
27 }
28
29 function compressPage( $row ) {
30 if( false !== strpos( $row->old_flags, "gzip" ) ) {
31 print "Already compressed row {$row->old_id}?\n";
32 return false;
33 }
34 $dbw =& wfGetDB( DB_MASTER );
35 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
36 $compress = $dbw->strencode( gzdeflate( $row->old_text ) );
37 $dbw->update( 'old',
38 array( /* SET */
39 'old_flags' => $flags,
40 'old_text' => $compress
41 ), array( /* WHERE */
42 'old_id' => $row->old_id
43 ), $fname, 'LIMIT 1'
44 );
45 return $res;
46 }
47
48 ?>