X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fstorage%2FmoveToExternal.php;h=80dc7f96202c7111994202086c7e356aeac3b46e;hb=04d1aa3033f40a38d721f7f0e88b5bac440d2869;hp=ab59cb8d0a98d5c5216e3fed5427668fad7e83bc;hpb=ba5cf138d20b5e79f3bb607870143313c08da4c6;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/storage/moveToExternal.php b/maintenance/storage/moveToExternal.php index ab59cb8d0a..9554797f44 100644 --- a/maintenance/storage/moveToExternal.php +++ b/maintenance/storage/moveToExternal.php @@ -21,42 +21,44 @@ * @ingroup Maintenance ExternalStorage */ +use MediaWiki\MediaWikiServices; + define( 'REPORTING_INTERVAL', 1 ); if ( !defined( 'MEDIAWIKI' ) ) { + $optionsWithArgs = [ 'e', 's' ]; require_once __DIR__ . '/../commandLine.inc'; require_once 'resolveStubs.php'; $fname = 'moveToExternal'; - if ( !isset( $args[0] ) ) { - print "Usage: php moveToExternal.php [-s ] [-e ] \n"; + if ( !isset( $args[1] ) ) { + print "Usage: php moveToExternal.php [-s ] [-e ] \n"; exit; } - $cluster = $args[0]; + $type = $args[0]; // e.g. "DB" or "mwstore" + $location = $args[1]; // e.g. "cluster12" or "global-swift" $dbw = wfGetDB( DB_MASTER ); - if ( isset( $options['e'] ) ) { - $maxID = $options['e']; - } else { - $maxID = $dbw->selectField( 'text', 'MAX(old_id)', false, $fname ); - } - $minID = isset( $options['s'] ) ? $options['s'] : 1; + $maxID = $options['e'] ?? $dbw->selectField( 'text', 'MAX(old_id)', '', $fname ); + $minID = $options['s'] ?? 1; - moveToExternal( $cluster, $maxID, $minID ); + moveToExternal( $type, $location, $maxID, $minID ); } -function moveToExternal( $cluster, $maxID, $minID = 1 ) { +function moveToExternal( $type, $location, $maxID, $minID = 1 ) { $fname = 'moveToExternal'; $dbw = wfGetDB( DB_MASTER ); - $dbr = wfGetDB( DB_SLAVE ); + $dbr = wfGetDB( DB_REPLICA ); $count = $maxID - $minID + 1; $blockSize = 1000; $numBlocks = ceil( $count / $blockSize ); print "Moving text rows from $minID to $maxID to external storage\n"; - $ext = new ExternalStoreDB; + + $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory(); + $extStore = $esFactory->getStore( $type ); $numMoved = 0; for ( $block = 0; $block < $numBlocks; $block++ ) { @@ -68,11 +70,11 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) { wfWaitForSlaves(); } - $res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ), - array( + $res = $dbr->select( 'text', [ 'old_id', 'old_flags', 'old_text' ], + [ "old_id BETWEEN $blockStart AND $blockEnd", 'old_flags NOT ' . $dbr->buildLike( $dbr->anyString(), 'external', $dbr->anyString() ), - ), $fname ); + ], $fname ); foreach ( $res as $row ) { # Resolve stubs $text = $row->old_text; @@ -111,14 +113,14 @@ function moveToExternal( $cluster, $maxID, $minID = 1 ) { # print "Storing " . strlen( $text ) . " bytes to $url\n"; # print "old_id=$id\n"; - $url = $ext->store( $cluster, $text ); + $url = $extStore->store( $location, $text ); if ( !$url ) { print "Error writing to external storage\n"; exit; } $dbw->update( 'text', - array( 'old_flags' => $flags, 'old_text' => $url ), - array( 'old_id' => $id ), $fname ); + [ 'old_flags' => $flags, 'old_text' => $url ], + [ 'old_id' => $id ], $fname ); $numMoved++; } }