MediaWiki  master
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;
if(PHP_SAPI !='cli-server') if(!isset( $_SERVER['SCRIPT_FILENAME'])) $file
Item class for a filearchive table row.
Definition: router.php:42
const RUN_MAINTENANCE_IF_MAIN
Definition: Maintenance.php:39
error( $err, $die=0)
Throw an error to the user.
getDbType()
Definition: patchSql.php:42
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:86
execute()
Definition: patchSql.php:46
const DB_MASTER
Definition: defines.php:26
$maintClass
Definition: patchSql.php:69
addDescription( $text)
Set the description text.
const DB_ADMIN
Definition: Maintenance.php:93
addArg( $arg, $description, $required=true)
Add some args that are needed.
output( $out, $channel=null)
Throw some output to the user.
Maintenance script that manually runs an SQL patch outside of the general updaters.
Definition: patchSql.php:32
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
__construct()
Definition: patchSql.php:33
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.