Fix annoying dupe messages with chunksize
[lhc/web/wiklou.git] / maintenance / compressOld.inc
1 <?php
2
3 include_once( "Article.php" );
4
5 function compressOldPages( $start = 0 ) {
6 $chunksize = 50;
7 print "Starting from old_id $start...\n";
8 do {
9 $end = $start + $chunksize;
10 $sql = "SELECT old_id,old_flags,old_namespace,old_title,old_text FROM old WHERE old_id>=$start AND old_id<$end ORDER BY old_id LIMIT $chunksize";
11 $res = wfQuery( $sql, DB_READ, "compressOldPages" );
12 if( wfNumRows( $res ) == 0 ) {
13 break;
14 }
15 while( $row = wfFetchObject( $res ) ) {
16 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
17 compressPage( $row );
18 }
19 wfFreeResult( $res );
20 $start += $chunksize;
21 print "$start...\n";
22 } while( true );
23 }
24
25 function compressPage( $row ) {
26 if( false !== strpos( $row->old_flags, "gzip" ) ) {
27 print "Already compressed row {$row->old_id}?\n";
28 return false;
29 }
30 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
31 $compress = wfStrencode( gzdeflate( $row->old_text ) );
32
33 $sql = "UPDATE old SET old_flags='$flags', old_text='$compress' WHERE old_id={$row->old_id} LIMIT 1";
34 $res = wfQuery( $sql, DB_WRITE, 'compressPage' );
35 return $res;
36 }
37
38 ?>