3 define( 'REPORTING_INTERVAL', 100 );
5 if ( !defined( 'MEDIAWIKI' ) ) {
6 $optionsWithArgs = array( 'm' );
8 require_once( '../commandLine.inc' );
9 require_once( 'ExternalStoreDB.php' );
10 require_once( 'resolveStubs.php' );
12 $fname = 'moveToExternal';
14 if ( !isset( $args[0] ) ) {
15 print "Usage: php moveToExternal.php [-m <maxid>] <cluster>\n";
20 $dbw =& wfGetDB( DB_MASTER
);
22 if ( isset( $options['m'] ) ) {
23 $maxID = $options['m'];
25 $maxID = $dbw->selectField( 'text', 'MAX(old_id)', false, $fname );
28 moveToExternal( $cluster, $maxID );
33 function moveToExternal( $cluster, $maxID ) {
34 $fname = 'moveToExternal';
35 $dbw =& wfGetDB( DB_MASTER
);
37 print "Moving $maxID text rows to external storage\n";
38 $ext = new ExternalStoreDB
;
39 for ( $id = 1; $id <= $maxID; $id++
) {
40 if ( !($id % REPORTING_INTERVAL
) ) {
44 $row = $dbw->selectRow( 'text', array( 'old_flags', 'old_text' ),
47 "old_flags NOT LIKE '%external%'",
50 # Non-existent or already done
55 $text = $row->old_text
;
56 if ( $row->old_flags
=== '' ) {
59 $flags = "{$row->old_flags},external";
62 if ( strpos( $flags, 'object' ) !== false ) {
63 $obj = unserialize( $text );
64 $className = strtolower( get_class( $obj ) );
65 if ( $className == 'historyblobstub' ) {
66 resolveStub( $id, $row->old_text
, $row->old_flags
);
68 } elseif ( $className == 'historyblobcurstub' ) {
69 $text = gzdeflate( $obj->getText() );
70 $flags = 'utf-8,gzip,external';
71 } elseif ( $className == 'concatenatedgziphistoryblob' ) {
74 print "Warning: unrecognised object class \"$className\"\n";
79 if ( strlen( $text ) < 100 ) {
80 // Don't move tiny revisions
84 #print "Storing " . strlen( $text ) . " bytes to $url\n";
86 $url = $ext->store( $cluster, $text );
88 print "Error writing to external storage\n";
92 array( 'old_flags' => $flags, 'old_text' => $url ),
93 array( 'old_id' => $id ), $fname );