X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=maintenance%2Fsql.php;h=a93e51fe5ace013278f008702b46dac388a35c18;hb=f796dbb59df851dca0d71de72d4a136cd716ece7;hp=82eae21642b18ffa1e843ea5eedf7740531bef66;hpb=7f1df682b62457e267831ec6527ca4728723caef;p=lhc%2Fweb%2Fwiklou.git diff --git a/maintenance/sql.php b/maintenance/sql.php index 82eae21642..a93e51fe5a 100644 --- a/maintenance/sql.php +++ b/maintenance/sql.php @@ -34,6 +34,7 @@ class MwSql extends Maintenance { parent::__construct(); $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 ); @@ -89,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*/ ); @@ -102,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 @@ -122,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