2013-01-23 01:16:24 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorSetupCheckDatabase extends PhabricatorSetupCheck {
|
|
|
|
|
|
|
|
public function getExecutionOrder() {
|
|
|
|
// This must run after basic PHP checks, but before most other checks.
|
|
|
|
return 0.5;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function executeChecks() {
|
|
|
|
$conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider');
|
|
|
|
$conn_user = $conf->getUser();
|
|
|
|
$conn_pass = $conf->getPassword();
|
|
|
|
$conn_host = $conf->getHost();
|
2013-07-15 01:02:12 +02:00
|
|
|
$conn_port = $conf->getPort();
|
2013-01-23 01:16:24 +01:00
|
|
|
|
|
|
|
ini_set('mysql.connect_timeout', 2);
|
|
|
|
|
2013-04-10 06:37:20 +02:00
|
|
|
$config = array(
|
|
|
|
'user' => $conn_user,
|
|
|
|
'pass' => $conn_pass,
|
|
|
|
'host' => $conn_host,
|
2013-07-15 01:02:12 +02:00
|
|
|
'port' => $conn_port,
|
2013-04-10 06:37:20 +02:00
|
|
|
'database' => null,
|
|
|
|
);
|
|
|
|
|
2013-01-23 01:16:24 +01:00
|
|
|
$conn_raw = PhabricatorEnv::newObjectFromConfig(
|
|
|
|
'mysql.implementation',
|
2013-04-10 06:37:20 +02:00
|
|
|
array($config));
|
2013-01-23 01:16:24 +01:00
|
|
|
|
|
|
|
try {
|
|
|
|
queryfx($conn_raw, 'SELECT 1');
|
2014-08-05 23:51:21 +02:00
|
|
|
} catch (AphrontConnectionQueryException $ex) {
|
2013-01-23 01:16:24 +01:00
|
|
|
$message = pht(
|
|
|
|
"Unable to connect to MySQL!\n\n".
|
|
|
|
"%s\n\n".
|
|
|
|
"Make sure Phabricator and MySQL are correctly configured.",
|
|
|
|
$ex->getMessage());
|
|
|
|
|
|
|
|
$this->newIssue('mysql.connect')
|
|
|
|
->setName(pht('Can Not Connect to MySQL'))
|
|
|
|
->setMessage($message)
|
|
|
|
->setIsFatal(true)
|
2013-04-10 22:10:52 +02:00
|
|
|
->addRelatedPhabricatorConfig('mysql.host')
|
2013-07-15 01:02:12 +02:00
|
|
|
->addRelatedPhabricatorConfig('mysql.port')
|
2013-04-10 22:10:52 +02:00
|
|
|
->addRelatedPhabricatorConfig('mysql.user')
|
|
|
|
->addRelatedPhabricatorConfig('mysql.pass');
|
2013-01-23 01:16:24 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$engines = queryfx_all($conn_raw, 'SHOW ENGINES');
|
|
|
|
$engines = ipull($engines, 'Support', 'Engine');
|
|
|
|
|
|
|
|
$innodb = idx($engines, 'InnoDB');
|
|
|
|
if ($innodb != 'YES' && $innodb != 'DEFAULT') {
|
|
|
|
$message = pht(
|
|
|
|
"The 'InnoDB' engine is not available in MySQL. Enable InnoDB in ".
|
|
|
|
"your MySQL configuration.".
|
|
|
|
"\n\n".
|
|
|
|
"(If you aleady created tables, MySQL incorrectly used some other ".
|
|
|
|
"engine to create them. You need to convert them or drop and ".
|
|
|
|
"reinitialize them.)");
|
|
|
|
|
|
|
|
$this->newIssue('mysql.innodb')
|
|
|
|
->setName(pht('MySQL InnoDB Engine Not Available'))
|
|
|
|
->setMessage($message)
|
|
|
|
->setIsFatal(true);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$namespace = PhabricatorEnv::getEnvConfig('storage.default-namespace');
|
|
|
|
|
|
|
|
$databases = queryfx_all($conn_raw, 'SHOW DATABASES');
|
|
|
|
$databases = ipull($databases, 'Database', 'Database');
|
|
|
|
|
|
|
|
if (empty($databases[$namespace.'_meta_data'])) {
|
|
|
|
$message = pht(
|
|
|
|
'Run the storage upgrade script to setup Phabricator\'s database '.
|
|
|
|
'schema.');
|
|
|
|
|
|
|
|
$this->newIssue('storage.upgrade')
|
|
|
|
->setName(pht('Setup MySQL Schema'))
|
|
|
|
->setMessage($message)
|
|
|
|
->setIsFatal(true)
|
2013-01-29 20:29:56 +01:00
|
|
|
->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade'));
|
2013-04-10 06:37:20 +02:00
|
|
|
} else {
|
|
|
|
|
|
|
|
$config['database'] = $namespace.'_meta_data';
|
|
|
|
$conn_meta = PhabricatorEnv::newObjectFromConfig(
|
|
|
|
'mysql.implementation',
|
|
|
|
array($config));
|
|
|
|
|
|
|
|
$applied = queryfx_all($conn_meta, 'SELECT patch FROM patch_status');
|
|
|
|
$applied = ipull($applied, 'patch', 'patch');
|
|
|
|
|
|
|
|
$all = PhabricatorSQLPatchList::buildAllPatches();
|
|
|
|
$diff = array_diff_key($all, $applied);
|
|
|
|
|
|
|
|
if ($diff) {
|
|
|
|
$this->newIssue('storage.patch')
|
|
|
|
->setName(pht('Upgrade MySQL Schema'))
|
|
|
|
->setMessage(pht(
|
|
|
|
"Run the storage upgrade script to upgrade Phabricator's database ".
|
2013-07-18 20:31:30 +02:00
|
|
|
"schema. Missing patches:<br />%s<br />",
|
|
|
|
phutil_implode_html(phutil_tag('br'), array_keys($diff))))
|
2013-04-10 06:37:20 +02:00
|
|
|
->addCommand(
|
|
|
|
hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade'));
|
|
|
|
}
|
2013-01-23 01:16:24 +01:00
|
|
|
}
|
2013-07-15 01:57:50 +02:00
|
|
|
|
|
|
|
|
|
|
|
$host = PhabricatorEnv::getEnvConfig('mysql.host');
|
|
|
|
$matches = null;
|
|
|
|
if (preg_match('/^([^:]+):(\d+)$/', $host, $matches)) {
|
|
|
|
$host = $matches[1];
|
|
|
|
$port = $matches[2];
|
|
|
|
|
|
|
|
$this->newIssue('storage.mysql.hostport')
|
|
|
|
->setName(pht('Deprecated mysql.host Format'))
|
|
|
|
->setSummary(
|
|
|
|
pht(
|
|
|
|
'Move port information from `mysql.host` to `mysql.port` in your '.
|
|
|
|
'config.'))
|
|
|
|
->setMessage(
|
|
|
|
pht(
|
|
|
|
'Your `mysql.host` configuration contains a port number, but '.
|
|
|
|
'this usage is deprecated. Instead, put the port number in '.
|
|
|
|
'`mysql.port`.'))
|
|
|
|
->addPhabricatorConfig('mysql.host')
|
|
|
|
->addPhabricatorConfig('mysql.port')
|
|
|
|
->addCommand(
|
|
|
|
hsprintf(
|
|
|
|
'<tt>phabricator/ $</tt> ./bin/config set mysql.host %s',
|
|
|
|
$host))
|
|
|
|
->addCommand(
|
|
|
|
hsprintf(
|
|
|
|
'<tt>phabricator/ $</tt> ./bin/config set mysql.port %s',
|
|
|
|
$port));
|
|
|
|
}
|
|
|
|
|
2013-01-23 01:16:24 +01:00
|
|
|
}
|
|
|
|
}
|