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 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
62 $extStore = $esFactory->getStore(
$type );
65 for ( $block = 0; $block < $numBlocks; $block++ ) {
66 $blockStart = $block * $blockSize + $minID;
67 $blockEnd = $blockStart + $blockSize - 1;
70 print "oldid=$blockStart, moved=$numMoved\n";
71 $lbFactory->waitForReplication();
74 $res =
$dbr->select(
'text', [
'old_id',
'old_flags',
'old_text' ],
76 "old_id BETWEEN $blockStart AND $blockEnd",
77 'old_flags NOT ' .
$dbr->buildLike(
$dbr->anyString(),
'external',
$dbr->anyString() ),
80 foreach (
$res as $row ) {
82 $text = $row->old_text;
84 if ( $row->old_flags ===
'' ) {
87 $flags =
"{$row->old_flags},external";
90 if ( strpos( $flags,
'object' ) !==
false ) {
92 $className = strtolower( get_class( $obj ) );
93 if ( $className ==
'historyblobstub' ) {
94 # resolveStub( $id, $row->old_text, $row->old_flags );
97 } elseif ( $className ==
'historyblobcurstub' ) {
98 $text = gzdeflate( $obj->getText() );
99 $flags =
'utf-8,gzip,external';
100 } elseif ( $className ==
'concatenatedgziphistoryblob' ) {
103 print "Warning: unrecognised object class \"$className\"\n";
110 if ( strlen( $text ) < 100 && $className ===
false ) {
115 # print "Storing " . strlen( $text ) . " bytes to $url\n";
116 # print "old_id=$id\n";
118 $url = $extStore->store( $location, $text );
120 print "Error writing to external storage\n";
123 $dbw->update(
'text',
124 [
'old_flags' => $flags,
'old_text' => $url ],
125 [
'old_id' => $id ], $fname );