From 1ecfa0313c483a019ed34e90e840b1231d29a357 Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Fri, 30 Jan 2015 07:15:27 +1100 Subject: [PATCH] Add a `./bin/storage shell` command Summary: Fixes T7078. Adds a `./bin/storage shell` command which passes through to a MySQL shell. This is slightly more convenient than running `mysql` manually. Test Plan: Ran `./bin/storage shell` and got a MySQL shell. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, epriestley Maniphest Tasks: T7078 Differential Revision: https://secure.phabricator.com/D11548 --- src/__phutil_library_map__.php | 2 + ...abricatorStorageManagementDumpWorkflow.php | 16 -------- ...bricatorStorageManagementShellWorkflow.php | 38 +++++++++++++++++++ .../PhabricatorStorageManagementWorkflow.php | 15 ++++++++ 4 files changed, 55 insertions(+), 16 deletions(-) create mode 100644 src/infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index b65acebb9f..d689923575 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -2462,6 +2462,7 @@ phutil_register_library_map(array( 'PhabricatorStorageManagementDumpWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php', 'PhabricatorStorageManagementProbeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementProbeWorkflow.php', 'PhabricatorStorageManagementQuickstartWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementQuickstartWorkflow.php', + 'PhabricatorStorageManagementShellWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php', 'PhabricatorStorageManagementStatusWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementStatusWorkflow.php', 'PhabricatorStorageManagementUpgradeWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementUpgradeWorkflow.php', 'PhabricatorStorageManagementWorkflow' => 'infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php', @@ -5753,6 +5754,7 @@ phutil_register_library_map(array( 'PhabricatorStorageManagementDumpWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementProbeWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementQuickstartWorkflow' => 'PhabricatorStorageManagementWorkflow', + 'PhabricatorStorageManagementShellWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementStatusWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementUpgradeWorkflow' => 'PhabricatorStorageManagementWorkflow', 'PhabricatorStorageManagementWorkflow' => 'PhabricatorManagementWorkflow', diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php index deca8967de..a775a1aaad 100644 --- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php +++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementDumpWorkflow.php @@ -32,7 +32,6 @@ final class PhabricatorStorageManagementDumpWorkflow list($host, $port) = $this->getBareHostAndPort($api->getHost()); $flag_password = ''; - $password = $api->getPassword(); if ($password) { if (strlen($password->openEnvelope())) { @@ -54,19 +53,4 @@ final class PhabricatorStorageManagementDumpWorkflow $databases); } - private function getBareHostAndPort($host) { - // Split out port information, since the command-line client requires a - // separate flag for the port. - $uri = new PhutilURI('mysql://'.$host); - if ($uri->getPort()) { - $port = $uri->getPort(); - $bare_hostname = $uri->getDomain(); - } else { - $port = null; - $bare_hostname = $host; - } - - return array($bare_hostname, $port); - } - } diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php new file mode 100644 index 0000000000..ffbb018687 --- /dev/null +++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementShellWorkflow.php @@ -0,0 +1,38 @@ +setName('shell') + ->setExamples('**shell** [__options__]') + ->setSynopsis('Launch an interactive shell.'); + } + + public function execute(PhutilArgumentParser $args) { + $api = $this->getAPI(); + list($host, $port) = $this->getBareHostAndPort($api->getHost()); + + $flag_port = $port + ? csprintf('--port %d', $port) + : ''; + + $flag_password = ''; + $password = $api->getPassword(); + if ($password) { + if (strlen($password->openEnvelope())) { + $flag_password = csprintf('--password=%P', $password); + } + } + + return phutil_passthru( + 'mysql --default-character-set=utf8 '. + '-u %s %C -h %s %C', + $api->getUser(), + $flag_password, + $host, + $flag_port); + } + +} diff --git a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php index 5478420f22..35a02bff38 100644 --- a/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php +++ b/src/infrastructure/storage/management/workflow/PhabricatorStorageManagementWorkflow.php @@ -663,4 +663,19 @@ abstract class PhabricatorStorageManagementWorkflow return 2; } + protected final function getBareHostAndPort($host) { + // Split out port information, since the command-line client requires a + // separate flag for the port. + $uri = new PhutilURI('mysql://'.$host); + if ($uri->getPort()) { + $port = $uri->getPort(); + $bare_hostname = $uri->getDomain(); + } else { + $port = null; + $bare_hostname = $host; + } + + return array($bare_hostname, $port); + } + }