예제 #1
0
파일: sql.php 프로젝트: seedbank/old-repo
 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);
         }
     }
 }
예제 #2
0
 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();
 }
예제 #3
0
파일: eval.php 프로젝트: mangowi/mediawiki
        $wgDebugLogFile = '/dev/stdout';
    }
    if ($d > 1) {
        $lb = wfGetLB();
        $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 {
예제 #4
0
파일: sql.php 프로젝트: mangowi/mediawiki
 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();
 }
예제 #5
0
 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);
         }
     }
 }
예제 #6
0
파일: sql.php 프로젝트: paladox/mediawiki
 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();
 }
예제 #7
0
 public function execute()
 {
     global $wgParserTestFiles, $wgDBtype;
     // Cases of weird db corruption were encountered when running tests on earlyish
     // versions of SQLite
     if ($wgDBtype == 'sqlite') {
         $db = wfGetDB(DB_MASTER);
         $version = $db->getServerVersion();
         if (version_compare($version, '3.6') < 0) {
             die("Parser tests require SQLite version 3.6 or later, you have {$version}\n");
         }
     }
     // Print out software version to assist with locating regressions
     $version = SpecialVersion::getVersion('nodb');
     echo "This is MediaWiki version {$version}.\n\n";
     // Only colorize output if stdout is a terminal.
     $color = !wfIsWindows() && Maintenance::posix_isatty(1);
     if ($this->hasOption('color')) {
         switch ($this->getOption('color')) {
             case 'no':
                 $color = false;
                 break;
             case 'yes':
             default:
                 $color = true;
                 break;
         }
     }
     $record = $this->hasOption('record');
     $compare = $this->hasOption('compare');
     $regex = $this->getOption('filter', $this->getOption('regex', false));
     if ($regex !== false) {
         $regex = "/{$regex}/i";
         if ($record) {
             echo "Warning: --record cannot be used with --regex, disabling --record\n";
             $record = false;
         }
     }
     $term = $color ? new AnsiTermColorer() : new DummyTermColorer();
     $recorder = new MultiTestRecorder();
     $recorder->addRecorder(new ParserTestPrinter($term, ['showDiffs' => !$this->hasOption('quick'), 'showProgress' => !$this->hasOption('quiet'), 'showFailure' => !$this->hasOption('quiet') || !$record && !$compare, 'showOutput' => $this->hasOption('show-output'), 'useDwdiff' => $this->hasOption('dwdiff'), 'markWhitespace' => $this->hasOption('mark-ws')]));
     $recorderLB = false;
     if ($record || $compare) {
         $recorderLB = wfGetLBFactory()->newMainLB();
         // This connection will have the wiki's table prefix, not parsertest_
         $recorderDB = $recorderLB->getConnection(DB_MASTER);
         // Add recorder before previewer because recorder will create the
         // DB table if it doesn't exist
         if ($record) {
             $recorder->addRecorder(new DbTestRecorder($recorderDB));
         }
         $recorder->addRecorder(new DbTestPreviewer($recorderDB, function ($name) use($regex) {
             // Filter reports of old tests by the filter regex
             if ($regex === false) {
                 return true;
             } else {
                 return (bool) preg_match($regex, $name);
             }
         }));
     }
     // Default parser tests and any set from extensions or local config
     $files = $this->getOption('file', $wgParserTestFiles);
     $norm = $this->hasOption('norm') ? explode(',', $this->getOption('norm')) : [];
     $tester = new ParserTestRunner($recorder, ['norm' => $norm, 'regex' => $regex, 'keep-uploads' => $this->hasOption('keep-uploads'), 'run-disabled' => $this->hasOption('run-disabled'), 'run-parsoid' => $this->hasOption('run-parsoid'), 'use-tidy-config' => $this->hasOption('use-tidy-config'), 'file-backend' => $this->getOption('file-backend'), 'upload-dir' => $this->getOption('upload-dir')]);
     $ok = $tester->runTestsFromFiles($files);
     if ($recorderLB) {
         $recorderLB->closeAll();
     }
     if (!$ok) {
         exit(1);
     }
 }