Prevent buffering of user feedback output (may be a problem in cygwin)
[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 $sql = "SELECT old_id,old_flags,old_namespace,old_title,old_text FROM old WHERE old_id>=$start ORDER BY old_id LIMIT $chunksize";
10 $res = wfQuery( $sql, DB_READ, "compressOldPages" );
11 if( wfNumRows( $res ) == 0 ) {
12 break;
13 }
14 while( $row = wfFetchObject( $res ) ) {
15 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
16 compressPage( $row );
17 }
18 wfFreeResult( $res );
19 $start += $chunksize;
20 print "$start...\n";
21 } while( true );
22 }
23
24 function compressPage( $row ) {
25 if( false !== strpos( $row->old_flags, "gzip" ) ) {
26 print "Already compressed row {$row->old_id}?\n";
27 return false;
28 }
29 $flags = $row->old_flags ? "{$row->old_flags},gzip" : "gzip";
30 $compress = wfStrencode( gzdeflate( $row->old_text ) );
31
32 $sql = "UPDATE old SET old_flags='$flags', old_text='$compress' WHERE old_id={$row->old_id} LIMIT 1";
33 $res = wfQuery( $sql, DB_WRITE, 'compressPage' );
34 return $res;
35 }
36
37 ?>