* Moved content from liveCmdLine.inc into commandLine.inc, obsoleting the former.
[lhc/web/wiklou.git] / maintenance / compressOld.inc
1 <?php
2
3 function compressOldPages( $start = 0 ) {
4 $chunksize = 50;
5 print "Starting from old_id $start...\n";
6 do {
7 $end = $start + $chunksize;
8 $sql = "SELECT old_id,old_flags,old_namespace,old_title,old_text FROM old WHERE old_id>=$start ORDER BY old_id LIMIT $chunksize";
9 $res = wfQuery( $sql, DB_READ, "compressOldPages" );
10 if( wfNumRows( $res ) == 0 ) {
11 break;
12 }
13 $last = $start;
14 while( $row = wfFetchObject( $res ) ) {
15 # print " {$row->old_id} - {$row->old_namespace}:{$row->old_title}\n";
16 compressPage( $row );
17 $last = $row->old_id;
18 }
19 wfFreeResult( $res );
20 $start = $last + 1; # Deletion may leave long empty stretches
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 ?>