53 $fname =
'moveToExternal';
57 $count = $maxID - $minID + 1;
59 $numBlocks = ceil( $count / $blockSize );
60 print "Moving text rows from $minID to $maxID to external storage\n";
62 $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory();
63 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
64 $extStore = $esFactory->getStore(
$type );
67 for ( $block = 0; $block < $numBlocks; $block++ ) {
68 $blockStart = $block * $blockSize + $minID;
69 $blockEnd = $blockStart + $blockSize - 1;
72 print "oldid=$blockStart, moved=$numMoved\n";
73 $lbFactory->waitForReplication();
76 $res =
$dbr->select(
'text', [
'old_id',
'old_flags',
'old_text' ],
78 "old_id BETWEEN $blockStart AND $blockEnd",
79 'old_flags NOT ' .
$dbr->buildLike(
$dbr->anyString(),
'external',
$dbr->anyString() ),
82 foreach (
$res as $row ) {
84 $text = $row->old_text;
86 if ( $row->old_flags ===
'' ) {
89 $flags =
"{$row->old_flags},external";
92 if ( strpos( $flags,
'object' ) !==
false ) {
94 $className = strtolower( get_class( $obj ) );
95 if ( $className ==
'historyblobstub' ) {
96 # resolveStub( $id, $row->old_text, $row->old_flags );
99 } elseif ( $className ==
'historyblobcurstub' ) {
100 $text = gzdeflate( $obj->getText() );
101 $flags =
'utf-8,gzip,external';
102 } elseif ( $className ==
'concatenatedgziphistoryblob' ) {
105 print "Warning: unrecognised object class \"$className\"\n";
112 if ( strlen( $text ) < 100 && $className ===
false ) {
117 # print "Storing " . strlen( $text ) . " bytes to $url\n";
118 # print "old_id=$id\n";
120 $url = $extStore->store( $location, $text );
122 print "Error writing to external storage\n";
125 $dbw->update(
'text',
126 [
'old_flags' => $flags,
'old_text' => $url ],
127 [
'old_id' => $id ], $fname );