Quick hacky script to initialize site_stats row where missing.
[lhc/web/wiklou.git] / maintenance / storage / moveToExternal.php
1 <?php
2
3 define( 'REPORTING_INTERVAL', 100 );
4 define( 'STUB_HEADER', 'O:15:"historyblobstub"' );
5
6 if ( !defined( 'MEDIAWIKI' ) ) {
7 $optionsWithArgs = array( 'm' );
8
9 require_once( '../commandLine.inc' );
10 require_once( 'ExternalStoreDB.php' );
11 require_once( 'resolveStubs.php' );
12
13 $fname = 'moveToExternal';
14
15 if ( !isset( $args[0] ) ) {
16 print "Usage: php moveToExternal.php [-m <maxid>] <cluster>\n";
17 exit;
18 }
19
20 $cluster = $args[0];
21 $dbw =& wfGetDB( DB_MASTER );
22
23 if ( isset( $options['m'] ) ) {
24 $maxID = $options['m'];
25 } else {
26 $maxID = $dbw->selectField( 'text', 'MAX(old_id)', false, $fname );
27 }
28
29 moveToExternal( $cluster, $maxID );
30 }
31
32
33
34 function moveToExternal( $cluster, $maxID ) {
35 $fname = 'moveToExternal';
36 $dbw =& wfGetDB( DB_MASTER );
37
38 print "Moving $maxID text rows to external storage\n";
39 $ext = new ExternalStoreDB;
40 for ( $id = 1; $id <= $maxID; $id++ ) {
41 if ( !($id % REPORTING_INTERVAL) ) {
42 print "$id\n";
43 wfWaitForSlaves( 5 );
44 }
45 $row = $dbw->selectRow( 'text', array( 'old_flags', 'old_text' ),
46 array(
47 'old_id' => $id,
48 "old_flags NOT LIKE '%external%'",
49 ), $fname );
50 if ( !$row ) {
51 # Non-existent or already done
52 continue;
53 }
54
55 # Resolve stubs
56 $flags = explode( ',', $row->old_flags );
57 if ( in_array( 'object', $flags )
58 && substr( $row->old_text, 0, strlen( STUB_HEADER ) ) === STUB_HEADER )
59 {
60 resolveStub( $id, $row->old_text, $row->old_flags );
61 continue;
62 }
63
64 $url = $ext->store( $cluster, $row->old_text );
65 if ( !$url ) {
66 print "Error writing to external storage\n";
67 exit;
68 }
69 if ( $row->old_flags === '' ) {
70 $flags = 'external';
71 } else {
72 $flags = "{$row->old_flags},external";
73 }
74 $dbw->update( 'text',
75 array( 'old_flags' => $flags, 'old_text' => $url ),
76 array( 'old_id' => $id ), $fname );
77 }
78 }
79
80 ?>