public function execute() { $dbw = wfGetDB(DB_MASTER); if ($this->hasArg()) { $fileName = $this->getArg(); $file = fopen($fileName, 'r'); if (!$file) { $this->error("Unable to open input file", true); } $error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult')); if ($error !== true) { $this->error($error, true); } else { exit(0); } } $useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0); if ($useReadline) { global $IP; $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history"; readline_read_history($historyFile); } $wholeLine = ''; $newPrompt = '> '; $prompt = $newPrompt; while (($line = Maintenance::readconsole($prompt)) !== false) { if (!$line) { # User simply pressed return key continue; } $done = $dbw->streamStatementEnd($wholeLine, $line); $wholeLine .= $line; if (!$done) { $wholeLine .= ' '; $prompt = ' -> '; continue; } if ($useReadline) { # Delimiter is eated by streamStatementEnd, we add it # up in the history (bug 37020) readline_add_history($wholeLine . $dbw->getDelimiter()); readline_write_history($historyFile); } try { $res = $dbw->query($wholeLine); $this->sqlPrintResult($res, $dbw); $prompt = $newPrompt; $wholeLine = ''; } catch (DBQueryError $e) { $doDie = !Maintenance::posix_isatty(0); $this->error($e, $doDie); } } }
public function execute() { $dbw = wfGetDB(DB_MASTER); if ($this->hasArg()) { $fileName = $this->getArg(); $file = fopen($fileName, 'r'); if (!$file) { $this->error("Unable to open input file", true); } $error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult')); if ($error !== true) { $this->error($error, true); } else { exit(0); } } $useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0); if ($useReadline) { global $IP; $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history"; readline_read_history($historyFile); } $wholeLine = ''; while (($line = Maintenance::readconsole()) !== false) { $done = $dbw->streamStatementEnd($wholeLine, $line); $wholeLine .= $line; if (!$done) { continue; } if ($useReadline) { readline_add_history($wholeLine); readline_write_history($historyFile); } try { $res = $dbw->query($wholeLine); $this->sqlPrintResult($res, $dbw); $wholeLine = ''; } catch (DBQueryError $e) { $this->error($e, true); } } }
public function execute() { $wiki = $this->getOption('wikidb') ?: false; // Get the appropriate load balancer (for this wiki) if ($this->hasOption('cluster')) { $lb = wfGetLBFactory()->getExternalLB($this->getOption('cluster'), $wiki); } else { $lb = wfGetLB($wiki); } // Figure out which server to use if ($this->hasOption('slave')) { $server = $this->getOption('slave'); if ($server === 'any') { $index = DB_SLAVE; } else { $index = null; for ($i = 0; $i < $lb->getServerCount(); ++$i) { if ($lb->getServerName($i) === $server) { $index = $i; break; } } if ($index === null) { $this->error("No slave server configured with the name '{$server}'.", 1); } } } else { $index = DB_MASTER; } // Get a DB handle (with this wiki's DB selected) from the appropriate load balancer $db = $lb->getConnection($index, array(), $wiki); if ($this->hasOption('slave') && $db->getLBInfo('master') !== null) { $this->error("The server selected ({$db->getServer()}) is not a slave.", 1); } if ($this->hasArg(0)) { $file = fopen($this->getArg(0), 'r'); if (!$file) { $this->error("Unable to open input file", true); } $error = $db->sourceStream($file, false, array($this, 'sqlPrintResult')); if ($error !== true) { $this->error($error, true); } else { exit(0); } } $useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0); if ($useReadline) { global $IP; $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history"; readline_read_history($historyFile); } $wholeLine = ''; $newPrompt = '> '; $prompt = $newPrompt; while (($line = Maintenance::readconsole($prompt)) !== false) { if (!$line) { # User simply pressed return key continue; } $done = $db->streamStatementEnd($wholeLine, $line); $wholeLine .= $line; if (!$done) { $wholeLine .= ' '; $prompt = ' -> '; continue; } if ($useReadline) { # Delimiter is eated by streamStatementEnd, we add it # up in the history (bug 37020) 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); } } wfWaitForSlaves(); }
$serverCount = $lb->getServerCount(); for ($i = 0; $i < $serverCount; $i++) { $server = $lb->getServerInfo($i); $server['flags'] |= DBO_DEBUG; $lb->setServerInfo($i, $server); } } if ($d > 2) { $wgDebugFunctionEntry = true; } } $useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0); if ($useReadline) { $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mweval_history" : "{$IP}/maintenance/.mweval_history"; readline_read_history($historyFile); } while (($line = Maintenance::readconsole()) !== false) { if ($useReadline) { readline_add_history($line); readline_write_history($historyFile); } $val = eval($line . ";"); if (wfIsHipHop() || is_null($val)) { echo "\n"; } elseif (is_string($val) || is_numeric($val)) { echo "{$val}\n"; } else { var_dump($val); } } print "\n";
public function execute() { // Get a DB handle (with this wiki's DB select) from the appropriate load balancer if ($this->hasOption('cluster')) { $lb = wfGetLBFactory()->getExternalLB($this->getOption('cluster')); $dbw = $lb->getConnection(DB_MASTER); // master for external LB } else { $dbw = wfGetDB(DB_MASTER); // master for primary LB for this wiki } if ($this->hasArg(0)) { $file = fopen($this->getArg(0), 'r'); if (!$file) { $this->error("Unable to open input file", true); } $error = $dbw->sourceStream($file, false, array($this, 'sqlPrintResult')); if ($error !== true) { $this->error($error, true); } else { exit(0); } } $useReadline = function_exists('readline_add_history') && Maintenance::posix_isatty(0); if ($useReadline) { global $IP; $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history"; readline_read_history($historyFile); } $wholeLine = ''; $newPrompt = '> '; $prompt = $newPrompt; while (($line = Maintenance::readconsole($prompt)) !== false) { if (!$line) { # User simply pressed return key continue; } $done = $dbw->streamStatementEnd($wholeLine, $line); $wholeLine .= $line; if (!$done) { $wholeLine .= ' '; $prompt = ' -> '; continue; } if ($useReadline) { # Delimiter is eated by streamStatementEnd, we add it # up in the history (bug 37020) readline_add_history($wholeLine . $dbw->getDelimiter()); readline_write_history($historyFile); } try { $res = $dbw->query($wholeLine); $this->sqlPrintResult($res, $dbw); $prompt = $newPrompt; $wholeLine = ''; } catch (DBQueryError $e) { $doDie = !Maintenance::posix_isatty(0); $this->error($e, $doDie); } } wfWaitForSlaves(); }
if ($command === 'fullhelp') { $max_cmd_len = max(array_map('strlen', array_keys($commandList))); foreach ($commandList as $cmd => $desc) { printf("%-{$max_cmd_len}s: %s\n", $cmd, $desc); } } elseif (isset($commandList[$command])) { print "{$command}: {$commandList[$command]}\n"; } else { print "{$command}: command does not exist or no help for it\n"; } } do { $bad = false; $showhelp = false; $quit = false; $line = Maintenance::readconsole(); if ($line === false) { exit; } $args = explode(' ', $line); $command = array_shift($args); // process command switch ($command) { case 'help': // show an help message mccShowHelp(array_shift($args)); break; case 'get': $sub = ''; if (array_key_exists(1, $args)) { $sub = $args[1];
public function execute() { global $IP; // We wan't to allow "" for the wikidb, meaning don't call select_db() $wiki = $this->hasOption('wikidb') ? $this->getOption('wikidb') : false; // Get the appropriate load balancer (for this wiki) if ($this->hasOption('cluster')) { $lb = wfGetLBFactory()->getExternalLB($this->getOption('cluster'), $wiki); } else { $lb = wfGetLB($wiki); } // Figure out which server to use $replicaDB = $this->getOption('replicadb', $this->getOption('slave', '')); if ($replicaDB === 'any') { $index = DB_REPLICA; } elseif ($replicaDB != '') { $index = null; $serverCount = $lb->getServerCount(); for ($i = 0; $i < $serverCount; ++$i) { if ($lb->getServerName($i) === $replicaDB) { $index = $i; break; } } if ($index === null) { $this->error("No replica DB server configured with the name '{$replicaDB}'.", 1); } } else { $index = DB_MASTER; } /** @var Database $db DB handle for the appropriate cluster/wiki */ $db = $lb->getConnection($index, [], $wiki); if ($replicaDB != '' && $db->getLBInfo('master') !== null) { $this->error("The server selected ({$db->getServer()}) is not a replica DB.", 1); } if ($index === DB_MASTER) { $updater = DatabaseUpdater::newForDB($db, true, $this); $db->setSchemaVars($updater->getSchemaVars()); } if ($this->hasArg(0)) { $file = fopen($this->getArg(0), 'r'); if (!$file) { $this->error("Unable to open input file", true); } $error = $db->sourceStream($file, null, [$this, 'sqlPrintResult']); if ($error !== true) { $this->error($error, true); } else { exit(0); } } if ($this->hasOption('query')) { $query = $this->getOption('query'); $this->sqlDoQuery($db, $query, true); wfWaitForSlaves(); return; } if (function_exists('readline_add_history') && Maintenance::posix_isatty(0)) { $historyFile = isset($_ENV['HOME']) ? "{$_ENV['HOME']}/.mwsql_history" : "{$IP}/maintenance/.mwsql_history"; readline_read_history($historyFile); } else { $historyFile = null; } $wholeLine = ''; $newPrompt = '> '; $prompt = $newPrompt; $doDie = !Maintenance::posix_isatty(0); while (($line = Maintenance::readconsole($prompt)) !== false) { if (!$line) { # User simply pressed return key continue; } $done = $db->streamStatementEnd($wholeLine, $line); $wholeLine .= $line; if (!$done) { $wholeLine .= ' '; $prompt = ' -> '; continue; } if ($historyFile) { # Delimiter is eated by streamStatementEnd, we add it # up in the history (bug 37020) readline_add_history($wholeLine . ';'); readline_write_history($historyFile); } $this->sqlDoQuery($db, $wholeLine, $doDie); $prompt = $newPrompt; $wholeLine = ''; } wfWaitForSlaves(); }