Changeset View
Changeset View
Standalone View
Standalone View
src/applications/config/check/PhabricatorDatabaseSetupCheck.php
<?php | <?php | ||||
final class PhabricatorDatabaseSetupCheck extends PhabricatorSetupCheck { | final class PhabricatorDatabaseSetupCheck extends PhabricatorSetupCheck { | ||||
public function getDefaultGroup() { | public function getDefaultGroup() { | ||||
return self::GROUP_IMPORTANT; | return self::GROUP_IMPORTANT; | ||||
} | } | ||||
public function getExecutionOrder() { | public function getExecutionOrder() { | ||||
// This must run after basic PHP checks, but before most other checks. | // This must run after basic PHP checks, but before most other checks. | ||||
return 0.5; | return 0.5; | ||||
} | } | ||||
protected function executeChecks() { | protected function executeChecks() { | ||||
$conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider'); | $master = PhabricatorDatabaseRef::getMasterDatabaseRef(); | ||||
$conn_user = $conf->getUser(); | if (!$master) { | ||||
$conn_pass = $conf->getPassword(); | // If we're implicitly in read-only mode during disaster recovery, | ||||
$conn_host = $conf->getHost(); | // don't bother with these setup checks. | ||||
$conn_port = $conf->getPort(); | return; | ||||
} | |||||
ini_set('mysql.connect_timeout', 2); | |||||
$conn_raw = $master->newManagementConnection(); | |||||
$config = array( | |||||
'user' => $conn_user, | |||||
'pass' => $conn_pass, | |||||
'host' => $conn_host, | |||||
'port' => $conn_port, | |||||
'database' => null, | |||||
); | |||||
$conn_raw = PhabricatorEnv::newObjectFromConfig( | |||||
'mysql.implementation', | |||||
array($config)); | |||||
try { | try { | ||||
queryfx($conn_raw, 'SELECT 1'); | queryfx($conn_raw, 'SELECT 1'); | ||||
} catch (AphrontConnectionQueryException $ex) { | } catch (AphrontConnectionQueryException $ex) { | ||||
$message = pht( | $message = pht( | ||||
"Unable to connect to MySQL!\n\n". | "Unable to connect to MySQL!\n\n". | ||||
"%s\n\n". | "%s\n\n". | ||||
"Make sure Phabricator and MySQL are correctly configured.", | "Make sure Phabricator and MySQL are correctly configured.", | ||||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | if (empty($databases[$namespace.'_meta_data'])) { | ||||
"schema."); | "schema."); | ||||
$this->newIssue('storage.upgrade') | $this->newIssue('storage.upgrade') | ||||
->setName(pht('Setup MySQL Schema')) | ->setName(pht('Setup MySQL Schema')) | ||||
->setMessage($message) | ->setMessage($message) | ||||
->setIsFatal(true) | ->setIsFatal(true) | ||||
->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); | ->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); | ||||
} else { | } else { | ||||
$conn_meta = $master->newApplicationConnection( | |||||
$config['database'] = $namespace.'_meta_data'; | $namespace.'_meta_data'); | ||||
$conn_meta = PhabricatorEnv::newObjectFromConfig( | |||||
'mysql.implementation', | |||||
array($config)); | |||||
$applied = queryfx_all($conn_meta, 'SELECT patch FROM patch_status'); | $applied = queryfx_all($conn_meta, 'SELECT patch FROM patch_status'); | ||||
$applied = ipull($applied, 'patch', 'patch'); | $applied = ipull($applied, 'patch', 'patch'); | ||||
$all = PhabricatorSQLPatchList::buildAllPatches(); | $all = PhabricatorSQLPatchList::buildAllPatches(); | ||||
$diff = array_diff_key($all, $applied); | $diff = array_diff_key($all, $applied); | ||||
if ($diff) { | if ($diff) { | ||||
$this->newIssue('storage.patch') | $this->newIssue('storage.patch') | ||||
->setName(pht('Upgrade MySQL Schema')) | ->setName(pht('Upgrade MySQL Schema')) | ||||
->setMessage( | ->setMessage( | ||||
pht( | pht( | ||||
"Run the storage upgrade script to upgrade Phabricator's ". | "Run the storage upgrade script to upgrade Phabricator's ". | ||||
"database schema. Missing patches:<br />%s<br />", | "database schema. Missing patches:<br />%s<br />", | ||||
phutil_implode_html(phutil_tag('br'), array_keys($diff)))) | phutil_implode_html(phutil_tag('br'), array_keys($diff)))) | ||||
->addCommand( | ->addCommand( | ||||
hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); | hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade')); | ||||
} | } | ||||
} | } | ||||
$host = PhabricatorEnv::getEnvConfig('mysql.host'); | $host = PhabricatorEnv::getEnvConfig('mysql.host'); | ||||
$matches = null; | $matches = null; | ||||
if (preg_match('/^([^:]+):(\d+)$/', $host, $matches)) { | if (preg_match('/^([^:]+):(\d+)$/', $host, $matches)) { | ||||
$host = $matches[1]; | $host = $matches[1]; | ||||
$port = $matches[2]; | $port = $matches[2]; | ||||
$this->newIssue('storage.mysql.hostport') | $this->newIssue('storage.mysql.hostport') | ||||
->setName(pht('Deprecated mysql.host Format')) | ->setName(pht('Deprecated mysql.host Format')) | ||||
Show All 25 Lines |