MediaWiki master
patchSql.php
Go to the documentation of this file.
1<?php
27
28// @codeCoverageIgnoreStart
29require_once __DIR__ . '/Maintenance.php';
30// @codeCoverageIgnoreEnd
31
37class PatchSql extends Maintenance {
38 public function __construct() {
39 parent::__construct();
40 $this->addDescription( 'Run an SQL file into the DB, replacing prefix and charset vars' );
41 $this->addArg(
42 'patch-name',
43 'Name of the patch file, either full path or in sql/$dbtype/'
44 );
45 }
46
48 public function getDbType() {
49 return Maintenance::DB_ADMIN;
50 }
51
52 public function execute() {
53 $dbw = $this->getDB( DB_PRIMARY );
54 $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
55
56 foreach ( $this->getArgs() as $name ) {
57 $files = [
58 $name,
59 $updater->patchPath( $dbw, $name ),
60 $updater->patchPath( $dbw, "patch-$name.sql" ),
61 ];
62 foreach ( $files as $file ) {
63 if ( file_exists( $file ) ) {
64 $this->output( "$file ...\n" );
65 $dbw->sourceFile( $file );
66 continue 2;
67 }
68 }
69 $this->error( "Could not find $name\n" );
70 }
71 $this->output( "done.\n" );
72 }
73}
74
75// @codeCoverageIgnoreStart
76$maintClass = PatchSql::class;
77require_once RUN_MAINTENANCE_IF_MAIN;
78// @codeCoverageIgnoreEnd
Apply database changes after updating MediaWiki.
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
getArgs( $offset=0)
Get arguments.
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
error( $err, $die=0)
Throw an error to the user.
addDescription( $text)
Set the description text.
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition patchSql.php:37
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition patchSql.php:48
__construct()
Default constructor.
Definition patchSql.php:38
execute()
Do the actual work.
Definition patchSql.php:52
$maintClass
Definition patchSql.php:76
const DB_PRIMARY
Definition defines.php:28