* @file
* @ingroup Maintenance ExternalStorage
*/
+use MediaWiki\MediaWikiServices;
+use MediaWiki\Revision\SlotRecord;
require_once __DIR__ . '/../Maintenance.php';
* @ingroup Maintenance ExternalStorage
*/
class CompressOld extends Maintenance {
- /**
- * Option to load each revision individually.
- */
- const LS_INDIVIDUAL = 0;
-
- /**
- * Option to load revisions in chunks.
- */
- const LS_CHUNKED = 1;
-
public function __construct() {
parent::__construct();
$this->addDescription( 'Compress the text of a wiki' );
# Store in external storage if required
if ( $extdb !== '' ) {
- $storeObj = new ExternalStoreDB;
+ $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory();
+ /** @var ExternalStoreDB $storeObj */
+ $storeObj = $esFactory->getStore( 'DB' );
$compress = $storeObj->store( $extdb, $compress );
if ( $compress === false ) {
$this->error( "Unable to store object" );
private function compressWithConcat( $startId, $maxChunkSize, $beginDate,
$endDate, $extdb = "", $maxPageId = false
) {
- $loadStyle = self::LS_CHUNKED;
+ global $wgMultiContentRevisionSchemaMigrationStage;
$dbr = $this->getDB( DB_REPLICA );
$dbw = $this->getDB( DB_MASTER );
# Set up external storage
if ( $extdb != '' ) {
- $storeObj = new ExternalStoreDB;
+ $esFactory = MediaWikiServices::getInstance()->getExternalStoreFactory();
+ /** @var ExternalStoreDB $storeObj */
+ $storeObj = $esFactory->getStore( 'DB' );
}
# Get all articles by page_id
}
$conds[] = "rev_timestamp<'" . $endDate . "'";
}
- if ( $loadStyle == self::LS_CHUNKED ) {
+
+ if ( $wgMultiContentRevisionSchemaMigrationStage & SCHEMA_COMPAT_READ_OLD ) {
$tables = [ 'revision', 'text' ];
- $fields = [ 'rev_id', 'rev_text_id', 'old_flags', 'old_text' ];
$conds[] = 'rev_text_id=old_id';
- $revLoadOptions = 'FOR UPDATE';
} else {
- $tables = [ 'revision' ];
- $fields = [ 'rev_id', 'rev_text_id' ];
- $revLoadOptions = [];
+ $slotRoleStore = MediaWikiServices::getInstance()->getSlotRoleStore();
+ $tables = [ 'revision', 'slots', 'content', 'text' ];
+ $conds = array_merge( [
+ 'rev_id=slot_revision_id',
+ 'slot_role_id=' . $slotRoleStore->getId( SlotRecord::MAIN ),
+ 'content_id=slot_content_id',
+ 'SUBSTRING(content_address, 1, 3)=' . $dbr->addQuotes( 'tt:' ),
+ 'SUBSTRING(content_address, 4)=old_id',
+ ], $conds );
}
+ $fields = [ 'rev_id', 'old_id', 'old_flags', 'old_text' ];
+ $revLoadOptions = 'FOR UPDATE';
+
# Don't work with current revisions
# Don't lock the page table for update either -- TS 2006-04-04
# $tables[] = 'page';
$stubs = [];
$this->beginTransaction( $dbw, __METHOD__ );
$usedChunk = false;
- $primaryOldid = $revs[$i]->rev_text_id;
+ $primaryOldid = $revs[$i]->old_id;
# Get the text of each revision and add it to the object
for ( $j = 0; $j < $thisChunkSize && $chunk->isHappy(); $j++ ) {
- $oldid = $revs[$i + $j]->rev_text_id;
+ $oldid = $revs[$i + $j]->old_id;
# Get text
- if ( $loadStyle == self::LS_INDIVIDUAL ) {
- $textRow = $dbw->selectRow( 'text',
- [ 'old_flags', 'old_text' ],
- [ 'old_id' => $oldid ],
- __METHOD__,
- 'FOR UPDATE'
- );
- $text = Revision::getRevisionText( $textRow );
- } else {
- $text = Revision::getRevisionText( $revs[$i + $j] );
- }
+ $text = Revision::getRevisionText( $revs[$i + $j] );
if ( $text === false ) {
$this->error( "\nError, unable to get text in old_id $oldid" );
# Store the stub objects
for ( $j = 1; $j < $thisChunkSize; $j++ ) {
# Skip if not compressing and don't overwrite the first revision
- if ( $stubs[$j] !== false && $revs[$i + $j]->rev_text_id != $primaryOldid ) {
+ if ( $stubs[$j] !== false && $revs[$i + $j]->old_id != $primaryOldid ) {
$dbw->update( 'text',
[ /* SET */
'old_text' => serialize( $stubs[$j] ),
'old_flags' => 'object,utf-8',
], [ /* WHERE */
- 'old_id' => $revs[$i + $j]->rev_text_id
+ 'old_id' => $revs[$i + $j]->old_id
]
);
}