[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/bin/ -> storage (source)

   1  #!/usr/bin/env php
   2  <?php
   3  
   4  $root = dirname(dirname(dirname(__FILE__)));
   5  require_once $root.'/scripts/__init_script__.php';
   6  
   7  $args = new PhutilArgumentParser($argv);
   8  $args->setTagline('manage Phabricator storage and schemata');
   9  $args->setSynopsis(<<<EOHELP
  10  **storage** __workflow__ [__options__]
  11  Manage Phabricator database storage and schema versioning.
  12  
  13  **storage** upgrade
  14  Initialize or upgrade Phabricator storage.
  15  
  16  **storage** upgrade --user __root__ --password __hunter2__
  17  Use administrative credentials for schema changes.
  18  EOHELP
  19  );
  20  $args->parseStandardArguments();
  21  
  22  $conf = PhabricatorEnv::newObjectFromConfig(
  23    'mysql.configuration-provider',
  24    array($dao = null, 'w'));
  25  
  26  $default_user       = $conf->getUser();
  27  $default_host       = $conf->getHost();
  28  $default_port       = $conf->getPort();
  29  $default_namespace  = PhabricatorLiskDAO::getDefaultStorageNamespace();
  30  
  31  try {
  32    $args->parsePartial(
  33      array(
  34        array(
  35          'name'    => 'force',
  36          'short'   => 'f',
  37          'help'    => 'Do not prompt before performing dangerous operations.',
  38        ),
  39        array(
  40          'name'    => 'user',
  41          'short'   => 'u',
  42          'param'   => 'username',
  43          'default' => $default_user,
  44          'help'    => "Connect with __username__ instead of the configured ".
  45                       "default ('{$default_user}').",
  46        ),
  47        array(
  48          'name'    => 'password',
  49          'short'   => 'p',
  50          'param'   => 'password',
  51          'help'    => 'Use __password__ instead of the configured default.',
  52        ),
  53        array(
  54          'name'    => 'namespace',
  55          'param'   => 'name',
  56          'default' => $default_namespace,
  57          'help'    => "Use namespace __namespace__ instead of the configured ".
  58                       "default ('{$default_namespace}'). This is an advanced ".
  59                       "feature used by unit tests; you should not normally ".
  60                       "use this flag.",
  61        ),
  62        array(
  63          'name'  => 'dryrun',
  64          'help'  => 'Do not actually change anything, just show what would be '.
  65                     'changed.',
  66        ),
  67        array(
  68          'name' => 'disable-utf8mb4',
  69          'help' => pht(
  70            'Disable utf8mb4, even if the database supports it. This is an '.
  71            'advanced feature used for testing changes to Phabricator; you '.
  72            'should not normally use this flag.'),
  73        )
  74      ));
  75  } catch (PhutilArgumentUsageException $ex) {
  76    $args->printUsageException($ex);
  77    exit(77);
  78  }
  79  
  80  // First, test that the Phabricator configuration is set up correctly. After
  81  // we know this works we'll test any administrative credentials specifically.
  82  
  83  $test_api = new PhabricatorStorageManagementAPI();
  84  $test_api->setUser($default_user);
  85  $test_api->setHost($default_host);
  86  $test_api->setPort($default_port);
  87  $test_api->setPassword($conf->getPassword());
  88  $test_api->setNamespace($args->getArg('namespace'));
  89  
  90  try {
  91    queryfx(
  92      $test_api->getConn(null),
  93      'SELECT 1');
  94  } catch (AphrontQueryException $ex) {
  95    $message = phutil_console_format(
  96      pht(
  97        "**MySQL Credentials Not Configured**\n\n".
  98        "Unable to connect to MySQL using the configured credentials. ".
  99        "You must configure standard credentials before you can upgrade ".
 100        "storage. Run these commands to set up credentials:\n".
 101        "\n".
 102        "  phabricator/ $ ./bin/config set mysql.host __host__\n".
 103        "  phabricator/ $ ./bin/config set mysql.user __username__\n".
 104        "  phabricator/ $ ./bin/config set mysql.pass __password__\n".
 105        "\n".
 106        "These standard credentials are separate from any administrative ".
 107        "credentials provided to this command with __--user__ or ".
 108        "__--password__, and must be configured correctly before you can ".
 109        "proceed.\n".
 110        "\n".
 111        "**Raw MySQL Error**: %s\n",
 112        $ex->getMessage()));
 113  
 114    echo phutil_console_wrap($message);
 115  
 116    exit(1);
 117  }
 118  
 119  
 120  if ($args->getArg('password') === null) {
 121    // This is already a PhutilOpaqueEnvelope.
 122    $password = $conf->getPassword();
 123  } else {
 124    // Put this in a PhutilOpaqueEnvelope.
 125    $password = new PhutilOpaqueEnvelope($args->getArg('password'));
 126    PhabricatorEnv::overrideConfig('mysql.pass', $args->getArg('password'));
 127  }
 128  
 129  $api = new PhabricatorStorageManagementAPI();
 130  $api->setUser($args->getArg('user'));
 131  PhabricatorEnv::overrideConfig('mysql.user', $args->getArg('user'));
 132  $api->setHost($default_host);
 133  $api->setPort($default_port);
 134  $api->setPassword($password);
 135  $api->setNamespace($args->getArg('namespace'));
 136  $api->setDisableUTF8MB4($args->getArg('disable-utf8mb4'));
 137  
 138  try {
 139    queryfx(
 140      $api->getConn(null),
 141      'SELECT 1');
 142  } catch (AphrontQueryException $ex) {
 143    $message = phutil_console_format(
 144      pht(
 145        "**Bad Administrative Credentials**\n\n".
 146        "Unable to connnect to MySQL using the administrative credentials ".
 147        "provided with the __--user__ and __--password__ flags. Check that ".
 148        "you have entered them correctly.\n".
 149        "\n".
 150        "**Raw MySQL Error**: %s\n",
 151        $ex->getMessage()));
 152  
 153    echo phutil_console_wrap($message);
 154  
 155    exit(1);
 156  }
 157  
 158  $workflows = id(new PhutilSymbolLoader())
 159    ->setAncestorClass('PhabricatorStorageManagementWorkflow')
 160    ->loadObjects();
 161  
 162  $patches = PhabricatorSQLPatchList::buildAllPatches();
 163  
 164  foreach ($workflows as $workflow) {
 165    $workflow->setAPI($api);
 166    $workflow->setPatches($patches);
 167  }
 168  
 169  $workflows[] = new PhutilHelpArgumentWorkflow();
 170  
 171  $args->parseWorkflows($workflows);


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