1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-08-24 01:03:05 +02:00

Merge branch '3.3.x' into ticket/16641

This commit is contained in:
3D-I
2020-12-31 22:27:12 +01:00
32 changed files with 1334 additions and 495 deletions

View File

@@ -45,30 +45,30 @@ class oracle extends \phpbb\db\driver\driver
if ($new_link)
{
if (!function_exists('ocinlogon'))
if (!function_exists('oci_new_connect'))
{
$this->connect_error = 'ocinlogon function does not exist, is oci extension installed?';
$this->connect_error = 'oci_new_connect function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ocinlogon($this->user, $sqlpassword, $connect, 'UTF8');
$this->db_connect_id = @oci_new_connect($this->user, $sqlpassword, $connect, 'UTF8');
}
else if ($this->persistency)
{
if (!function_exists('ociplogon'))
if (!function_exists('oci_pconnect'))
{
$this->connect_error = 'ociplogon function does not exist, is oci extension installed?';
$this->connect_error = 'oci_pconnect function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ociplogon($this->user, $sqlpassword, $connect, 'UTF8');
$this->db_connect_id = @oci_pconnect($this->user, $sqlpassword, $connect, 'UTF8');
}
else
{
if (!function_exists('ocilogon'))
if (!function_exists('oci_connect'))
{
$this->connect_error = 'ocilogon function does not exist, is oci extension installed?';
$this->connect_error = 'oci_connect function does not exist, is oci extension installed?';
return $this->sql_error('');
}
$this->db_connect_id = @ocilogon($this->user, $sqlpassword, $connect, 'UTF8');
$this->db_connect_id = @oci_connect($this->user, $sqlpassword, $connect, 'UTF8');
}
return ($this->db_connect_id) ? $this->db_connect_id : $this->sql_error('');
@@ -101,7 +101,7 @@ class oracle extends \phpbb\db\driver\driver
$cache->put('oracle_version', $this->sql_server_version);
}
*/
$this->sql_server_version = @ociserverversion($this->db_connect_id);
$this->sql_server_version = @oci_server_version($this->db_connect_id);
return $this->sql_server_version;
}
@@ -119,11 +119,11 @@ class oracle extends \phpbb\db\driver\driver
break;
case 'commit':
return @ocicommit($this->db_connect_id);
return @oci_commit($this->db_connect_id);
break;
case 'rollback':
return @ocirollback($this->db_connect_id);
return @oci_rollback($this->db_connect_id);
break;
}
@@ -405,14 +405,14 @@ class oracle extends \phpbb\db\driver\driver
break;
}
$this->query_result = @ociparse($this->db_connect_id, $query);
$this->query_result = @oci_parse($this->db_connect_id, $query);
foreach ($array as $key => $value)
{
@ocibindbyname($this->query_result, $key, $array[$key], -1);
@oci_bind_by_name($this->query_result, $key, $array[$key], -1);
}
$success = @ociexecute($this->query_result, OCI_DEFAULT);
$success = @oci_execute($this->query_result, OCI_DEFAULT);
if (!$success)
{
@@ -481,7 +481,7 @@ class oracle extends \phpbb\db\driver\driver
*/
function sql_affectedrows()
{
return ($this->query_result) ? @ocirowcount($this->query_result) : false;
return ($this->query_result) ? @oci_num_rows($this->query_result) : false;
}
/**
@@ -503,10 +503,7 @@ class oracle extends \phpbb\db\driver\driver
if ($query_id)
{
$row = array();
$result = ocifetchinto($query_id, $row, OCI_ASSOC + OCI_RETURN_NULLS);
if (!$result || !$row)
if (!$row = oci_fetch_array($query_id, OCI_ASSOC + OCI_RETURN_NULLS))
{
return false;
}
@@ -558,7 +555,7 @@ class oracle extends \phpbb\db\driver\driver
}
// Reset internal pointer
@ociexecute($query_id, OCI_DEFAULT);
@oci_execute($query_id, OCI_DEFAULT);
// We do not fetch the row for rownum == 0 because then the next resultset would be the second row
for ($i = 0; $i < $rownum; $i++)
@@ -584,17 +581,17 @@ class oracle extends \phpbb\db\driver\driver
if (preg_match('#^INSERT[\t\n ]+INTO[\t\n ]+([a-z0-9\_\-]+)#is', $this->last_query_text, $tablename))
{
$query = 'SELECT ' . $tablename[1] . '_seq.currval FROM DUAL';
$stmt = @ociparse($this->db_connect_id, $query);
$stmt = @oci_parse($this->db_connect_id, $query);
if ($stmt)
{
$success = @ociexecute($stmt, OCI_DEFAULT);
$success = @oci_execute($stmt, OCI_DEFAULT);
if ($success)
{
$temp_result = ocifetchinto($stmt, $temp_array, OCI_ASSOC + OCI_RETURN_NULLS);
ocifreestatement($stmt);
$temp_array = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS);
oci_free_statement($stmt);
if ($temp_result)
if (!empty($temp_array))
{
return $temp_array['CURRVAL'];
}
@@ -630,7 +627,7 @@ class oracle extends \phpbb\db\driver\driver
if (isset($this->open_queries[(int) $query_id]))
{
unset($this->open_queries[(int) $query_id]);
return ocifreestatement($query_id);
return oci_free_statement($query_id);
}
return false;
@@ -683,11 +680,11 @@ class oracle extends \phpbb\db\driver\driver
*/
function _sql_error()
{
if (function_exists('ocierror'))
if (function_exists('oci_error'))
{
$error = @ocierror();
$error = (!$error) ? @ocierror($this->query_result) : $error;
$error = (!$error) ? @ocierror($this->db_connect_id) : $error;
$error = @oci_error();
$error = (!$error) ? @oci_error($this->query_result) : $error;
$error = (!$error) ? @oci_error($this->db_connect_id) : $error;
if ($error)
{
@@ -715,7 +712,7 @@ class oracle extends \phpbb\db\driver\driver
*/
function _sql_close()
{
return @ocilogoff($this->db_connect_id);
return @oci_close($this->db_connect_id);
}
/**
@@ -734,11 +731,10 @@ class oracle extends \phpbb\db\driver\driver
$sql = "SELECT table_name
FROM USER_TABLES
WHERE table_name LIKE '%PLAN_TABLE%'";
$stmt = ociparse($this->db_connect_id, $sql);
ociexecute($stmt);
$result = array();
$stmt = oci_parse($this->db_connect_id, $sql);
oci_execute($stmt);
if (ocifetchinto($stmt, $result, OCI_ASSOC + OCI_RETURN_NULLS))
if ($result = oci_fetch_array($stmt, OCI_ASSOC + OCI_RETURN_NULLS))
{
$table = $result['TABLE_NAME'];
@@ -746,17 +742,17 @@ class oracle extends \phpbb\db\driver\driver
$statement_id = substr(md5($query), 0, 30);
// Remove any stale plans
$stmt2 = ociparse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
ociexecute($stmt2);
ocifreestatement($stmt2);
$stmt2 = oci_parse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
oci_execute($stmt2);
oci_free_statement($stmt2);
// Explain the plan
$sql = "EXPLAIN PLAN
SET STATEMENT_ID = '$statement_id'
FOR $query";
$stmt2 = ociparse($this->db_connect_id, $sql);
ociexecute($stmt2);
ocifreestatement($stmt2);
$stmt2 = oci_parse($this->db_connect_id, $sql);
oci_execute($stmt2);
oci_free_statement($stmt2);
// Get the data from the plan
$sql = "SELECT operation, options, object_name, object_type, cardinality, cost
@@ -764,24 +760,23 @@ class oracle extends \phpbb\db\driver\driver
START WITH id = 0 AND statement_id = '$statement_id'
CONNECT BY PRIOR id = parent_id
AND statement_id = '$statement_id'";
$stmt2 = ociparse($this->db_connect_id, $sql);
ociexecute($stmt2);
$stmt2 = oci_parse($this->db_connect_id, $sql);
oci_execute($stmt2);
$row = array();
while (ocifetchinto($stmt2, $row, OCI_ASSOC + OCI_RETURN_NULLS))
while ($row = oci_fetch_array($stmt2, OCI_ASSOC + OCI_RETURN_NULLS))
{
$html_table = $this->sql_report('add_select_row', $query, $html_table, $row);
}
ocifreestatement($stmt2);
oci_free_statement($stmt2);
// Remove the plan we just made, we delete them on request anyway
$stmt2 = ociparse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
ociexecute($stmt2);
ocifreestatement($stmt2);
$stmt2 = oci_parse($this->db_connect_id, "DELETE FROM $table WHERE statement_id='$statement_id'");
oci_execute($stmt2);
oci_free_statement($stmt2);
}
ocifreestatement($stmt);
oci_free_statement($stmt);
if ($html_table)
{
@@ -794,19 +789,19 @@ class oracle extends \phpbb\db\driver\driver
$endtime = explode(' ', microtime());
$endtime = $endtime[0] + $endtime[1];
$result = @ociparse($this->db_connect_id, $query);
$result = @oci_parse($this->db_connect_id, $query);
if ($result)
{
$success = @ociexecute($result, OCI_DEFAULT);
$success = @oci_execute($result, OCI_DEFAULT);
if ($success)
{
$row = array();
array();
while (ocifetchinto($result, $row, OCI_ASSOC + OCI_RETURN_NULLS))
while ($row = oci_fetch_array($result, OCI_ASSOC + OCI_RETURN_NULLS))
{
// Take the time spent on parsing rows into account
}
@ocifreestatement($result);
@oci_free_statement($result);
}
}

View File

@@ -1,227 +0,0 @@
<?php
/**
*
* This file is part of the phpBB Forum Software package.
*
* @copyright (c) phpBB Limited <https://www.phpbb.com>
* @license GNU General Public License, version 2 (GPL-2.0)
*
* For full copyright and license information, please see
* the docs/CREDITS.txt file.
*
*/
namespace phpbb\install\module\install_database\task;
use phpbb\install\exception\resource_limit_reached_exception;
/**
* Create database schema
*/
class create_schema extends \phpbb\install\task_base
{
/**
* @var \phpbb\install\helper\config
*/
protected $config;
/**
* @var \phpbb\db\driver\driver_interface
*/
protected $db;
/**
* @var \phpbb\db\tools\tools_interface
*/
protected $db_tools;
/**
* @var \phpbb\install\helper\database
*/
protected $database_helper;
/**
* @var \phpbb\filesystem\filesystem_interface
*/
protected $filesystem;
/**
* @var \phpbb\install\helper\iohandler\iohandler_interface
*/
protected $iohandler;
/**
* @var string
*/
protected $phpbb_root_path;
/**
* @var string
*/
protected $php_ext;
/**
* Constructor
*
* @param \phpbb\install\helper\config $config Installer's config provider
* @param \phpbb\install\helper\database $db_helper Installer's database helper
* @param \phpbb\filesystem\filesystem_interface $filesystem Filesystem service
* @param \phpbb\install\helper\iohandler\iohandler_interface $iohandler Installer's input-output handler
* @param string $phpbb_root_path Path phpBB's root
* @param string $php_ext Extension of PHP files
*/
public function __construct(\phpbb\install\helper\config $config,
\phpbb\install\helper\database $db_helper,
\phpbb\filesystem\filesystem_interface $filesystem,
\phpbb\install\helper\iohandler\iohandler_interface $iohandler,
$phpbb_root_path,
$php_ext)
{
$dbms = $db_helper->get_available_dbms($config->get('dbms'));
$dbms = $dbms[$config->get('dbms')]['DRIVER'];
$factory = new \phpbb\db\tools\factory();
$this->db = new $dbms();
$this->db->sql_connect(
$config->get('dbhost'),
$config->get('dbuser'),
$config->get('dbpasswd'),
$config->get('dbname'),
$config->get('dbport'),
false,
false
);
$this->config = $config;
$this->db_tools = $factory->get($this->db);
$this->database_helper = $db_helper;
$this->filesystem = $filesystem;
$this->iohandler = $iohandler;
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $php_ext;
parent::__construct(true);
}
/**
* {@inheritdoc}
*/
public function run()
{
// As this task may take a large amount of time to complete refreshing the page might be necessary for some
// server configurations with limited resources
if (!$this->config->get('pre_schema_forced_refresh'))
{
if ($this->config->get_time_remaining() < 5)
{
$this->config->set('pre_schema_forced_refresh', true);
throw new resource_limit_reached_exception();
}
}
$this->db->sql_return_on_error(true);
$dbms = $this->config->get('dbms');
$dbms_info = $this->database_helper->get_available_dbms($dbms);
$schema_name = $dbms_info[$dbms]['SCHEMA'];
$delimiter = $dbms_info[$dbms]['DELIM'];
$table_prefix = $this->config->get('table_prefix');
if ($dbms === 'mysql')
{
$schema_name .= '_41';
}
$db_schema_path = $this->phpbb_root_path . 'install/schemas/' . $schema_name . '_schema.sql';
// Load database vendor specific code if there is any
if ($this->filesystem->exists($db_schema_path))
{
$sql_query = @file_get_contents($db_schema_path);
$sql_query = preg_replace('#phpbb_#i', $table_prefix, $sql_query);
$sql_query = $this->database_helper->remove_comments($sql_query);
$sql_query = $this->database_helper->split_sql_file($sql_query, $delimiter);
foreach ($sql_query as $sql)
{
if (!$this->db->sql_query($sql))
{
$error = $this->db->sql_error($this->db->get_sql_error_sql());
$this->iohandler->add_error_message('INST_ERR_DB', $error['message']);
}
}
unset($sql_query);
}
$change_prefix = false;
// Generate database schema
if ($this->filesystem->exists($this->phpbb_root_path . 'install/schemas/schema.json'))
{
$db_table_schema = @file_get_contents($this->phpbb_root_path . 'install/schemas/schema.json');
$db_table_schema = json_decode($db_table_schema, true);
$change_prefix = true;
}
else
{
global $table_prefix;
$table_prefix = $this->config->get('table_prefix');
if (!defined('CONFIG_TABLE'))
{
// We need to include the constants file for the table constants
// when we generate the schema from the migration files.
include ($this->phpbb_root_path . 'includes/constants.' . $this->php_ext);
}
$finder = new \phpbb\finder($this->filesystem, $this->phpbb_root_path, null, $this->php_ext);
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db, true);
$schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes,
new \phpbb\config\config(array()),
$this->db,
$db_tools,
$this->phpbb_root_path,
$this->php_ext,
$table_prefix
);
$db_table_schema = $schema_generator->get_schema();
}
if (!defined('CONFIG_TABLE'))
{
// CONFIG_TABLE is required by sql_create_index() to check the
// length of index names. However table_prefix is not defined
// here yet, so we need to create the constant ourselves.
define('CONFIG_TABLE', $table_prefix . 'config');
}
foreach ($db_table_schema as $table_name => $table_data)
{
$this->db_tools->sql_create_table(
( ($change_prefix) ? ($table_prefix . substr($table_name, 6)) : $table_name ),
$table_data
);
}
}
/**
* {@inheritdoc}
*/
static public function get_step_count()
{
return 1;
}
/**
* {@inheritdoc}
*/
public function get_task_lang_name()
{
return 'TASK_CREATE_DATABASE_SCHEMA';
}
}

View File

@@ -259,7 +259,10 @@ class manager
* Replace Emoji and other 4bit UTF-8 chars not allowed by MySQL
* with their Numeric Character Reference's Hexadecimal notation.
*/
$cp_data['pf_' . $row['field_ident']] = utf8_encode_ucr($cp_data['pf_' . $row['field_ident']]);
if (is_string($cp_data['pf_' . $row['field_ident']]))
{
$cp_data['pf_' . $row['field_ident']] = utf8_encode_ucr($cp_data['pf_' . $row['field_ident']]);
}
$check_value = $cp_data['pf_' . $row['field_ident']];