Debian Codegraph @

maintenance/storage/fixLegacyEncoding.php

raw symbols SCIP
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 // @codeCoverageIgnoreStart
27 require_once __DIR__ . '/moveToExternal.php';
28 // @codeCoverageIgnoreEnd
29
30 class FixLegacyEncoding extends MoveToExternal {
31 public function __construct() {
32 parent::__construct();
33 $this->addDescription( 'Change encoding of stored content from legacy encoding to UTF-8' );
34 }
35
36 protected function getConditions( $blockStart, $blockEnd, $dbr ) {
37 return [
38 $dbr->expr( 'old_id', '>=', $blockStart ),
39 $dbr->expr( 'old_id', '<=', $blockEnd ),
40 $dbr->expr( 'old_flags', IExpression::NOT_LIKE,
41 new LikeValue( $dbr->anyString(), 'utf-8', $dbr->anyString() ) ),
42 $dbr->expr( 'old_flags', IExpression::NOT_LIKE,
43 new LikeValue( $dbr->anyString(), 'utf8', $dbr->anyString() ) ),
44 ];
45 }
46
47 protected function resolveText( $text, $flags ) {
48 if ( in_array( 'error', $flags ) ) {
49 return [ $text, $flags ];
50 }
51 $blobStore = $this->getServiceContainer()->getBlobStore();
52 if ( in_array( 'external', $flags ) && $blobStore instanceof SqlBlobStore ) {
53 $newText = $blobStore->expandBlob( $text, $flags );
54 if ( $newText === false ) {
55 return [ false, $flags ];
56 }
57 $text = $newText;
58 // It will be put back in external storage again
59 $flags = array_diff( $flags, [ 'external' ] );
60 }
61 if ( in_array( 'gzip', $flags ) ) {
62 $newText = gzinflate( $text );
63 if ( $newText === false ) {
64 return [ false, $flags ];
65 }
66 $text = $newText;
67 $flags = array_diff( $flags, [ 'gzip' ] );
68 }
69 return [ $text, $flags ];
70 }
71
72 }
73
74 // @codeCoverageIgnoreStart
75 $maintClass = FixLegacyEncoding::class;
76 require_once RUN_MAINTENANCE_IF_MAIN;
77 // @codeCoverageIgnoreEnd