Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 29 |
|
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 | * This program is free software; you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation; either version 2 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License along |
14 | * with this program; if not, write to the Free Software Foundation, Inc., |
15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
16 | * http://www.gnu.org/copyleft/gpl.html |
17 | * |
18 | * @file |
19 | * @ingroup Maintenance ExternalStorage |
20 | */ |
21 | |
22 | use MediaWiki\Storage\SqlBlobStore; |
23 | use Wikimedia\Rdbms\IExpression; |
24 | use Wikimedia\Rdbms\LikeValue; |
25 | |
26 | require_once __DIR__ . '/moveToExternal.php'; |
27 | |
28 | class FixLegacyEncoding extends MoveToExternal { |
29 | public function __construct() { |
30 | parent::__construct(); |
31 | $this->addDescription( 'Change encoding of stored content from legacy encoding to UTF-8' ); |
32 | } |
33 | |
34 | protected function getConditions( $blockStart, $blockEnd, $dbr ) { |
35 | return [ |
36 | $dbr->expr( 'old_id', '>=', $blockStart ), |
37 | $dbr->expr( 'old_id', '<=', $blockEnd ), |
38 | $dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
39 | new LikeValue( $dbr->anyString(), 'utf-8', $dbr->anyString() ) ), |
40 | $dbr->expr( 'old_flags', IExpression::NOT_LIKE, |
41 | new LikeValue( $dbr->anyString(), 'utf8', $dbr->anyString() ) ), |
42 | ]; |
43 | } |
44 | |
45 | protected function resolveText( $text, $flags ) { |
46 | if ( in_array( 'error', $flags ) ) { |
47 | return [ $text, $flags ]; |
48 | } |
49 | $blobStore = $this->getServiceContainer()->getBlobStore(); |
50 | if ( in_array( 'external', $flags ) && $blobStore instanceof SqlBlobStore ) { |
51 | $newText = $blobStore->expandBlob( $text, $flags ); |
52 | if ( $newText === false ) { |
53 | return [ false, $flags ]; |
54 | } |
55 | $text = $newText; |
56 | // It will be put back in external storage again |
57 | $flags = array_diff( $flags, [ 'external' ] ); |
58 | } |
59 | if ( in_array( 'gzip', $flags ) ) { |
60 | $newText = gzinflate( $text ); |
61 | if ( $newText === false ) { |
62 | return [ false, $flags ]; |
63 | } |
64 | $text = $newText; |
65 | $flags = array_diff( $flags, [ 'gzip' ] ); |
66 | } |
67 | return [ $text, $flags ]; |
68 | } |
69 | |
70 | } |
71 | |
72 | $maintClass = FixLegacyEncoding::class; |
73 | require_once RUN_MAINTENANCE_IF_MAIN; |