MediaWiki  1.34.0
patchSql.php
Go to the documentation of this file.
1 <?php
25 require_once __DIR__ . '/Maintenance.php';
26 
32 class 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() {
43  return Maintenance::DB_ADMIN;
44  }
45 
46  public function execute() {
47  $dbw = $this->getDB( DB_MASTER );
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;
70 require_once RUN_MAINTENANCE_IF_MAIN;
RUN_MAINTENANCE_IF_MAIN
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
DatabaseUpdater\newForDB
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
Definition: DatabaseUpdater.php:191
Maintenance\addDescription
addDescription( $text)
Set the description text.
Definition: Maintenance.php:348
PatchSql
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition: patchSql.php:32
$file
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
PatchSql\execute
execute()
Do the actual work.
Definition: patchSql.php:46
Maintenance
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:82
DB_MASTER
const DB_MASTER
Definition: defines.php:26
Maintenance\DB_ADMIN
const DB_ADMIN
Definition: Maintenance.php:89
Maintenance\getDB
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
Definition: Maintenance.php:1396
Maintenance\addArg
addArg( $arg, $description, $required=true)
Add some args that are needed.
Definition: Maintenance.php:319
Maintenance\error
error( $err, $die=0)
Throw an error to the user.
Definition: Maintenance.php:481
Maintenance\output
output( $out, $channel=null)
Throw some output to the user.
Definition: Maintenance.php:453
PatchSql\getDbType
getDbType()
Does the script need different DB access? By default, we give Maintenance scripts normal rights to th...
Definition: patchSql.php:42
$maintClass
$maintClass
Definition: patchSql.php:69
PatchSql\__construct
__construct()
Default constructor.
Definition: patchSql.php:33