Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| FixLegacyEncoding | |
0.00% |
0 / 26 |
|
0.00% |
0 / 3 |
90 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getConditions | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| resolveText | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
56 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * @license GPL-2.0-or-later |
| 4 | * @file |
| 5 | * @ingroup Maintenance ExternalStorage |
| 6 | */ |
| 7 | |
| 8 | use MediaWiki\Storage\SqlBlobStore; |
| 9 | use Wikimedia\Rdbms\IExpression; |
| 10 | use Wikimedia\Rdbms\IReadableDatabase; |
| 11 | use Wikimedia\Rdbms\LikeValue; |
| 12 | |
| 13 | // @codeCoverageIgnoreStart |
| 14 | require_once __DIR__ . '/moveToExternal.php'; |
| 15 | // @codeCoverageIgnoreEnd |
| 16 | |
| 17 | class FixLegacyEncoding extends MoveToExternal { |
| 18 | public function __construct() { |
| 19 | parent::__construct(); |
| 20 | $this->addDescription( 'Change encoding of stored content from legacy encoding to UTF-8' ); |
| 21 | } |
| 22 | |
| 23 | protected function getConditions( int $blockStart, int $blockEnd, IReadableDatabase $dbr ): array { |
| 24 | return [ |
| 25 | $dbr->expr( 'old_id', '>=', $blockStart ), |
| 26 | $dbr->expr( 'old_id', '<=', $blockEnd ), |
| 27 | $dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
| 28 | new LikeValue( $dbr->anyString(), 'utf-8', $dbr->anyString() ) ), |
| 29 | $dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
| 30 | new LikeValue( $dbr->anyString(), 'utf8', $dbr->anyString() ) ), |
| 31 | ]; |
| 32 | } |
| 33 | |
| 34 | protected function resolveText( string $text, array $flags ): array { |
| 35 | if ( in_array( 'error', $flags ) ) { |
| 36 | return [ $text, $flags ]; |
| 37 | } |
| 38 | $blobStore = $this->getServiceContainer()->getBlobStore(); |
| 39 | if ( in_array( 'external', $flags ) && $blobStore instanceof SqlBlobStore ) { |
| 40 | $newText = $blobStore->expandBlob( $text, $flags ); |
| 41 | if ( $newText === false ) { |
| 42 | return [ false, $flags ]; |
| 43 | } |
| 44 | $text = $newText; |
| 45 | // It will be put back in external storage again |
| 46 | $flags = array_diff( $flags, [ 'external' ] ); |
| 47 | } |
| 48 | if ( in_array( 'gzip', $flags ) ) { |
| 49 | $newText = gzinflate( $text ); |
| 50 | if ( $newText === false ) { |
| 51 | return [ false, $flags ]; |
| 52 | } |
| 53 | $text = $newText; |
| 54 | $flags = array_diff( $flags, [ 'gzip' ] ); |
| 55 | } |
| 56 | return [ $text, $flags ]; |
| 57 | } |
| 58 | |
| 59 | } |
| 60 | |
| 61 | // @codeCoverageIgnoreStart |
| 62 | $maintClass = FixLegacyEncoding::class; |
| 63 | require_once RUN_MAINTENANCE_IF_MAIN; |
| 64 | // @codeCoverageIgnoreEnd |