1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-06-21 10:40:58 +02:00

Merge branch 'develop-olympus' into develop

* develop-olympus:
  [ticket/10057] Fixes for a bunch of small problems.
  [ticket/10035] ACP template edit feature allows to read any files on webserver.
  [ticket/10057] Handle the case of missing interbase extension better.
  [ticket/10057] Fixed wrong usage of sql_error again, in firebird.
  [ticket/10057] Fixed usage of sql_error again.
  [ticket/10057] Condition file/line display on DEBUG_EXTRA or IN_INSTALL.
  [ticket/10057] Fixed wrong usage of sql_error in postgres dbal.
  [ticket/10057] Skip ibase_service_attach if firebird connection failed.
  [ticket/10057] Check for interbase function existence.
  [ticket/10057] Split statements in firebird dbal for readability.
  [ticket/10057] Include error collector class file in postgres dbal.
  [ticket/10057] Moved error collector class into its own file.
  [ticket/10057] Use a class for error collection.
  [ticket/10057] More informative error messages in postgres dbal.
  [ticket/10057] No negative array indexing.
  [ticket/10057] Report postgres db connection errors.
This commit is contained in:
Oleg Pudeyev
2011-03-10 05:25:36 -05:00
4 changed files with 143 additions and 5 deletions

View File

@ -716,7 +716,7 @@ parse_css_file = {PARSE_CSS_FILE}
$save_changes = (isset($_POST['save'])) ? true : false;
// make sure template_file path doesn't go upwards
$template_file = str_replace('..', '.', $template_file);
$template_file = preg_replace('#\.{2,}#', '.', $template_file);
// Retrieve some information about the template
$sql = 'SELECT template_storedb, template_path, template_name

View File

@ -28,6 +28,7 @@ class dbal_firebird extends dbal
var $last_query_text = '';
var $service_handle = false;
var $affected_rows = 0;
var $connect_error = '';
/**
* Connect to server
@ -53,9 +54,35 @@ class dbal_firebird extends dbal
$use_database = $this->server . ':' . $this->dbname;
}
$this->db_connect_id = ($this->persistency) ? @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3) : @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3);
if ($this->persistency)
{
if (!function_exists('ibase_pconnect'))
{
$this->connect_error = 'ibase_pconnect function does not exist, is interbase extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ibase_pconnect($use_database, $this->user, $sqlpassword, false, false, 3);
}
else
{
if (!function_exists('ibase_connect'))
{
$this->connect_error = 'ibase_connect function does not exist, is interbase extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ibase_connect($use_database, $this->user, $sqlpassword, false, false, 3);
}
$this->service_handle = (function_exists('ibase_service_attach') && $this->server) ? @ibase_service_attach($this->server, $this->user, $sqlpassword) : false;
// Do not call ibase_service_attach if connection failed,
// otherwise error message from ibase_(p)connect call will be clobbered.
if ($this->db_connect_id && function_exists('ibase_service_attach') && $this->server)
{
$this->service_handle = @ibase_service_attach($this->server, $this->user, $sqlpassword);
}
else
{
$this->service_handle = false;
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
}
@ -487,8 +514,24 @@ class dbal_firebird extends dbal
*/
function _sql_error()
{
// Need special handling here because ibase_errmsg returns
// connection errors, however if the interbase extension
// is not installed then ibase_errmsg does not exist and
// we cannot call it.
if (function_exists('ibase_errmsg'))
{
$msg = @ibase_errmsg();
if (!$msg)
{
$msg = $this->connect_error;
}
}
else
{
$msg = $this->connect_error;
}
return array(
'message' => @ibase_errmsg(),
'message' => $msg,
'code' => (@function_exists('ibase_errcode') ? @ibase_errcode() : '')
);
}

View File

@ -18,6 +18,11 @@ if (!defined('IN_PHPBB'))
include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
if (!class_exists('phpbb_error_collector'))
{
include($phpbb_root_path . 'includes/error_collector.' . $phpEx);
}
/**
* PostgreSQL Database Abstraction Layer
* Minimum Requirement is Version 7.3+
@ -26,6 +31,7 @@ include_once($phpbb_root_path . 'includes/db/dbal.' . $phpEx);
class dbal_postgres extends dbal
{
var $last_query_text = '';
var $connect_error = '';
/**
* Connect to server
@ -81,13 +87,29 @@ class dbal_postgres extends dbal
if ($this->persistency)
{
if (!function_exists('pg_pconnect'))
{
$this->connect_error = 'pg_pconnect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_pconnect($connect_string) : @pg_pconnect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}
else
{
if (!function_exists('pg_connect'))
{
$this->connect_error = 'pg_connect function does not exist, is pgsql extension installed?';
return $this->sql_error('');
}
$collector = new phpbb_error_collector;
$collector->install();
$this->db_connect_id = (!$new_link) ? @pg_connect($connect_string) : @pg_connect($connect_string, PGSQL_CONNECT_FORCE_NEW);
}
$collector->uninstall();
if ($this->db_connect_id)
{
if (version_compare($this->sql_server_info(true), '8.2', '>='))
@ -102,6 +124,7 @@ class dbal_postgres extends dbal
return $this->db_connect_id;
}
$this->connect_error = $collector->format_errors();
return $this->sql_error('');
}
@ -387,8 +410,19 @@ class dbal_postgres extends dbal
*/
function _sql_error()
{
// pg_last_error only works when there is an established connection.
// Connection errors have to be tracked by us manually.
if ($this->db_connect_id)
{
$message = @pg_last_error($this->db_connect_id);
}
else
{
$message = $this->connect_error;
}
return array(
'message' => (!$this->db_connect_id) ? @pg_last_error() : @pg_last_error($this->db_connect_id),
'message' => $message,
'code' => ''
);
}

View File

@ -0,0 +1,61 @@
<?php
/**
*
* @package phpBB
* @version $Id$
* @copyright (c) 2011 phpBB Group
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
*/
/**
* @ignore
*/
if (!defined('IN_PHPBB'))
{
exit;
}
class phpbb_error_collector
{
var $errors;
function phpbb_error_collector()
{
$this->errors = array();
}
function install()
{
set_error_handler(array(&$this, 'error_handler'));
}
function uninstall()
{
restore_error_handler();
}
function error_handler($errno, $msg_text, $errfile, $errline)
{
$this->errors[] = array($errno, $msg_text, $errfile, $errline);
}
function format_errors()
{
$text = '';
foreach ($this->errors as $error)
{
if (!empty($text))
{
$text .= "<br />\n";
}
list($errno, $msg_text, $errfile, $errline) = $error;
$text .= "Errno $errno: $msg_text";
if (defined('DEBUG_EXTRA') || defined('IN_INSTALL'))
{
$text .= " at $errfile line $errline";
}
}
return $text;
}
}