[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/config/check/ -> PhabricatorSetupCheckDatabase.php (source)

   1  <?php
   2  
   3  final class PhabricatorSetupCheckDatabase extends PhabricatorSetupCheck {
   4  
   5    public function getExecutionOrder() {
   6      // This must run after basic PHP checks, but before most other checks.
   7      return 0.5;
   8    }
   9  
  10    protected function executeChecks() {
  11      $conf = PhabricatorEnv::newObjectFromConfig('mysql.configuration-provider');
  12      $conn_user = $conf->getUser();
  13      $conn_pass = $conf->getPassword();
  14      $conn_host = $conf->getHost();
  15      $conn_port = $conf->getPort();
  16  
  17      ini_set('mysql.connect_timeout', 2);
  18  
  19      $config = array(
  20        'user'      => $conn_user,
  21        'pass'      => $conn_pass,
  22        'host'      => $conn_host,
  23        'port'      => $conn_port,
  24        'database'  => null,
  25      );
  26  
  27      $conn_raw = PhabricatorEnv::newObjectFromConfig(
  28        'mysql.implementation',
  29        array($config));
  30  
  31      try {
  32        queryfx($conn_raw, 'SELECT 1');
  33      } catch (AphrontConnectionQueryException $ex) {
  34        $message = pht(
  35          "Unable to connect to MySQL!\n\n".
  36          "%s\n\n".
  37          "Make sure Phabricator and MySQL are correctly configured.",
  38          $ex->getMessage());
  39  
  40        $this->newIssue('mysql.connect')
  41          ->setName(pht('Can Not Connect to MySQL'))
  42          ->setMessage($message)
  43          ->setIsFatal(true)
  44          ->addRelatedPhabricatorConfig('mysql.host')
  45          ->addRelatedPhabricatorConfig('mysql.port')
  46          ->addRelatedPhabricatorConfig('mysql.user')
  47          ->addRelatedPhabricatorConfig('mysql.pass');
  48        return;
  49      }
  50  
  51      $engines = queryfx_all($conn_raw, 'SHOW ENGINES');
  52      $engines = ipull($engines, 'Support', 'Engine');
  53  
  54      $innodb = idx($engines, 'InnoDB');
  55      if ($innodb != 'YES' && $innodb != 'DEFAULT') {
  56        $message = pht(
  57          "The 'InnoDB' engine is not available in MySQL. Enable InnoDB in ".
  58          "your MySQL configuration.".
  59          "\n\n".
  60          "(If you aleady created tables, MySQL incorrectly used some other ".
  61          "engine to create them. You need to convert them or drop and ".
  62          "reinitialize them.)");
  63  
  64        $this->newIssue('mysql.innodb')
  65          ->setName(pht('MySQL InnoDB Engine Not Available'))
  66          ->setMessage($message)
  67          ->setIsFatal(true);
  68        return;
  69      }
  70  
  71      $namespace = PhabricatorEnv::getEnvConfig('storage.default-namespace');
  72  
  73      $databases = queryfx_all($conn_raw, 'SHOW DATABASES');
  74      $databases = ipull($databases, 'Database', 'Database');
  75  
  76      if (empty($databases[$namespace.'_meta_data'])) {
  77        $message = pht(
  78          'Run the storage upgrade script to setup Phabricator\'s database '.
  79          'schema.');
  80  
  81        $this->newIssue('storage.upgrade')
  82          ->setName(pht('Setup MySQL Schema'))
  83          ->setMessage($message)
  84          ->setIsFatal(true)
  85          ->addCommand(hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade'));
  86      } else {
  87  
  88        $config['database'] = $namespace.'_meta_data';
  89        $conn_meta = PhabricatorEnv::newObjectFromConfig(
  90          'mysql.implementation',
  91          array($config));
  92  
  93        $applied = queryfx_all($conn_meta, 'SELECT patch FROM patch_status');
  94        $applied = ipull($applied, 'patch', 'patch');
  95  
  96        $all = PhabricatorSQLPatchList::buildAllPatches();
  97        $diff = array_diff_key($all, $applied);
  98  
  99        if ($diff) {
 100          $this->newIssue('storage.patch')
 101            ->setName(pht('Upgrade MySQL Schema'))
 102            ->setMessage(pht(
 103              "Run the storage upgrade script to upgrade Phabricator's database ".
 104                "schema. Missing patches:<br />%s<br />",
 105              phutil_implode_html(phutil_tag('br'), array_keys($diff))))
 106            ->addCommand(
 107              hsprintf('<tt>phabricator/ $</tt> ./bin/storage upgrade'));
 108        }
 109      }
 110  
 111  
 112      $host = PhabricatorEnv::getEnvConfig('mysql.host');
 113      $matches = null;
 114      if (preg_match('/^([^:]+):(\d+)$/', $host, $matches)) {
 115        $host = $matches[1];
 116        $port = $matches[2];
 117  
 118        $this->newIssue('storage.mysql.hostport')
 119          ->setName(pht('Deprecated mysql.host Format'))
 120          ->setSummary(
 121            pht(
 122              'Move port information from `mysql.host` to `mysql.port` in your '.
 123              'config.'))
 124          ->setMessage(
 125            pht(
 126              'Your `mysql.host` configuration contains a port number, but '.
 127              'this usage is deprecated. Instead, put the port number in '.
 128              '`mysql.port`.'))
 129          ->addPhabricatorConfig('mysql.host')
 130          ->addPhabricatorConfig('mysql.port')
 131          ->addCommand(
 132            hsprintf(
 133              '<tt>phabricator/ $</tt> ./bin/config set mysql.host %s',
 134              $host))
 135          ->addCommand(
 136            hsprintf(
 137              '<tt>phabricator/ $</tt> ./bin/config set mysql.port %s',
 138              $port));
 139      }
 140  
 141    }
 142  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1