MediaWiki 1.43.1
patchSql.php
Go to the documentation of this file.
1<?php
26
27// @codeCoverageIgnoreStart
28require_once __DIR__ . '/Maintenance.php';
29// @codeCoverageIgnoreEnd
30
36class PatchSql extends Maintenance {
37 public function __construct() {
38 parent::__construct();
39 $this->addDescription( 'Run an SQL file into the DB, replacing prefix and charset vars' );
40 $this->addArg(
41 'patch-name',
42 'Name of the patch file, either full path or in maintenance/archives'
43 );
44 }
45
46 public function getDbType() {
47 return Maintenance::DB_ADMIN;
48 }
49
50 public function execute() {
51 $dbw = $this->getDB( DB_PRIMARY );
52 $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
53
54 foreach ( $this->getArgs() as $name ) {
55 $files = [
56 $name,
57 $updater->patchPath( $dbw, $name ),
58 $updater->patchPath( $dbw, "patch-$name.sql" ),
59 ];
60 foreach ( $files as $file ) {
61 if ( file_exists( $file ) ) {
62 $this->output( "$file ...\n" );
63 $dbw->sourceFile( $file );
64 continue 2;
65 }
66 }
67 $this->error( "Could not find $name\n" );
68 }
69 $this->output( "done.\n" );
70 }
71}
72
73// @codeCoverageIgnoreStart
74$maintClass = PatchSql::class;
75require_once RUN_MAINTENANCE_IF_MAIN;
76// @codeCoverageIgnoreEnd
Class for handling database updates.
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition patchSql.php:36
getDbType()
Definition patchSql.php:46
__construct()
Definition patchSql.php:37
$maintClass
Definition patchSql.php:74
const DB_PRIMARY
Definition defines.php:28