Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 25
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
PatchSql
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 3
42
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 1
2
 getDbType
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 15
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2/**
3 * Manually run an SQL patch outside of the general updaters.
4 * This ensures that the DB options (charset, prefix, engine) are correctly set.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 * http://www.gnu.org/copyleft/gpl.html
20 *
21 * @file
22 * @ingroup Maintenance
23 */
24
25use MediaWiki\Installer\DatabaseUpdater;
26
27require_once __DIR__ . '/Maintenance.php';
28
29/**
30 * Maintenance script that manually runs an SQL patch outside of the general updaters.
31 *
32 * @ingroup Maintenance
33 */
34class PatchSql extends Maintenance {
35    public function __construct() {
36        parent::__construct();
37        $this->addDescription( 'Run an SQL file into the DB, replacing prefix and charset vars' );
38        $this->addArg(
39            'patch-name',
40            'Name of the patch file, either full path or in maintenance/archives'
41        );
42    }
43
44    public function getDbType() {
45        return Maintenance::DB_ADMIN;
46    }
47
48    public function execute() {
49        $dbw = $this->getDB( DB_PRIMARY );
50        $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
51
52        foreach ( $this->getArgs() as $name ) {
53            $files = [
54                $name,
55                $updater->patchPath( $dbw, $name ),
56                $updater->patchPath( $dbw, "patch-$name.sql" ),
57            ];
58            foreach ( $files as $file ) {
59                if ( file_exists( $file ) ) {
60                    $this->output( "$file ...\n" );
61                    $dbw->sourceFile( $file );
62                    continue 2;
63                }
64            }
65            $this->error( "Could not find $name\n" );
66        }
67        $this->output( "done.\n" );
68    }
69}
70
71$maintClass = PatchSql::class;
72require_once RUN_MAINTENANCE_IF_MAIN;