* @ingroup Maintenance ExternalStorage
*/
-define( 'CONCAT_HEADER', 'O:27:"concatenatedgziphistoryblob"' );
-
if ( !defined( 'MEDIAWIKI' ) ) {
require_once( dirname( __FILE__ ) . '/../commandLine.inc' );
* @ingroup Maintenance ExternalStorage
*/
class CheckStorage {
+ const CONCAT_HEADER = 'O:27:"concatenatedgziphistoryblob"';
var $oldIdMap, $errors;
var $dbStore = null;
);
function check( $fix = false, $xml = '' ) {
- $fname = 'checkStorage';
$dbr = wfGetDB( DB_SLAVE );
if ( $fix ) {
$dbw = wfGetDB( DB_MASTER );
} else {
print "Checking...\n";
}
- $maxRevId = $dbr->selectField( 'revision', 'MAX(rev_id)', false, $fname );
+ $maxRevId = $dbr->selectField( 'revision', 'MAX(rev_id)', false, __METHOD__ );
$chunkSize = 1000;
$flagStats = array();
$objectStats = array();
$this->oldIdMap = array();
$dbr->ping();
$res = $dbr->select( 'revision', array( 'rev_id', 'rev_text_id' ),
- array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), $fname );
+ array( "rev_id BETWEEN $chunkStart AND $chunkEnd" ), __METHOD__ );
foreach ( $res as $row ) {
$this->oldIdMap[$row->rev_id] = $row->rev_text_id;
}
$externalRevs = array();
$objectRevs = array();
$res = $dbr->select( 'text', array( 'old_id', 'old_flags' ),
- 'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', $fname );
+ 'old_id IN (' . implode( ',', $this->oldIdMap ) . ')', __METHOD__ );
foreach ( $res as $row ) {
$flags = $row->old_flags;
$id = $row->old_id;
$dbw = wfGetDB( DB_MASTER );
$dbw->ping();
$dbw->update( 'text', array( 'old_flags' => '' ),
- array( 'old_id' => $id ), $fname );
+ array( 'old_id' => $id ), __METHOD__ );
echo "Fixed\n";
} else {
$this->error( 'fixable', "Warning: old_flags set to 0", $id );
$externalNormalBlobs = array();
if ( count( $externalRevs ) ) {
$res = $dbr->select( 'text', array( 'old_id', 'old_flags', 'old_text' ),
- array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), $fname );
+ array( 'old_id IN (' . implode( ',', $externalRevs ) . ')' ), __METHOD__ );
foreach ( $res as $row ) {
$urlParts = explode( '://', $row->old_text, 2 );
if ( count( $urlParts ) !== 2 || $urlParts[1] == '' ) {
$blobsTable = $this->dbStore->getTable( $extDb );
$res = $extDb->select( $blobsTable,
array( 'blob_id' ),
- array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
+ array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
foreach ( $res as $row ) {
unset( $xBlobIds[$row->blob_id] );
}
if ( count( $objectRevs ) ) {
$headerLength = 300;
$res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
- array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), $fname );
+ array( 'old_id IN (' . implode( ',', $objectRevs ) . ')' ), __METHOD__ );
foreach ( $res as $row ) {
$oldId = $row->old_id;
$matches = array();
if ( count( $concatBlobs ) ) {
$headerLength = 300;
$res = $dbr->select( 'text', array( 'old_id', 'old_flags', "LEFT(old_text, $headerLength) AS header" ),
- array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), $fname );
+ array( 'old_id IN (' . implode( ',', array_keys( $concatBlobs ) ) . ')' ), __METHOD__ );
foreach ( $res as $row ) {
$flags = explode( ',', $row->old_flags );
if ( in_array( 'external', $flags ) ) {
$this->error( 'unfixable', "Error: invalid flags \"{$row->old_flags}\" on concat bulk row {$row->old_id}",
$concatBlobs[$row->old_id] );
}
- } elseif ( strcasecmp( substr( $row->header, 0, strlen( CONCAT_HEADER ) ), CONCAT_HEADER ) ) {
+ } elseif ( strcasecmp( substr( $row->header, 0, strlen( self::CONCAT_HEADER ) ), self::CONCAT_HEADER ) ) {
$this->error( 'restore text', "Error: Incorrect object header for concat bulk row {$row->old_id}",
$concatBlobs[$row->old_id] );
} # else good
}
function checkExternalConcatBlobs( $externalConcatBlobs ) {
- $fname = 'CheckStorage::checkExternalConcatBlobs';
if ( !count( $externalConcatBlobs ) ) {
return;
}
$blobIds = array_keys( $oldIds );
$extDb =& $this->dbStore->getSlave( $cluster );
$blobsTable = $this->dbStore->getTable( $extDb );
- $headerLength = strlen( CONCAT_HEADER );
+ $headerLength = strlen( self::CONCAT_HEADER );
$res = $extDb->select( $blobsTable,
array( 'blob_id', "LEFT(blob_text, $headerLength) AS header" ),
- array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), $fname );
+ array( 'blob_id IN( ' . implode( ',', $blobIds ) . ')' ), __METHOD__ );
foreach ( $res as $row ) {
- if ( strcasecmp( $row->header, CONCAT_HEADER ) ) {
+ if ( strcasecmp( $row->header, self::CONCAT_HEADER ) ) {
$this->error( 'restore text', "Error: invalid header on target $cluster/{$row->blob_id} of two-part ES URL",
$oldIds[$row->blob_id] );
}
}
function importRevision( &$revision, &$importer ) {
- $fname = 'CheckStorage::importRevision';
-
$id = $revision->getID();
$text = $revision->getText();
if ( $text === '' ) {
// Find text row again
$dbr = wfGetDB( DB_SLAVE );
- $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), $fname );
+ $oldId = $dbr->selectField( 'revision', 'rev_text_id', array( 'rev_id' => $id ), __METHOD__ );
if ( !$oldId ) {
echo "Missing revision row for rev_id $id\n";
return;
$dbw->update( 'text',
array( 'old_flags' => $flags, 'old_text' => $text ),
array( 'old_id' => $oldId ),
- $fname, array( 'LIMIT' => 1 )
+ __METHOD__, array( 'LIMIT' => 1 )
);
// Remove it from the unfixed list and add it to the fixed list