/** * @return string|null When string, "skip" or "continue" */ public function execute() { if ($this->getVar('_ExistingDBSettings')) { return 'skip'; } $r = $this->parent->request; if ($r->wasPosted()) { $status = $this->submit(); if ($status->isGood()) { $this->setVar('_UpgradeDone', false); return 'continue'; } else { $this->parent->showStatusBox($status); } } $this->startForm(); $types = "<ul class=\"config-settings-block\">\n"; $settings = ''; $defaultType = $this->getVar('wgDBtype'); // Messages: config-dbsupport-mysql, config-dbsupport-postgres, config-dbsupport-oracle, // config-dbsupport-sqlite, config-dbsupport-mssql $dbSupport = ''; foreach (Installer::getDBTypes() as $type) { $dbSupport .= wfMessage("config-dbsupport-{$type}")->plain() . "\n"; } $this->addHTML($this->parent->getInfoBox(wfMessage('config-support-info', trim($dbSupport))->text())); // It's possible that the library for the default DB type is not compiled in. // In that case, instead select the first supported DB type in the list. $compiledDBs = $this->parent->getCompiledDBs(); if (!in_array($defaultType, $compiledDBs)) { $defaultType = $compiledDBs[0]; } foreach ($compiledDBs as $type) { $installer = $this->parent->getDBInstaller($type); $types .= '<li>' . Xml::radioLabel($installer->getReadableName(), 'DBType', $type, "DBType_{$type}", $type == $defaultType, array('class' => 'dbRadio', 'rel' => "DB_wrapper_{$type}")) . "</li>\n"; // Messages: config-header-mysql, config-header-postgres, config-header-oracle, // config-header-sqlite $settings .= Html::openElement('div', array('id' => 'DB_wrapper_' . $type, 'class' => 'dbWrapper')) . Html::element('h3', array(), wfMessage('config-header-' . $type)->text()) . $installer->getConnectForm() . "</div>\n"; } $types .= "</ul><br style=\"clear: left\"/>\n"; $this->addHTML($this->parent->label('config-db-type', false, $types) . $settings); $this->endForm(); return null; }
/** * Initiate an upgrade of the existing database * * @param mixed[] $vars Variables from LocalSettings.php * * @return Status */ protected function handleExistingUpgrade($vars) { // Check $wgDBtype if (!isset($vars['wgDBtype']) || !in_array($vars['wgDBtype'], Installer::getDBTypes())) { return Status::newFatal('config-localsettings-connection-error', ''); } // Set the relevant variables from LocalSettings.php $requiredVars = ['wgDBtype']; $status = $this->importVariables($requiredVars, $vars); $installer = $this->parent->getDBInstaller(); $status->merge($this->importVariables($installer->getGlobalNames(), $vars)); if (!$status->isOK()) { return $status; } if (isset($vars['wgDBadminuser'])) { $this->setVar('_InstallUser', $vars['wgDBadminuser']); } else { $this->setVar('_InstallUser', $vars['wgDBuser']); } if (isset($vars['wgDBadminpassword'])) { $this->setVar('_InstallPassword', $vars['wgDBadminpassword']); } else { $this->setVar('_InstallPassword', $vars['wgDBpassword']); } // Test the database connection $status = $installer->getConnection(); if (!$status->isOK()) { // Adjust the error message to explain things correctly $status->replaceMessage('config-connection-error', 'config-localsettings-connection-error'); return $status; } // All good $this->setVar('_ExistingDBSettings', true); // Copy $wgAuthenticationTokenVersion too, if it exists $this->setVar('wgAuthenticationTokenVersion', isset($vars['wgAuthenticationTokenVersion']) ? $vars['wgAuthenticationTokenVersion'] : null); return $status; }
/** * @param DatabaseBase $db * @param bool $shared * @param Maintenance $maintenance * * @throws MWException * @return DatabaseUpdater */ public static function newForDB(&$db, $shared = false, $maintenance = null) { $type = $db->getType(); if (in_array($type, Installer::getDBTypes())) { $class = ucfirst($type) . 'Updater'; return new $class($db, $shared, $maintenance); } else { throw new MWException(__METHOD__ . ' called for unsupported $wgDBtype'); } }