From 5d4a6bcf954a67348bbf1bd77620cf8d994b7a67 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 24 Jul 2012 10:47:27 -0700 Subject: [PATCH] Break AphrontDatabaseConnection dependencies on PhabricatorEnv Summary: We pull "retries" and a doc link from PhabricatorEnv directly. Break these dependencies so the classes can move to libphutil. Test Plan: Browsed site, triggered a schema exception and verified I still got the useful footer text. Reviewers: btrahan, vrana Reviewed By: vrana CC: aran Maniphest Tasks: T1283 Differential Revision: https://secure.phabricator.com/D3053 --- src/__phutil_library_map__.php | 2 ++ ...AphrontDefaultApplicationConfiguration.php | 8 +++++++ .../AphrontIsolatedDatabaseConnection.php | 10 ++++---- .../mysql/AphrontMySQLDatabaseConnection.php | 3 ++- .../AphrontMySQLDatabaseConnectionBase.php | 4 ++-- .../mysql/AphrontMySQLiDatabaseConnection.php | 3 ++- .../AphrontQueryNotSupportedException.php | 24 +++++++++++++++++++ .../exception/AphrontQuerySchemaException.php | 10 -------- .../storage/lisk/PhabricatorLiskDAO.php | 2 ++ 9 files changed, 46 insertions(+), 20 deletions(-) create mode 100644 src/infrastructure/storage/exception/AphrontQueryNotSupportedException.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index fc510b3eb9..e9196a3e27 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -87,6 +87,7 @@ phutil_register_library_map(array( 'AphrontQueryDeadlockException' => 'infrastructure/storage/exception/AphrontQueryDeadlockException.php', 'AphrontQueryDuplicateKeyException' => 'infrastructure/storage/exception/AphrontQueryDuplicateKeyException.php', 'AphrontQueryException' => 'infrastructure/storage/exception/AphrontQueryException.php', + 'AphrontQueryNotSupportedException' => 'infrastructure/storage/exception/AphrontQueryNotSupportedException.php', 'AphrontQueryObjectMissingException' => 'infrastructure/storage/exception/AphrontQueryObjectMissingException.php', 'AphrontQueryParameterException' => 'infrastructure/storage/exception/AphrontQueryParameterException.php', 'AphrontQueryRecoverableException' => 'infrastructure/storage/exception/AphrontQueryRecoverableException.php', @@ -1205,6 +1206,7 @@ phutil_register_library_map(array( 'AphrontQueryDeadlockException' => 'AphrontQueryRecoverableException', 'AphrontQueryDuplicateKeyException' => 'AphrontQueryException', 'AphrontQueryException' => 'Exception', + 'AphrontQueryNotSupportedException' => 'AphrontQueryException', 'AphrontQueryObjectMissingException' => 'AphrontQueryException', 'AphrontQueryParameterException' => 'AphrontQueryException', 'AphrontQueryRecoverableException' => 'AphrontQueryException', diff --git a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php index ed1ac6bcb2..b22a7ac68c 100644 --- a/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php +++ b/src/aphront/configuration/AphrontDefaultApplicationConfiguration.php @@ -565,6 +565,14 @@ class AphrontDefaultApplicationConfiguration $class = phutil_escape_html(get_class($ex)); $message = phutil_escape_html($ex->getMessage()); + if ($ex instanceof AphrontQuerySchemaException) { + $message .= + "\n\n". + "NOTE: This usually indicates that the MySQL schema has not been ". + "properly upgraded. Run 'bin/storage upgrade' to ensure your ". + "schema is up to date."; + } + if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) { $trace = $this->renderStackTrace($ex->getTrace(), $user); } else { diff --git a/src/infrastructure/storage/connection/AphrontIsolatedDatabaseConnection.php b/src/infrastructure/storage/connection/AphrontIsolatedDatabaseConnection.php index 07fac75486..e83ec5cf3b 100644 --- a/src/infrastructure/storage/connection/AphrontIsolatedDatabaseConnection.php +++ b/src/infrastructure/storage/connection/AphrontIsolatedDatabaseConnection.php @@ -96,12 +96,10 @@ final class AphrontIsolatedDatabaseConnection $preg_keywords = implode('|', $preg_keywords); if (!preg_match('/^[\s<>K]*('.$preg_keywords.')\s*/i', $raw_query)) { - $doc_uri = PhabricatorEnv::getDoclink('article/Writing_Unit_Tests.html'); - throw new Exception( - "Database isolation currently only supports some queries. For more ". - "information, see <{$doc_uri}>. You are trying to issue a query which ". - "does not begin with an allowed keyword ". - "(".implode(', ', $keywords)."): '".$raw_query."'"); + throw new AphrontQueryNotSupportedException( + "Database isolation currently only supports some queries. You are ". + "trying to issue a query which does not begin with an allowed ". + "keyword (".implode(', ', $keywords)."): '".$raw_query."'"); } $this->transcript[] = $raw_query; diff --git a/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php b/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php index 15d805665d..016b686afd 100644 --- a/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php +++ b/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnection.php @@ -52,11 +52,12 @@ final class AphrontMySQLDatabaseConnection $user = $this->getConfiguration('user'); $host = $this->getConfiguration('host'); $database = $this->getConfiguration('database'); + $pass = $this->getConfiguration('pass'); $conn = @mysql_connect( $host, $user, - $this->getConfiguration('pass'), + $pass, $new_link = true, $flags = 0); diff --git a/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php b/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php index d1fd2379e6..cca9ce1781 100644 --- a/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php +++ b/src/infrastructure/storage/connection/mysql/AphrontMySQLDatabaseConnectionBase.php @@ -101,7 +101,7 @@ abstract class AphrontMySQLDatabaseConnectionBase 'database' => $database, )); - $retries = max(1, PhabricatorEnv::getEnvConfig('mysql.connection-retries')); + $retries = max(1, $this->getConfiguration('retries', 3)); while ($retries--) { try { $conn = $this->connect(); @@ -143,7 +143,7 @@ abstract class AphrontMySQLDatabaseConnectionBase public function executeRawQuery($raw_query) { $this->lastResult = null; - $retries = max(1, PhabricatorEnv::getEnvConfig('mysql.connection-retries')); + $retries = max(1, $this->getConfiguration('retries', 3)); while ($retries--) { try { $this->requireConnection(); diff --git a/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php b/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php index c0d59f1630..6892a2f5ab 100644 --- a/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php +++ b/src/infrastructure/storage/connection/mysql/AphrontMySQLiDatabaseConnection.php @@ -50,11 +50,12 @@ final class AphrontMySQLiDatabaseConnection $user = $this->getConfiguration('user'); $host = $this->getConfiguration('host'); $database = $this->getConfiguration('database'); + $pass = $this->getConfiguration('pass'); $conn = @new mysqli( $host, $user, - $this->getConfiguration('pass'), + $pass, $database); $errno = $conn->connect_errno; diff --git a/src/infrastructure/storage/exception/AphrontQueryNotSupportedException.php b/src/infrastructure/storage/exception/AphrontQueryNotSupportedException.php new file mode 100644 index 0000000000..0e562cbfa6 --- /dev/null +++ b/src/infrastructure/storage/exception/AphrontQueryNotSupportedException.php @@ -0,0 +1,24 @@ + $conf->getPassword(), 'host' => $conf->getHost(), 'database' => $conf->getDatabase(), + 'retries' => $retries, ), )); }