MediaWiki master
patchSql.php
Go to the documentation of this file.
1<?php
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
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:23
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition patchSql.php:34
__construct()
Default constructor.
Definition patchSql.php:24
execute()
Do the actual work.
Definition patchSql.php:38
$maintClass
Definition patchSql.php:62