summaryrefslogtreecommitdiff
path: root/maintenance/sql.php
diff options
context:
space:
mode:
authorPierre Schmitz <pierre@archlinux.de>2015-12-17 09:15:42 +0100
committerPierre Schmitz <pierre@archlinux.de>2015-12-17 09:44:51 +0100
commita1789ddde42033f1b05cc4929491214ee6e79383 (patch)
tree63615735c4ddffaaabf2428946bb26f90899f7bf /maintenance/sql.php
parent9e06a62f265e3a2aaabecc598d4bc617e06fa32d (diff)
Update to MediaWiki 1.26.0
Diffstat (limited to 'maintenance/sql.php')
-rw-r--r--maintenance/sql.php33
1 files changed, 23 insertions, 10 deletions
diff --git a/maintenance/sql.php b/maintenance/sql.php
index 886e3f10..a93e51fe 100644
--- a/maintenance/sql.php
+++ b/maintenance/sql.php
@@ -32,7 +32,9 @@ require_once __DIR__ . '/Maintenance.php';
class MwSql extends Maintenance {
public function __construct() {
parent::__construct();
- $this->mDescription = "Send SQL queries to a MediaWiki database";
+ $this->mDescription = "Send SQL queries to a MediaWiki database. " .
+ "Takes a file name containing SQL as argument or runs interactively.";
+ $this->addOption( 'query', 'Run a single query instead of running interactively', false, true );
$this->addOption( 'cluster', 'Use an external cluster by name', false, true );
$this->addOption( 'wikidb', 'The database wiki ID to use if not the current one', false, true );
$this->addOption( 'slave', 'Use a slave server (either "any" or by name)', false, true );
@@ -88,6 +90,13 @@ class MwSql extends Maintenance {
}
}
+ if ( $this->hasOption( 'query' ) ) {
+ $query = $this->getOption( 'query' );
+ $this->sqlDoQuery( $db, $query, /* dieOnError */ true );
+ wfWaitForSlaves();
+ return;
+ }
+
$useReadline = function_exists( 'readline_add_history' )
&& Maintenance::posix_isatty( 0 /*STDIN*/ );
@@ -101,6 +110,7 @@ class MwSql extends Maintenance {
$wholeLine = '';
$newPrompt = '> ';
$prompt = $newPrompt;
+ $doDie = !Maintenance::posix_isatty( 0 );
while ( ( $line = Maintenance::readconsole( $prompt ) ) !== false ) {
if ( !$line ) {
# User simply pressed return key
@@ -121,19 +131,22 @@ class MwSql extends Maintenance {
readline_add_history( $wholeLine . $db->getDelimiter() );
readline_write_history( $historyFile );
}
- try {
- $res = $db->query( $wholeLine );
- $this->sqlPrintResult( $res, $db );
- $prompt = $newPrompt;
- $wholeLine = '';
- } catch ( DBQueryError $e ) {
- $doDie = !Maintenance::posix_isatty( 0 );
- $this->error( $e, $doDie );
- }
+ $this->sqlDoQuery( $db, $wholeLine, $doDie );
+ $prompt = $newPrompt;
+ $wholeLine = '';
}
wfWaitForSlaves();
}
+ protected function sqlDoQuery( $db, $line, $dieOnError ) {
+ try {
+ $res = $db->query( $line );
+ $this->sqlPrintResult( $res, $db );
+ } catch ( DBQueryError $e ) {
+ $this->error( $e, $dieOnError );
+ }
+ }
+
/**
* Print the results, callback for $db->sourceStream()
* @param ResultWrapper $res The results object