25require_once __DIR__ .
'/Maintenance.php';
39 parent::__construct();
40 $this->
addDescription(
'Send SQL queries to a MediaWiki database. ' .
41 'Takes a file name containing SQL as argument or runs interactively.' );
43 'Run a single query instead of running interactively',
false,
true );
44 $this->
addOption(
'json',
'Output the results as JSON instead of PHP objects' );
45 $this->
addOption(
'status',
'Return successful exit status only if the query succeeded '
46 .
'(selected or altered rows), otherwise 1 for errors, 2 for no rows' );
47 $this->
addOption(
'cluster',
'Use an external cluster by name',
false,
true );
49 'The database wiki ID to use if not the current one',
false,
true );
51 'Replica DB server to use instead of the master DB (can be "any")',
false,
true );
60 $lbFactory = MediaWikiServices::getInstance()->getDBLoadBalancerFactory();
62 $lb = $lbFactory->getExternalLB( $this->
getOption(
'cluster' ) );
64 $lb = $lbFactory->getMainLB( $wiki );
68 if ( $replicaDB ===
'any' ) {
70 }
elseif ( $replicaDB !=
'' ) {
72 $serverCount = $lb->getServerCount();
74 if ( $lb->getServerName( $i ) === $replicaDB ) {
79 if ( $index ===
null ) {
80 $this->
fatalError(
"No replica DB server configured with the name '$replicaDB'." );
87 $db = $lb->getConnection( $index, [], $wiki );
88 if ( $replicaDB !=
'' && $db->getLBInfo(
'master' ) !==
null ) {
89 $this->
fatalError(
"The server selected ({$db->getServer()}) is not a replica DB." );
94 $db->setSchemaVars(
$updater->getSchemaVars() );
97 if ( $this->
hasArg( 0 ) ) {
100 $this->
fatalError(
"Unable to open input file" );
103 $error = $db->sourceStream( $file,
null, [ $this,
'sqlPrintResult' ] );
104 if ( $error !==
true ) {
125 $historyFile =
isset( $_ENV[
'HOME'] ) ?
126 "{$_ENV['HOME']}/.mwsql_history" :
"$IP/maintenance/.mwsql_history";
139 # User simply pressed return key
142 $done = $db->streamStatementEnd( $wholeLine,
$line );
151 if ( $historyFile ) {
152 # Delimiter is eated by streamStatementEnd, we add it
153 # up in the history (T39020)
200 foreach (
$res as $row ) {
207 $out =
'Query OK, 0 row(s) affected';
210 return count(
$rows );
212 $affected = $db->affectedRows();
214 $this->
output(
json_encode( [
'affected' => $affected ], JSON_PRETTY_PRINT ) .
"\n" );
216 $this->
output(
"Query OK, $affected row(s) affected\n" );
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two and(2) offer you this license which gives you legal permission to copy
wfWaitForSlaves( $ifWritesSince=null, $wiki=false, $cluster=false, $timeout=null)
Waits for the replica DBs to catch up to the master position.
static newForDB(IMaintainableDatabase $db, $shared=false, Maintenance $maintenance=null)
Abstract maintenance class for quickly writing and churning out maintenance scripts with minimal effo...
output( $out, $channel=null)
Throw some output to the user.
hasArg( $argId=0)
Does a given argument exist?
hasOption( $name)
Checks to see if a particular option exists.
static readconsole( $prompt='> ')
Prompt the console for input.
static posix_isatty( $fd)
Wrapper for posix_isatty() We default as considering stdin a tty (for nice readline methods) but trea...
getArg( $argId=0, $default=null)
Get an argument.
addDescription( $text)
Set the description text.
addOption( $name, $description, $required=false, $withArg=false, $shortName=false, $multiOccurrence=false)
Add a parameter to the script.
getOption( $name, $default=null)
Get an option, or return the default.
fatalError( $msg, $exitCode=1)
Output a message and terminate the current script.
Maintenance script that sends SQL queries from the specified file to the database.
sqlPrintResult( $res, $db)
Print the results, callback for $db->sourceStream()
__construct()
Default constructor.
sqlDoQuery(IDatabase $db, $line, $dieOnError)
execute()
Do the actual work.
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults also a ContextSource after deleting those rows but within the same transaction $rows
this hook is for auditing only or null if authentication failed before getting that far or null if we can t even determine that When $user is not it can be in the form of< username >< more info > e g for bot passwords intended to be added to log contexts Fields it might only if the login was with a bot password it is not rendered in wiki pages or galleries in category pages allow injecting custom HTML after the section Any uses of the hook need to handle escaping see BaseTemplate::getToolbox and BaseTemplate::makeListItem for details on the format of individual items inside of this array or by returning and letting standard HTTP rendering take place modifiable or by returning false and taking over the output $out
do that in ParserLimitReportFormat instead use this to modify the parameters of the image all existing parser cache entries will be invalid To avoid you ll need to handle that somehow(e.g. with the RejectParserCacheValue hook) because MediaWiki won 't do it for you. & $defaults error
null for the local wiki Added should default to null in handler for backwards compatibility add a value to it if you want to add a cookie that have to vary cache options can modify $query
returning false will NOT prevent logging $e
require_once RUN_MAINTENANCE_IF_MAIN
$page->newPageUpdater($user) $updater