MediaWiki REL1_39
patchSql.php
Go to the documentation of this file.
1<?php
25require_once __DIR__ . '/Maintenance.php';
26
32class PatchSql extends Maintenance {
33 public function __construct() {
34 parent::__construct();
35 $this->addDescription( 'Run an SQL file into the DB, replacing prefix and charset vars' );
36 $this->addArg(
37 'patch-name',
38 'Name of the patch file, either full path or in maintenance/archives'
39 );
40 }
41
42 public function getDbType() {
44 }
45
46 public function execute() {
47 $dbw = $this->getDB( DB_PRIMARY );
48 $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
49
50 foreach ( $this->mArgs as $arg ) {
51 $files = [
52 $arg,
53 $updater->patchPath( $dbw, $arg ),
54 $updater->patchPath( $dbw, "patch-$arg.sql" ),
55 ];
56 foreach ( $files as $file ) {
57 if ( file_exists( $file ) ) {
58 $this->output( "$file ...\n" );
59 $dbw->sourceFile( $file );
60 continue 2;
61 }
62 }
63 $this->error( "Could not find $arg\n" );
64 }
65 $this->output( "done.\n" );
66 }
67}
68
69$maintClass = PatchSql::class;
70require_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)
Add some args that are needed.
output( $out, $channel=null)
Throw some output 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:32
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition patchSql.php:42
__construct()
Default constructor.
Definition patchSql.php:33
execute()
Do the actual work.
Definition patchSql.php:46
$maintClass
Definition patchSql.php:69
const DB_PRIMARY
Definition defines.php:28
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition router.php:42