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
47 public function getDbType() {
48 return Maintenance::DB_ADMIN;
49 }
50
51 public function execute() {
52 $dbw = $this->getDB( DB_PRIMARY );
53 $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
54
55 foreach ( $this->getArgs() as $name ) {
56 $files = [
57 $name,
58 $updater->patchPath( $dbw, $name ),
59 $updater->patchPath( $dbw, "patch-$name.sql" ),
60 ];
61 foreach ( $files as $file ) {
62 if ( file_exists( $file ) ) {
63 $this->output( "$file ...\n" );
64 $dbw->sourceFile( $file );
65 continue 2;
66 }
67 }
68 $this->error( "Could not find $name\n" );
69 }
70 $this->output( "done.\n" );
71 }
72}
73
74// @codeCoverageIgnoreStart
75$maintClass = PatchSql::class;
76require_once RUN_MAINTENANCE_IF_MAIN;
77// @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:47
__construct()
Default constructor.
Definition patchSql.php:38
execute()
Do the actual work.
Definition patchSql.php:51
$maintClass
Definition patchSql.php:75
const DB_PRIMARY
Definition defines.php:28