3 define( 'REPORTING_INTERVAL', 100 );
4 define( 'STUB_HEADER', 'O:15:"historyblobstub"' );
6 if ( !defined( 'MEDIAWIKI' ) ) {
7 $optionsWithArgs = array( 'm' );
9 require_once( '../commandLine.inc' );
10 require_once( 'ExternalStoreDB.php' );
11 require_once( 'resolveStubs.php' );
13 $fname = 'moveToExternal';
15 if ( !isset( $args[0] ) ) {
16 print "Usage: php moveToExternal.php [-m <maxid>] <cluster>\n";
21 $dbw =& wfGetDB( DB_MASTER
);
23 if ( isset( $options['m'] ) ) {
24 $maxID = $options['m'];
26 $maxID = $dbw->selectField( 'text', 'MAX(old_id)', false, $fname );
29 moveToExternal( $cluster, $maxID );
34 function moveToExternal( $cluster, $maxID ) {
35 $fname = 'moveToExternal';
36 $dbw =& wfGetDB( DB_MASTER
);
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
) ) {
45 $row = $dbw->selectRow( 'text', array( 'old_flags', 'old_text' ),
48 "old_flags NOT LIKE '%external%'",
51 # Non-existent or already done
56 $flags = explode( ',', $row->old_flags
);
57 if ( in_array( 'object', $flags )
58 && substr( $row->old_text
, 0, strlen( STUB_HEADER
) ) === STUB_HEADER
)
60 resolveStub( $id, $row->old_text
, $row->old_flags
);
64 $url = $ext->store( $cluster, $row->old_text
);
66 print "Error writing to external storage\n";
69 if ( $row->old_flags
=== '' ) {
72 $flags = "{$row->old_flags},external";
75 array( 'old_flags' => $flags, 'old_text' => $url ),
76 array( 'old_id' => $id ), $fname );