MediaWiki master
patchSql.php
Go to the documentation of this file.
1<?php
10
13
14// @codeCoverageIgnoreStart
15require_once __DIR__ . '/Maintenance.php';
16// @codeCoverageIgnoreEnd
17
23class PatchSql extends Maintenance {
24 public function __construct() {
25 parent::__construct();
26 $this->addDescription( 'Run an SQL file into the DB, replacing prefix and charset vars' );
27 $this->addArg(
28 'patch-name',
29 'Name of the patch file, either full path or in sql/$dbtype/'
30 );
31 }
32
34 public function getDbType() {
35 return Maintenance::DB_ADMIN;
36 }
37
38 public function execute() {
39 $dbw = $this->getDB( DB_PRIMARY );
40 $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
41
42 foreach ( $this->getArgs() as $name ) {
43 $files = [
44 $name,
45 $updater->patchPath( $dbw, $name ),
46 $updater->patchPath( $dbw, "patch-$name.sql" ),
47 ];
48 foreach ( $files as $file ) {
49 if ( file_exists( $file ) ) {
50 $this->output( "$file ...\n" );
51 $dbw->sourceFile( $file );
52 continue 2;
53 }
54 }
55 $this->error( "Could not find $name\n" );
56 }
57 $this->output( "done.\n" );
58 }
59}
60
61// @codeCoverageIgnoreStart
62$maintClass = PatchSql::class;
63require_once RUN_MAINTENANCE_IF_MAIN;
64// @codeCoverageIgnoreEnd
const DB_PRIMARY
Definition defines.php:28
$maintClass
Apply database changes after updating MediaWiki.
static newForDB(IMaintainableDatabase $db, $shared=false, ?Maintenance $maintenance=null)
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition patchSql.php:23
getDbType()
Definition patchSql.php:34
__construct()
Definition patchSql.php:24