26 define(
'REPORTING_INTERVAL', 1 );
28 if ( !defined(
'MEDIAWIKI' ) ) {
30 require_once __DIR__ .
'/../commandLine.inc';
31 require_once
'resolveStubs.php';
33 $fname =
'moveToExternal';
35 if ( !isset(
$args[1] ) ) {
36 print
"Usage: php moveToExternal.php [-s <startid>] [-e <endid>] <type> <location>\n";
44 $maxID = $options[
'e'] ?? $dbw->selectField(
'text',
'MAX(old_id)',
'', $fname );
45 $minID = $options[
's'] ?? 1;
51 $fname =
'moveToExternal';
55 $count = $maxID - $minID + 1;
57 $numBlocks = ceil( $count / $blockSize );
58 print
"Moving text rows from $minID to $maxID to external storage\n";
60 $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory();
61 $extStore = $esFactory->getStore(
$type );
64 for ( $block = 0; $block < $numBlocks; $block++ ) {
65 $blockStart = $block * $blockSize + $minID;
66 $blockEnd = $blockStart + $blockSize - 1;
69 print
"oldid=$blockStart, moved=$numMoved\n";
73 $res =
$dbr->select(
'text', [
'old_id',
'old_flags',
'old_text' ],
75 "old_id BETWEEN $blockStart AND $blockEnd",
76 'old_flags NOT ' .
$dbr->buildLike(
$dbr->anyString(),
'external',
$dbr->anyString() ),
78 foreach (
$res as $row ) {
80 $text = $row->old_text;
82 if ( $row->old_flags ===
'' ) {
85 $flags =
"{$row->old_flags},external";
88 if ( strpos( $flags,
'object' ) !== false ) {
90 $className = strtolower( get_class( $obj ) );
91 if ( $className ==
'historyblobstub' ) {
92 # resolveStub( $id, $row->old_text, $row->old_flags );
95 } elseif ( $className ==
'historyblobcurstub' ) {
96 $text = gzdeflate( $obj->getText() );
97 $flags =
'utf-8,gzip,external';
98 } elseif ( $className ==
'concatenatedgziphistoryblob' ) {
101 print
"Warning: unrecognised object class \"$className\"\n";
108 if ( strlen( $text ) < 100 && $className ===
false ) {
113 # print "Storing " . strlen( $text ) . " bytes to $url\n";
114 # print "old_id=$id\n";
116 $url = $extStore->store( $location, $text );
118 print
"Error writing to external storage\n";
121 $dbw->update(
'text',
122 [
'old_flags' => $flags,
'old_text' => $url ],
123 [
'old_id' => $id ], $fname );