Changeset View
Changeset View
Standalone View
Standalone View
scripts/sql/manage_storage.php
| Show All 13 Lines | |||||
| Initialize or upgrade Phabricator storage. | Initialize or upgrade Phabricator storage. | ||||
| **storage** upgrade --user __root__ --password __hunter2__ | **storage** upgrade --user __root__ --password __hunter2__ | ||||
| Use administrative credentials for schema changes. | Use administrative credentials for schema changes. | ||||
| EOHELP | EOHELP | ||||
| ); | ); | ||||
| $args->parseStandardArguments(); | $args->parseStandardArguments(); | ||||
| $conf = PhabricatorEnv::newObjectFromConfig( | |||||
| 'mysql.configuration-provider', | |||||
| array($dao = null, 'w')); | |||||
| $default_user = $conf->getUser(); | |||||
| $default_host = $conf->getHost(); | |||||
| $default_port = $conf->getPort(); | |||||
| $default_namespace = PhabricatorLiskDAO::getDefaultStorageNamespace(); | $default_namespace = PhabricatorLiskDAO::getDefaultStorageNamespace(); | ||||
| try { | try { | ||||
| $args->parsePartial( | $args->parsePartial( | ||||
| array( | array( | ||||
| array( | array( | ||||
| 'name' => 'force', | 'name' => 'force', | ||||
| 'short' => 'f', | 'short' => 'f', | ||||
| 'help' => pht( | 'help' => pht( | ||||
| 'Do not prompt before performing dangerous operations.'), | 'Do not prompt before performing dangerous operations.'), | ||||
| ), | ), | ||||
| array( | array( | ||||
| 'name' => 'user', | 'name' => 'user', | ||||
| 'short' => 'u', | 'short' => 'u', | ||||
| 'param' => 'username', | 'param' => 'username', | ||||
| 'default' => $default_user, | |||||
| 'help' => pht( | 'help' => pht( | ||||
| "Connect with __username__ instead of the configured default ('%s').", | 'Connect with __username__ instead of the configured default.'), | ||||
| $default_user), | |||||
| ), | ), | ||||
| array( | array( | ||||
| 'name' => 'password', | 'name' => 'password', | ||||
| 'short' => 'p', | 'short' => 'p', | ||||
| 'param' => 'password', | 'param' => 'password', | ||||
| 'help' => pht('Use __password__ instead of the configured default.'), | 'help' => pht('Use __password__ instead of the configured default.'), | ||||
| ), | ), | ||||
| array( | array( | ||||
| Show All 23 Lines | |||||
| } catch (PhutilArgumentUsageException $ex) { | } catch (PhutilArgumentUsageException $ex) { | ||||
| $args->printUsageException($ex); | $args->printUsageException($ex); | ||||
| exit(77); | exit(77); | ||||
| } | } | ||||
| // First, test that the Phabricator configuration is set up correctly. After | // First, test that the Phabricator configuration is set up correctly. After | ||||
| // we know this works we'll test any administrative credentials specifically. | // we know this works we'll test any administrative credentials specifically. | ||||
| $ref = PhabricatorDatabaseRef::getMasterDatabaseRef(); | |||||
| if (!$ref) { | |||||
| throw new Exception( | |||||
| pht('No database master is configured.')); | |||||
| } | |||||
| $default_user = $ref->getUser(); | |||||
| $default_host = $ref->getHost(); | |||||
| $default_port = $ref->getPort(); | |||||
| $test_api = id(new PhabricatorStorageManagementAPI()) | $test_api = id(new PhabricatorStorageManagementAPI()) | ||||
| ->setUser($default_user) | ->setUser($default_user) | ||||
| ->setHost($default_host) | ->setHost($default_host) | ||||
| ->setPort($default_port) | ->setPort($default_port) | ||||
| ->setPassword($conf->getPassword()) | ->setPassword($ref->getPass()) | ||||
| ->setNamespace($args->getArg('namespace')); | ->setNamespace($args->getArg('namespace')); | ||||
| try { | try { | ||||
| queryfx( | queryfx( | ||||
| $test_api->getConn(null), | $test_api->getConn(null), | ||||
| 'SELECT 1'); | 'SELECT 1'); | ||||
| } catch (AphrontQueryException $ex) { | } catch (AphrontQueryException $ex) { | ||||
| $message = phutil_console_format( | $message = phutil_console_format( | ||||
| Show All 15 Lines | $message = phutil_console_format( | ||||
| pht('Raw MySQL Error'), | pht('Raw MySQL Error'), | ||||
| $ex->getMessage()); | $ex->getMessage()); | ||||
| echo phutil_console_wrap($message); | echo phutil_console_wrap($message); | ||||
| exit(1); | exit(1); | ||||
| } | } | ||||
| if ($args->getArg('password') === null) { | if ($args->getArg('password') === null) { | ||||
| // This is already a PhutilOpaqueEnvelope. | // This is already a PhutilOpaqueEnvelope. | ||||
| $password = $conf->getPassword(); | $password = $ref->getPass(); | ||||
| } else { | } else { | ||||
| // Put this in a PhutilOpaqueEnvelope. | // Put this in a PhutilOpaqueEnvelope. | ||||
| $password = new PhutilOpaqueEnvelope($args->getArg('password')); | $password = new PhutilOpaqueEnvelope($args->getArg('password')); | ||||
| PhabricatorEnv::overrideConfig('mysql.pass', $args->getArg('password')); | PhabricatorEnv::overrideConfig('mysql.pass', $args->getArg('password')); | ||||
| } | } | ||||
| $selected_user = $args->getArg('user'); | |||||
| if ($selected_user === null) { | |||||
| $selected_user = $default_user; | |||||
| } | |||||
| $api = id(new PhabricatorStorageManagementAPI()) | $api = id(new PhabricatorStorageManagementAPI()) | ||||
| ->setUser($args->getArg('user')) | ->setUser($selected_user) | ||||
| ->setHost($default_host) | ->setHost($default_host) | ||||
| ->setPort($default_port) | ->setPort($default_port) | ||||
| ->setPassword($password) | ->setPassword($password) | ||||
| ->setNamespace($args->getArg('namespace')) | ->setNamespace($args->getArg('namespace')) | ||||
| ->setDisableUTF8MB4($args->getArg('disable-utf8mb4')); | ->setDisableUTF8MB4($args->getArg('disable-utf8mb4')); | ||||
| PhabricatorEnv::overrideConfig('mysql.user', $api->getUser()); | PhabricatorEnv::overrideConfig('mysql.user', $api->getUser()); | ||||
| try { | try { | ||||
| Show All 33 Lines | |||||