MediaWiki master
patchSql.php
Go to the documentation of this file.
1<?php
26
27require_once __DIR__ . '/Maintenance.php';
28
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() {
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;
getDB()
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
error( $err, $die=0)
Throw an error to the user.
addArg( $arg, $description, $required=true, $multi=false)
Add some args that are needed.
getArgs( $offset=0)
Get arguments.
output( $out, $channel=null)
Throw some output to the user.
addDescription( $text)
Set the description text.
Class for handling database updates.
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition patchSql.php:34
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition patchSql.php:44
__construct()
Default constructor.
Definition patchSql.php:35
execute()
Do the actual work.
Definition patchSql.php:48
$maintClass
Definition patchSql.php:71
const DB_PRIMARY
Definition defines.php:28