| 1 |
<?php |
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
use MediaWiki\Installer\DatabaseUpdater; |
| 26 |
|
| 27 |
|
| 28 |
require_once __DIR__ . '/Maintenance.php'; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
class 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 |
|
| 74 |
$maintClass = PatchSql::class; |
| 75 |
require_once RUN_MAINTENANCE_IF_MAIN; |
| 76 |
|