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_PRIMARY );
48  $updater = DatabaseUpdater::newForDB( $dbw, true, $this );
49 
50  foreach ( $this->getArgs() as $name ) {
51  $files = [
52  $name,
53  $updater->patchPath( $dbw, $name ),
54  $updater->patchPath( $dbw, "patch-$name.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 $name\n" );
64  }
65  $this->output( "done.\n" );
66  }
67 }
68 
69 $maintClass = PatchSql::class;
70 require_once RUN_MAINTENANCE_IF_MAIN;
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
Definition: Maintenance.php:66
getDB( $db, $groups=[], $dbDomain=false)
Returns a database to be used by current maintenance script.
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.
const DB_ADMIN
Definition: Maintenance.php:73
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