mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 00:32:42 +01:00
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
This commit is contained in:
parent
be63cb386b
commit
5d4a6bcf95
9 changed files with 46 additions and 20 deletions
|
@ -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',
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @group storage
|
||||
*/
|
||||
final class AphrontQueryNotSupportedException extends AphrontQueryException {
|
||||
|
||||
}
|
|
@ -21,14 +21,4 @@
|
|||
*/
|
||||
final class AphrontQuerySchemaException extends AphrontQueryException {
|
||||
|
||||
public function __construct($message) {
|
||||
$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.";
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -107,6 +107,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
|
|||
'mysql.configuration-provider',
|
||||
array($this, $mode, $namespace));
|
||||
|
||||
$retries = PhabricatorEnv::getEnvConfig('mysql.connection-retries');
|
||||
return PhabricatorEnv::newObjectFromConfig(
|
||||
'mysql.implementation',
|
||||
array(
|
||||
|
@ -115,6 +116,7 @@ abstract class PhabricatorLiskDAO extends LiskDAO {
|
|||
'pass' => $conf->getPassword(),
|
||||
'host' => $conf->getHost(),
|
||||
'database' => $conf->getDatabase(),
|
||||
'retries' => $retries,
|
||||
),
|
||||
));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue