Compare commits

...

36 commits

Author SHA1 Message Date
rxu
d08ff27d72
Merge 599cb06107 into 30ee379576 2025-07-18 08:50:46 +02:00
Marc Alexander
30ee379576 Merge branch '3.3.x' 2025-07-07 15:35:55 +00:00
Marc Alexander
081f2391cb
Merge pull request #6836 from rxu/ticket/17533
[ticket/17533] Fix reverting migrations logic
2025-07-07 17:35:37 +02:00
rxu
0b242b9608
[ticket/17533] Fix reverting migrations logic
Basically, prefer revert_data() if exists.

PHPBB-17533
2025-07-07 11:02:30 +07:00
Marc Alexander
4367bc8d11
Merge pull request #6830 from rxu/ticket/17525
[ticket/17525] Correctly handle Doctrine DB tools exceptions, enrich error info
2025-07-05 09:31:52 +02:00
rxu
aa3f266b8c
[ticket/17525] Address the PR review comments
PHPBB-17525
2025-07-05 12:51:40 +07:00
rxu
10921ebc58
[ticket/17525] Fix migration failure on update
PHPBB-17525
2025-07-04 11:30:46 +07:00
rxu
5eaabb1c39
[ticket/17525] Fix handling index name prefix logic for renaming
PHPBB-17525
2025-07-04 01:25:04 +07:00
rxu
b5c3befa87
[ticket/17525] Fix handling index name prefix logic for renaming
PHPBB-17525
2025-07-02 11:01:49 +07:00
rxu
669af8f3aa
[ticket/17525] Automatically handle index name prefixes
PHPBB-17525
2025-07-01 23:32:36 +07:00
rxu
8e0ec1edd2
[ticket/17525] Automatically handle index name prefixes
PHPBB-17525
2025-07-01 21:01:09 +07:00
rxu
e9157f4d10
[ticket/17525] Fix tests
PHPBB-17525
2025-07-01 16:53:29 +07:00
rxu
4274faa715
[ticket/17525] Provide Doctrine connection via dbtools
PHPBB-17525
2025-07-01 15:53:19 +07:00
rxu
1cadb3818a
[ticket/17525] Provide Doctrine connection object for migrations
PHPBB-17525
2025-07-01 14:27:38 +07:00
rxu
58b3e5dee0
[ticket/17525] Migration to rename actual database indexes if any
Also generate short table names rather than use hardcoded map

PHPBB-17525
2025-07-01 00:11:36 +07:00
rxu
4da8591dd8
[ticket/17525] Run index renaming migration the last in migrations queue
PHPBB-17525
2025-06-27 22:10:27 +07:00
rxu
5e9d616f57
[ticket/17525] Map Sphinx table, add more test assertions
PHPBB-17525
2025-06-25 23:48:45 +07:00
rxu
de1f6329ff
[ticket/17525] Fix tests
PHPBB-17525
2025-06-25 22:44:08 +07:00
rxu
75c5fe9459
[ticket/17525] Add index names test for generated database schema
PHPBB-17525
2025-06-25 22:24:50 +07:00
rxu
a229797cd7
[ticket/17525] Add database schema getter
PHPBB-17525
2025-06-25 21:02:30 +07:00
rxu
1339a31c23
[ticket/17525] Rename all indexes to make names unique
With this reNAMING schema, max index name length is 23.

PHPBB-17525
2025-06-25 17:42:36 +07:00
rxu
45a69eca14
[ticket/17525] Rename migration to reflect its purpose
PHPBB-17525
2025-06-17 14:09:34 +07:00
rxu
84d195ac21
[ticket/17525] Add migration renaming index test
PHPBB-17525
2025-06-17 12:27:47 +07:00
rxu
78dcb0c862
[ticket/17525] Avoid more index name duplication
PHPBB-17525
2025-06-17 09:32:19 +07:00
rxu
7b0b95250c
[ticket/17525] Avoid more index name duplication
Many more tables have indexes with the same names which can cause issues
on SQLite/Postgres. Also, add an option for migrations to rename indexes.

PHPBB-17525
2025-06-17 00:46:17 +07:00
rxu
0e0214a71d
[ticket/17525] Avoid index name duplication (auth_role_id)
phpbb_acl_groups and phpbb_acl_users have indexes
with the same names (auth_role_id) which can cause issues on SQLite/Postgres

PHPBB-17525
2025-06-15 15:51:59 +07:00
rxu
8d1f8af7c6
[ticket/17525] Correctly handle Doctrine DB tools exceptions, enrich error info
PHPBB-17525
2025-06-15 13:03:55 +07:00
rxu
599cb06107
[ticket/16413] Add icon displaying test
PHPBB3-16413
2025-05-20 13:54:27 +07:00
rxu
71f0a3cb62
[ticket/16413] Adjust code and language entry, add test
PHPBB3-16413
2025-05-20 12:02:54 +07:00
rxu
299d6a0030
[ticket/16413] Adjust language entries
PHPBB3-16413
2025-05-20 10:41:16 +07:00
rxu
b84bc9adfc
[ticket/16413] Handle displaying icon on PM screen
Also, save empty color if custom icon name is empty.

PHPBB3-16413
2025-05-20 10:41:15 +07:00
rxu
80af2dc25e
[ticket/16413] refactor JQuery to pure Javascript
PHPBB3-16413
2025-05-20 10:41:15 +07:00
rxu
dbe91cac88
[ticket/16413] Add icon color picker
PHPBB3-16413
2025-05-20 10:41:14 +07:00
rxu
9fad235917
[ticket/16413] Add icon background color option
PHPBB3-16413
2025-05-20 10:41:13 +07:00
rxu
95da75d82c
[ticket/16413] Add icon background color option
PHPBB3-16413
2025-05-20 10:41:12 +07:00
rxu
24c3bc3f1f
[ticket/16413] Add an option to define CPF FontAwesome contact icon
PHPBB3-16413
2025-05-20 10:40:58 +07:00
42 changed files with 894 additions and 59 deletions

View file

@ -11,6 +11,7 @@
<div class="errorbox"> <div class="errorbox">
<p><strong>{{ lang('MIGRATION_EXCEPTION_ERROR') }}</strong></p> <p><strong>{{ lang('MIGRATION_EXCEPTION_ERROR') }}</strong></p>
<p>{{ MIGRATOR_ERROR }}</p> <p>{{ MIGRATOR_ERROR }}</p>
{% if MIGRATOR_ERROR_STACK_TRACE %}<p>{{ MIGRATOR_ERROR_STACK_TRACE|nl2br }}</p>{% endif %}
<p><a href="{{ U_RETURN }}">{{ lang('RETURN_TO_EXTENSION_LIST') }}</a></p> <p><a href="{{ U_RETURN }}">{{ lang('RETURN_TO_EXTENSION_LIST') }}</a></p>
</div> </div>
{% elseif S_PRE_STEP %} {% elseif S_PRE_STEP %}

View file

@ -11,6 +11,7 @@
<div class="errorbox"> <div class="errorbox">
<p><strong>{{ lang('MIGRATION_EXCEPTION_ERROR') }}</strong></p> <p><strong>{{ lang('MIGRATION_EXCEPTION_ERROR') }}</strong></p>
<p>{{ MIGRATOR_ERROR }}</p> <p>{{ MIGRATOR_ERROR }}</p>
{% if MIGRATOR_ERROR_STACK_TRACE %}<p>{{ MIGRATOR_ERROR_STACK_TRACE|nl2br }}</p>{% endif %}
<p><a href="{{ U_RETURN }}">{{ lang('RETURN_TO_EXTENSION_LIST') }}</a></p> <p><a href="{{ U_RETURN }}">{{ lang('RETURN_TO_EXTENSION_LIST') }}</a></p>
</div> </div>
{% elseif S_PRE_STEP %} {% elseif S_PRE_STEP %}

View file

@ -91,6 +91,12 @@
<dd><input type="checkbox" class="radio" id="field_is_contact" name="field_is_contact" value="1"<!-- IF S_FIELD_CONTACT --> checked="checked"<!-- ENDIF --> /></dd> <dd><input type="checkbox" class="radio" id="field_is_contact" name="field_is_contact" value="1"<!-- IF S_FIELD_CONTACT --> checked="checked"<!-- ENDIF --> /></dd>
<dd><input class="text medium" type="text" name="field_contact_desc" id="field_contact_desc" value="{FIELD_CONTACT_DESC}" /> <label for="field_contact_desc">{L_FIELD_CONTACT_DESC}</label></dd> <dd><input class="text medium" type="text" name="field_contact_desc" id="field_contact_desc" value="{FIELD_CONTACT_DESC}" /> <label for="field_contact_desc">{L_FIELD_CONTACT_DESC}</label></dd>
<dd><input class="text medium" type="text" name="field_contact_url" id="field_contact_url" value="{FIELD_CONTACT_URL}" /> <label for="field_contact_url">{L_FIELD_CONTACT_URL}</label></dd> <dd><input class="text medium" type="text" name="field_contact_url" id="field_contact_url" value="{FIELD_CONTACT_URL}" /> <label for="field_contact_url">{L_FIELD_CONTACT_URL}</label></dd>
<dt><label for="field_icon">{{ lang('FIELD_ICON') ~ lang('COLON') }}</label><br /><span>{{ lang('FIELD_ICON_EXPLAIN') }}</span></dt>
<dd><input name="field_icon" id="field_icon" type="text" size="15" maxlength="255" value="{{ FIELD_ICON }}" placeholder="{{ lang('FIELD_ICON') }}" />{{ Icon('font', FIELD_ICON, '', true, 'acp-icon', {'style': 'margin:0 6px;' ~ (FIELD_ICON_COLOR ? (' color: #' ~ FIELD_ICON_COLOR ~ ';') : '')}) }}</dd>
<dd>
<input name="field_icon_color" type="text" id="contact_field_icon_bgcolor" value="{{ FIELD_ICON_COLOR }}" size="7" maxlength="6" placeholder="{{ lang('FIELD_ICON_COLOR') }}" />
<input type="color" id="field_icon_color_picker" aria-label="{{ lang('FIELD_ICON_COLOR') }}">
</dd>
<!-- EVENT acp_profile_contact_last --> <!-- EVENT acp_profile_contact_last -->
</dl> </dl>
{% EVENT acp_profile_contact_after %} {% EVENT acp_profile_contact_after %}

View file

@ -3152,3 +3152,29 @@ span + .o-icon {
.acp-icon-disabled { .acp-icon-disabled {
color: #d0d0d0; color: #d0d0d0;
} }
input[type="color"] {
background-color: transparent;
border: solid 1px #d3d3d3;
border-radius: 50%;
width: 24px;
height: 24px;
padding: 2px;
cursor: pointer;
-webkit-appearance: none;
}
input[type="color"]::-webkit-color-swatch-wrapper {
padding: 0;
}
input[type="color"]::-webkit-color-swatch {
border: 0;
border-radius: 50%;
}
input[type="color"]::-moz-color-swatch {
border: 0;
border-radius: 50%;
}

View file

@ -246,6 +246,67 @@ function parse_document(container)
}); });
} }
/**
* Automatically display custom profile fields FontAwesome icon
*/
const DEFAULT_COLOR = '#000000';
const HEX_REGEX = /^#[A-Fa-f0-9]{6}$/;
const colorPicker = document.getElementById('field_icon_color_picker');
const colorText = colorPicker.previousElementSibling;
const syncColors = (source, target) => {
const value = '#' + source.value.trim();
target.value = HEX_REGEX.test(value) ? value : DEFAULT_COLOR;
};
const handleInput = ({ target }) => {
if (target === colorPicker) {
colorText.value = target.value.substring(1);
} else {
syncColors(colorText, colorPicker);
}
const icon = field_icon?.nextElementSibling;
if (icon && icon.tagName.toLowerCase() === 'i') {
icon.style.color = colorPicker.value;
}
};
colorPicker.addEventListener('input', handleInput);
colorText.addEventListener('input', handleInput);
colorText.addEventListener('blur', () => {
if (!colorText.value.trim()) {
colorPicker.value = DEFAULT_COLOR;
}
});
syncColors(colorText, colorPicker);
var field_icon = document.getElementById('field_icon');
if (!field_icon.nextElementSibling) {
icon_demo = document.createElement('i');
icon_demo.setAttribute('style', `margin:0 6px; color: ${colorPicker.value}`);
icon_demo.setAttribute('class', `o-icon o-icon-font fa-fw fas acp-icon`);
field_icon.after(icon_demo);
}
const updateIconClass = (element, newClass) => {
element.classList.forEach(className => {
if (className.startsWith('fa-') && className !== 'fa-fw') {
element.classList.remove(className);
}
});
element.classList.add(`fa-${newClass}`);
};
field_icon.addEventListener('keyup', function() {
updateIconClass(this.nextElementSibling, this.value);
});
field_icon.addEventListener('blur', function() {
updateIconClass(this.nextElementSibling, this.value);
});
/** /**
* Run onload functions * Run onload functions
*/ */

View file

@ -58,6 +58,7 @@ $db_doctrine = $ref->newInstanceWithoutConstructor();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db_doctrine, true); $db_tools = $factory->get($db_doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml'); $tables_data = \Symfony\Component\Yaml\Yaml::parseFile($phpbb_root_path . '/config/default/container/tables.yml');
$tables = []; $tables = [];

View file

@ -276,6 +276,11 @@ class acp_extensions
{ {
$this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user)); $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
} }
catch (\Exception $e)
{
$this->template->assign_var('MIGRATOR_ERROR', $e->getMessage());
$this->template->assign_var('MIGRATOR_ERROR_STACK_TRACE', phpbb_filter_root_path($e->getTraceAsString()));
}
$this->tpl_name = 'acp_ext_enable'; $this->tpl_name = 'acp_ext_enable';
@ -363,6 +368,11 @@ class acp_extensions
{ {
$this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user)); $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user));
} }
catch (\Exception $e)
{
$this->template->assign_var('MIGRATOR_ERROR', $e->getMessage());
$this->template->assign_var('MIGRATOR_ERROR_STACK_TRACE', phpbb_filter_root_path($e->getTraceAsString()));
}
$this->tpl_name = 'acp_ext_delete_data'; $this->tpl_name = 'acp_ext_delete_data';

View file

@ -360,6 +360,7 @@ class acp_profile
$field_row = array_merge($profile_field->get_default_option_values(), array( $field_row = array_merge($profile_field->get_default_option_values(), array(
'field_ident' => str_replace(' ', '_', utf8_clean_string($request->variable('field_ident', '', true))), 'field_ident' => str_replace(' ', '_', utf8_clean_string($request->variable('field_ident', '', true))),
'field_required' => 0, 'field_required' => 0,
'field_icon' => json_encode(['name' => '', 'color' => '']),
'field_show_novalue'=> 0, 'field_show_novalue'=> 0,
'field_hide' => 0, 'field_hide' => 0,
'field_show_profile'=> 0, 'field_show_profile'=> 0,
@ -381,7 +382,7 @@ class acp_profile
// $exclude contains the data we gather in each step // $exclude contains the data we gather in each step
$exclude = array( $exclude = array(
1 => array('field_ident', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_pm', 'field_show_on_vt', 'field_show_on_ml', 'field_required', 'field_show_novalue', 'field_hide', 'field_show_profile', 'field_no_view', 'field_is_contact', 'field_contact_desc', 'field_contact_url'), 1 => array('field_ident', 'field_icon', 'field_icon_color', 'lang_name', 'lang_explain', 'field_option_none', 'field_show_on_reg', 'field_show_on_pm', 'field_show_on_vt', 'field_show_on_ml', 'field_required', 'field_show_novalue', 'field_hide', 'field_show_profile', 'field_no_view', 'field_is_contact', 'field_contact_desc', 'field_contact_url'),
2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'), 2 => array('field_length', 'field_maxlen', 'field_minlen', 'field_validation', 'field_novalue', 'field_default_value'),
3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options') 3 => array('l_lang_name', 'l_lang_explain', 'l_lang_default_value', 'l_lang_options')
); );
@ -427,6 +428,13 @@ class acp_profile
$options = $profile_field->prepare_options_form($exclude, $visibility_ary); $options = $profile_field->prepare_options_form($exclude, $visibility_ary);
$field_icon_data = json_decode($field_row['field_icon'], true);
$field_icon_name = $request->variable('field_icon', $field_icon_data['name'] ?: '');
$field_icon_color = $field_icon_name ? $request->variable('field_icon_color', $field_icon_data['color'] ?: '') : '';
$cp->vars['field_icon'] = json_encode([
'name' => $field_icon_name,
'color' => $field_icon_color,
]);
$cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string($request->variable('field_ident', $field_row['field_ident'], true)) : $request->variable('field_ident', $field_row['field_ident']); $cp->vars['field_ident'] = ($action == 'create' && $step == 1) ? utf8_clean_string($request->variable('field_ident', $field_row['field_ident'], true)) : $request->variable('field_ident', $field_row['field_ident']);
$cp->vars['lang_name'] = $request->variable('lang_name', $field_row['lang_name'], true); $cp->vars['lang_name'] = $request->variable('lang_name', $field_row['lang_name'], true);
$cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true); $cp->vars['lang_explain'] = $request->variable('lang_explain', $field_row['lang_explain'], true);
@ -630,6 +638,7 @@ class acp_profile
{ {
// Create basic options - only small differences between field types // Create basic options - only small differences between field types
case 1: case 1:
$field_icon_data = json_decode($cp->vars['field_icon'], true);
$template_vars = array( $template_vars = array(
'S_STEP_ONE' => true, 'S_STEP_ONE' => true,
'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false, 'S_FIELD_REQUIRED' => ($cp->vars['field_required']) ? true : false,
@ -648,6 +657,8 @@ class acp_profile
'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']), 'L_LANG_SPECIFIC' => sprintf($user->lang['LANG_SPECIFIC_OPTIONS'], $config['default_lang']),
'FIELD_TYPE' => $profile_field->get_name(), 'FIELD_TYPE' => $profile_field->get_name(),
'FIELD_IDENT' => $cp->vars['field_ident'], 'FIELD_IDENT' => $cp->vars['field_ident'],
'FIELD_ICON' => $field_icon_data['name'],
'FIELD_ICON_COLOR' => $field_icon_data['color'],
'LANG_NAME' => $cp->vars['lang_name'], 'LANG_NAME' => $cp->vars['lang_name'],
'LANG_EXPLAIN' => $cp->vars['lang_explain'], 'LANG_EXPLAIN' => $cp->vars['lang_explain'],
); );
@ -984,6 +995,7 @@ class acp_profile
'field_is_contact' => $cp->vars['field_is_contact'], 'field_is_contact' => $cp->vars['field_is_contact'],
'field_contact_desc' => $cp->vars['field_contact_desc'], 'field_contact_desc' => $cp->vars['field_contact_desc'],
'field_contact_url' => $cp->vars['field_contact_url'], 'field_contact_url' => $cp->vars['field_contact_url'],
'field_icon' => $cp->vars['field_icon'],
); );
$field_data = $cp->vars; $field_data = $cp->vars;

View file

@ -2716,7 +2716,7 @@ function get_backtrace()
// Only show function arguments for include etc. // Only show function arguments for include etc.
// Other parameters may contain sensible information // Other parameters may contain sensible information
$argument = ''; $argument = '';
if (!empty($trace['args'][0]) && in_array($trace['function'], array('include', 'require', 'include_once', 'require_once'))) if (!empty($trace['args'][0]) && in_array($trace['function'], array('include', 'require', 'include_once', 'require_once', 'try_apply')))
{ {
$argument = htmlspecialchars(phpbb_filter_root_path($trace['args'][0]), ENT_COMPAT); $argument = htmlspecialchars(phpbb_filter_root_path($trace['args'][0]), ENT_COMPAT);
} }

View file

@ -373,8 +373,11 @@ function view_message($id, $mode, $folder_id, $msg_id, $folder, $message_row)
if ($cp_block_row['S_PROFILE_CONTACT']) if ($cp_block_row['S_PROFILE_CONTACT'])
{ {
$icon_data = json_decode($cp_block_row['PROFILE_FIELD_ICON'], true);
$template->assign_block_vars('contact', array( $template->assign_block_vars('contact', array(
'ID' => $cp_block_row['PROFILE_FIELD_IDENT'], 'ID' => $cp_block_row['PROFILE_FIELD_IDENT'],
'ICON' => $icon_data['name'],
'ICON_COLOR'=> $icon_data['color'],
'NAME' => $cp_block_row['PROFILE_FIELD_NAME'], 'NAME' => $cp_block_row['PROFILE_FIELD_NAME'],
'U_CONTACT' => $cp_block_row['PROFILE_FIELD_CONTACT'], 'U_CONTACT' => $cp_block_row['PROFILE_FIELD_CONTACT'],
)); ));

View file

@ -107,7 +107,7 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline): bool
{ {
/** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */ /** @var \phpbb\install\helper\iohandler\iohandler_interface $iohandler */
$iohandler = $phpbb_installer_container->get('installer.helper.iohandler'); $iohandler = $phpbb_installer_container->get('installer.helper.iohandler');
$iohandler->add_error_message($msg); $iohandler->add_error_message($msg, get_backtrace());
$iohandler->send_response(true); $iohandler->send_response(true);
exit(); exit();
} }

View file

@ -93,6 +93,9 @@ $lang = array_merge($lang, array(
'FIELD_DESCRIPTION' => 'Field description', 'FIELD_DESCRIPTION' => 'Field description',
'FIELD_DESCRIPTION_EXPLAIN' => 'The explanation for this field presented to the user.', 'FIELD_DESCRIPTION_EXPLAIN' => 'The explanation for this field presented to the user.',
'FIELD_DROPDOWN' => 'Dropdown box', 'FIELD_DROPDOWN' => 'Dropdown box',
'FIELD_ICON' => 'Field icon',
'FIELD_ICON_COLOR' => 'Icon colour',
'FIELD_ICON_EXPLAIN' => 'Enter a Font Awesome icon name to display with this contact field. Optionally, set its colour using a 6-digit hex code or the colour picker. Leave blank to use phpBBs default icon and clear the colour.',
'FIELD_IDENT' => 'Field identification', 'FIELD_IDENT' => 'Field identification',
'FIELD_IDENT_ALREADY_EXIST' => 'The chosen field identification already exist. Please choose another name.', 'FIELD_IDENT_ALREADY_EXIST' => 'The chosen field identification already exist. Please choose another name.',
'FIELD_IDENT_EXPLAIN' => 'The field identification is a name to identify the profile field within the database and the templates.', 'FIELD_IDENT_EXPLAIN' => 'The field identification is a name to identify the profile field within the database and the templates.',

View file

@ -13,6 +13,7 @@
namespace phpbb\db\doctrine; namespace phpbb\db\doctrine;
use InvalidArgumentException; use InvalidArgumentException;
use phpbb\db\tools\doctrine as doctrine_dbtools;
class table_helper class table_helper
{ {
@ -123,6 +124,54 @@ class table_helper
} }
} }
/**
* Maps table names to their short names for the purpose of prefixing tables' index names.
*
* @param array $table_names Table names with prefix to add to the map.
* @param string $table_prefix Tables prefix.
*
* @return array<string, string> Pairs of table names and their short name representations.
* @psalm-return array{string, string}
*/
public static function map_short_table_names(array $table_names = [], string $table_prefix = ''): array
{
$short_table_names_map = [];
foreach ($table_names as $table_name)
{
$short_table_names_map[$table_name] = self::generate_shortname(doctrine_dbtools::remove_prefix($table_name, $table_prefix));
}
return $short_table_names_map;
}
/**
* Generates short table names for the purpose of prefixing tables' index names.
*
* @param string $table_name Table name without prefix to generate its short name.
*
* @return string Short table name.
*/
public static function generate_shortname(string $table_name = ''): string
{
// Only shorten actually long names
if (strlen($table_name) > 4)
{
// Remove vowels
$table_name = preg_replace('/([^aeiou_])([aeiou]+)/i', '$1', $table_name);
// Remove underscores
$table_name = str_replace('_', '', $table_name);
// Remove repeated consonants and their combinations (like 'ss', 'flfl' and similar)
$table_name = preg_replace('/(.+)\\1+/i', '$1', $table_name);
// Restrict short name length to 10 chars
$table_name = substr($table_name, 0, 10);
}
return $table_name;
}
/** /**
* Private constructor. Call methods of table_helper statically. * Private constructor. Call methods of table_helper statically.
*/ */

View file

@ -0,0 +1,51 @@
<?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\db\migration\data\v400;
class custom_profile_field_contact_icon extends \phpbb\db\migration\migration
{
public function effectively_installed()
{
return $this->db_tools->sql_column_exists($this->table_prefix . 'profile_fields', 'field_icon');
}
public static function depends_on()
{
return [
'\phpbb\db\migration\data\v400\dev',
];
}
public function update_schema()
{
return array(
'add_columns' => [
$this->table_prefix . 'profile_fields' => [
'field_icon' => array('VCHAR:255', json_encode(['name' => '', 'color' => ''])),
],
],
);
}
public function revert_schema()
{
return array(
'drop_columns' => array(
$this->table_prefix . 'profile_fields' => array(
'field_icon',
),
),
);
}
}

View file

@ -0,0 +1,146 @@
<?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\db\migration\data\v400;
use phpbb\db\migration\migration;
use phpbb\db\doctrine\table_helper;
use phpbb\db\tools\doctrine as doctrine_dbtools;
class rename_duplicated_index_names extends migration
{
/**
* @var array
*/
protected static $table_keys;
/**
* @var array
*/
protected static $rename_index;
public static function depends_on()
{
return [
'\phpbb\db\migration\data\v400\storage_track_index',
];
}
public function update_schema()
{
if (!isset(self::$rename_index))
{
if (!isset(self::$table_keys))
{
$this->get_tables_index_names();
}
$short_table_names = table_helper::map_short_table_names(array_keys(self::$table_keys), $this->table_prefix);
foreach (self::$table_keys as $table_name => $key_names)
{
$prefixless_table_name = doctrine_dbtools::remove_prefix($table_name, $this->table_prefix);
foreach ($key_names as $key_name)
{
// If 'old' key name is already new format, do not rename it
if (str_starts_with($key_name, $short_table_names[$table_name]))
{
continue;
}
// If 'old' key name is prefixed by its table name with and/or without table name common prefix
// (f.e. 'phpbb_log_log_time'), remove it to prefix with the relevant table's short name
$cleaned_key_name = $key_name;
foreach ([$table_name, $prefixless_table_name] as $prefix)
{
$cleaned_key_name = doctrine_dbtools::remove_prefix($cleaned_key_name, $prefix);
}
$key_name_new = $short_table_names[$table_name] . '_' . $cleaned_key_name;
self::$rename_index[$table_name][$key_name] = $key_name_new;
}
}
}
return [
'rename_index' => self::$rename_index,
];
}
public function revert_schema()
{
$schema = $this->update_schema();
array_walk($schema['rename_index'], function (&$index_data, $table_name) {
$index_data = array_flip($index_data);
});
return $schema;
}
protected function get_schema()
{
$self_classname = '\\' . str_replace('/', '\\', self::class);
$finder_factory = new \phpbb\finder\factory(null, false, $this->phpbb_root_path, $this->php_ext);
$finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$self_class_index = array_search($self_classname, $migrator_classes);
unset($migrator_classes[$self_class_index]);
$schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes,
$this->config,
$this->db,
$this->db_tools,
$this->phpbb_root_path,
$this->php_ext,
$this->table_prefix,
$this->tables
);
return $schema_generator->get_schema();
}
public function get_tables_index_names()
{
$schema_manager = $this->db_tools->get_connection()->createSchemaManager();
$table_names = $schema_manager->listTableNames();
if (!empty($table_names))
{
foreach ($table_names as $table_name)
{
$indices = $schema_manager->listTableIndexes($table_name);
$indices = array_keys(array_filter($indices,
function (\Doctrine\DBAL\Schema\Index $index)
{
return !$index->isPrimary();
})
);
if (!empty($indices))
{
self::$table_keys[$table_name] = $indices;
}
}
}
else
{
foreach ($this->get_schema() as $table_name => $table_data)
{
if (isset($table_data['KEYS']))
{
self::$table_keys[$table_name] = array_keys($table_data['KEYS']);
}
}
}
}
}

View file

@ -42,6 +42,7 @@ class helper
'add_primary_keys' => 2, // perform_schema_changes only uses one level, but second is in the function 'add_primary_keys' => 2, // perform_schema_changes only uses one level, but second is in the function
'add_unique_index' => 2, 'add_unique_index' => 2,
'add_index' => 2, 'add_index' => 2,
'rename_index' => 1,
); );
foreach ($nested_level as $change_type => $data_depth) foreach ($nested_level as $change_type => $data_depth)

View file

@ -72,6 +72,8 @@ abstract class migration implements migration_interface
$this->php_ext = $php_ext; $this->php_ext = $php_ext;
$this->errors = array(); $this->errors = array();
$this->db_tools->set_table_prefix($this->table_prefix);
} }
/** /**

View file

@ -187,6 +187,7 @@ class schema_generator
'add_index' => 'KEYS', 'add_index' => 'KEYS',
'add_unique_index' => 'KEYS', 'add_unique_index' => 'KEYS',
'drop_keys' => 'KEYS', 'drop_keys' => 'KEYS',
'rename_index' => 'KEYS',
]; ];
$schema_changes = $migration->update_schema(); $schema_changes = $migration->update_schema();
@ -206,6 +207,7 @@ class schema_generator
{ {
case 'add': case 'add':
case 'change': case 'change':
case 'rename':
$action = function(&$value, $changes, $value_transform = null) { $action = function(&$value, $changes, $value_transform = null) {
self::set_all($value, $changes, $value_transform); self::set_all($value, $changes, $value_transform);
}; };
@ -347,7 +349,7 @@ class schema_generator
*/ */
private static function get_value_transform(string $change_type, string $schema_type) : Closure|null private static function get_value_transform(string $change_type, string $schema_type) : Closure|null
{ {
if ($change_type !== 'add') if (!in_array($change_type, ['add', 'rename']))
{ {
return null; return null;
} }
@ -355,6 +357,23 @@ class schema_generator
switch ($schema_type) switch ($schema_type)
{ {
case 'index': case 'index':
if ($change_type == 'rename')
{
return function(&$value, $key, $change) {
if (isset($value[$key]))
{
$data_backup = $value[$key];
unset($value[$key]);
$value[$change] = $data_backup;
unset($data_backup);
}
else
{
return null;
}
};
}
return function(&$value, $key, $change) { return function(&$value, $key, $change) {
$value[$key] = ['INDEX', $change]; $value[$key] = ['INDEX', $change];
}; };

View file

@ -575,7 +575,7 @@ class migrator
$state['migration_data_state']['_total_time'] : 0.0; $state['migration_data_state']['_total_time'] : 0.0;
$elapsed_time = microtime(true); $elapsed_time = microtime(true);
$steps = array_merge($this->helper->reverse_update_data($migration->update_data()), $migration->revert_data()); $steps = $migration->revert_data() ?: $this->helper->reverse_update_data($migration->update_data());
$result = $this->process_data_step($steps, $state['migration_data_state']); $result = $this->process_data_step($steps, $state['migration_data_state']);
$elapsed_time = microtime(true) - $elapsed_time; $elapsed_time = microtime(true) - $elapsed_time;

View file

@ -49,6 +49,11 @@ class doctrine implements tools_interface
*/ */
private $return_statements; private $return_statements;
/**
* @var string
*/
private $table_prefix;
/** /**
* Database tools constructors. * Database tools constructors.
* *
@ -61,6 +66,14 @@ class doctrine implements tools_interface
$this->connection = $connection; $this->connection = $connection;
} }
/**
* {@inheritDoc}
*/
public function get_connection(): Connection
{
return $this->connection;
}
/** /**
* @return AbstractSchemaManager * @return AbstractSchemaManager
* *
@ -86,6 +99,14 @@ class doctrine implements tools_interface
return $this->get_schema_manager()->createSchema(); return $this->get_schema_manager()->createSchema();
} }
/**
* {@inheritDoc}
*/
public function set_table_prefix($table_prefix): void
{
$this->table_prefix = $table_prefix;
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -330,6 +351,19 @@ class doctrine implements tools_interface
); );
} }
/**
* {@inheritDoc}
*/
public function sql_rename_index(string $table_name, string $index_name_old, string $index_name_new)
{
return $this->alter_schema(
function (Schema $schema) use ($table_name, $index_name_old, $index_name_new): void
{
$this->schema_rename_index($schema, $table_name, $index_name_old, $index_name_new);
}
);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -384,6 +418,23 @@ class doctrine implements tools_interface
} }
} }
/**
* {@inheritDoc}
*/
public static function add_prefix(string $name, string $prefix): string
{
return str_ends_with($prefix, '_') ? $prefix . $name : $prefix . '_' . $name;
}
/**
* {@inheritDoc}
*/
public static function remove_prefix(string $name, string $prefix = ''): string
{
$prefix = str_ends_with($prefix, '_') ? $prefix : $prefix . '_';
return $prefix && str_starts_with($name, $prefix) ? substr($name, strlen($prefix)) : $name;
}
/** /**
* Returns an array of indices for either unique and primary keys, or simple indices. * Returns an array of indices for either unique and primary keys, or simple indices.
* *
@ -457,8 +508,6 @@ class doctrine implements tools_interface
* @return bool|string[] * @return bool|string[]
*/ */
protected function alter_schema(callable $callback) protected function alter_schema(callable $callback)
{
try
{ {
$current_schema = $this->get_schema(); $current_schema = $this->get_schema();
$new_schema = clone $current_schema; $new_schema = clone $current_schema;
@ -481,12 +530,6 @@ class doctrine implements tools_interface
return true; return true;
} }
catch (Exception $e)
{
// @todo: check if it makes sense to properly handle the exception
return [$e->getMessage()];
}
}
/** /**
* Alter table. * Alter table.
@ -553,6 +596,11 @@ class doctrine implements tools_interface
'use_key' => true, 'use_key' => true,
'per_table' => true, 'per_table' => true,
], ],
'rename_index' => [
'method' => 'schema_rename_index',
'use_key' => true,
'per_table' => true,
],
]; ];
foreach ($mapping as $action => $params) foreach ($mapping as $action => $params)
@ -610,6 +658,7 @@ class doctrine implements tools_interface
} }
$table = $schema->createTable($table_name); $table = $schema->createTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
$dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName(); $dbms_name = $this->get_schema_manager()->getDatabasePlatform()->getName();
foreach ($table_data['COLUMNS'] as $column_name => $column_data) foreach ($table_data['COLUMNS'] as $column_name => $column_data)
@ -635,6 +684,7 @@ class doctrine implements tools_interface
foreach ($table_data['KEYS'] as $key_name => $key_data) foreach ($table_data['KEYS'] as $key_name => $key_data)
{ {
$columns = (is_array($key_data[1])) ? $key_data[1] : [$key_data[1]]; $columns = (is_array($key_data[1])) ? $key_data[1] : [$key_data[1]];
$key_name = !str_starts_with($key_name, $short_table_name) ? self::add_prefix($key_name, $short_table_name) : $key_name;
// Supports key columns defined with there length // Supports key columns defined with there length
$columns = array_map(function (string $column) $columns = array_map(function (string $column)
@ -667,6 +717,8 @@ class doctrine implements tools_interface
} }
/** /**
* Removes a table
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param bool $safe_check * @param bool $safe_check
@ -684,6 +736,8 @@ class doctrine implements tools_interface
} }
/** /**
* Adds column to a table
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $column_name * @param string $column_name
@ -714,6 +768,8 @@ class doctrine implements tools_interface
} }
/** /**
* Alters column properties
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $column_name * @param string $column_name
@ -744,6 +800,8 @@ class doctrine implements tools_interface
} }
/** /**
* Alters column properties or adds a column
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $column_name * @param string $column_name
@ -766,6 +824,8 @@ class doctrine implements tools_interface
} }
/** /**
* Removes a column in a table
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $column_name * @param string $column_name
@ -818,6 +878,8 @@ class doctrine implements tools_interface
} }
/** /**
* Creates non-unique index for a table
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $index_name * @param string $index_name
@ -830,6 +892,8 @@ class doctrine implements tools_interface
{ {
$columns = (is_array($column)) ? $column : [$column]; $columns = (is_array($column)) ? $column : [$column];
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
$index_name = !str_starts_with($index_name, $short_table_name) ? self::add_prefix($index_name, $short_table_name) : $index_name;
if ($safe_check && $table->hasIndex($index_name)) if ($safe_check && $table->hasIndex($index_name))
{ {
@ -840,6 +904,38 @@ class doctrine implements tools_interface
} }
/** /**
* Renames table index
*
* @param Schema $schema
* @param string $table_name
* @param string $index_name_old
* @param string $index_name_new
* @param bool $safe_check
*
* @throws SchemaException
*/
protected function schema_rename_index(Schema $schema, string $table_name, string $index_name_old, string $index_name_new, bool $safe_check = false): void
{
$table = $schema->getTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
if (!$table->hasIndex($index_name_old))
{
$index_name_old = !str_starts_with($index_name_old, $short_table_name) ? self::add_prefix($index_name_old, $short_table_name) : self::remove_prefix($index_name_old, $short_table_name);
}
$index_name_new = !str_starts_with($index_name_new, $short_table_name) ? self::add_prefix($index_name_new, $short_table_name) : $index_name_new;
if ($safe_check && !$table->hasIndex($index_name_old))
{
return;
}
$table->renameIndex($index_name_old, $index_name_new);
}
/**
* Creates unique (non-primary) index for a table
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $index_name * @param string $index_name
@ -852,6 +948,8 @@ class doctrine implements tools_interface
{ {
$columns = (is_array($column)) ? $column : [$column]; $columns = (is_array($column)) ? $column : [$column];
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
$index_name = !str_starts_with($index_name, $short_table_name) ? self::add_prefix($index_name, $short_table_name) : $index_name;
if ($safe_check && $table->hasIndex($index_name)) if ($safe_check && $table->hasIndex($index_name))
{ {
@ -862,6 +960,8 @@ class doctrine implements tools_interface
} }
/** /**
* Removes table index
*
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name
* @param string $index_name * @param string $index_name
@ -872,6 +972,12 @@ class doctrine implements tools_interface
protected function schema_index_drop(Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void protected function schema_index_drop(Schema $schema, string $table_name, string $index_name, bool $safe_check = false): void
{ {
$table = $schema->getTable($table_name); $table = $schema->getTable($table_name);
$short_table_name = table_helper::generate_shortname(self::remove_prefix($table_name, $this->table_prefix));
if (!$table->hasIndex($index_name))
{
$index_name = !str_starts_with($index_name, $short_table_name) ? self::add_prefix($index_name, $short_table_name) : self::remove_prefix($index_name, $short_table_name);
}
if ($safe_check && !$table->hasIndex($index_name)) if ($safe_check && !$table->hasIndex($index_name))
{ {
@ -882,6 +988,8 @@ class doctrine implements tools_interface
} }
/** /**
* Creates primary key for a table
*
* @param $column * @param $column
* @param Schema $schema * @param Schema $schema
* @param string $table_name * @param string $table_name

View file

@ -165,6 +165,17 @@ interface tools_interface
*/ */
public function sql_create_index(string $table_name, string $index_name, $column); public function sql_create_index(string $table_name, string $index_name, $column);
/**
* Rename index
*
* @param string $table_name Table to modify
* @param string $index_name_old Name of the index to rename
* @param string $index_name_new New name of the index being renamed
*
* @return bool|string[] True if the statements have been executed
*/
public function sql_rename_index(string $table_name, string $index_name_old, string $index_name_new);
/** /**
* Drop Index * Drop Index
* *
@ -215,4 +226,41 @@ interface tools_interface
* @return void * @return void
*/ */
public function sql_truncate_table(string $table_name): void; public function sql_truncate_table(string $table_name): void;
/**
* Gets current Doctrine DBAL connection
*
* @return \Doctrine\DBAL\Connection
*/
public function get_connection(): \Doctrine\DBAL\Connection;
/**
* Adds prefix to a string if needed
*
* @param string $name Table name with tables prefix
* @param string $prefix Prefix to add
*
* @return string Prefixed name
*/
public static function add_prefix(string $name, string $prefix): string;
/**
* Removes prefix from string if exists. If prefix is empty,
* the first part of the string ending with underscore will be removed.
*
* @param string $name String to remove the prefix from
* @param string $prefix Prefix to remove
*
* @return string Prefixless string
*/
public static function remove_prefix(string $name, string $prefix = ''): string;
/**
* Sets table prefix
*
* @param string $table_prefix String to test vs prefix
*
* @return void
*/
public function set_table_prefix(string $table_prefix): void;
} }

View file

@ -393,6 +393,7 @@ class database
$doctrine_db = connection_factory::get_connection_from_params($dbms, $dbhost, $dbuser, $dbpass, $dbname, $dbport); $doctrine_db = connection_factory::get_connection_from_params($dbms, $dbhost, $dbuser, $dbpass, $dbname, $dbport);
$db_tools_factory = new \phpbb\db\tools\factory(); $db_tools_factory = new \phpbb\db\tools\factory();
$db_tools = $db_tools_factory->get($doctrine_db); $db_tools = $db_tools_factory->get($doctrine_db);
$db_tools->set_table_prefix($table_prefix);
$tables = $db_tools->sql_list_tables(); $tables = $db_tools->sql_list_tables();
$tables = array_map('strtolower', $tables); $tables = array_map('strtolower', $tables);
$table_intersect = array_intersect($tables, $table_ary); $table_intersect = array_intersect($tables, $table_ary);

View file

@ -280,7 +280,9 @@ class installer
} }
catch (\Exception $e) catch (\Exception $e)
{ {
$this->iohandler->add_error_message($e->getMessage()); $stack_trace = phpbb_filter_root_path(str_replace("\n", '<br>', $e->getTraceAsString()));
$message = $e->getMessage();
$this->iohandler->add_error_message($message, $stack_trace);
$this->iohandler->send_response(true); $this->iohandler->send_response(true);
$fail_cleanup = true; $fail_cleanup = true;
} }

View file

@ -98,6 +98,7 @@ class add_tables extends task_base
$this->schema_file_path = $phpbb_root_path . 'store/schema.json'; $this->schema_file_path = $phpbb_root_path . 'store/schema.json';
$this->table_prefix = $this->config->get('table_prefix'); $this->table_prefix = $this->config->get('table_prefix');
$this->change_prefix = $this->config->get('change_table_prefix', true); $this->change_prefix = $this->config->get('change_table_prefix', true);
$this->db_tools->set_table_prefix($this->table_prefix);
parent::__construct(true); parent::__construct(true);
} }

View file

@ -145,6 +145,7 @@ class create_schema_file extends \phpbb\install\task_base
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes(); $migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($this->db_doctrine, true); $db_tools = $factory->get($this->db_doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$tables_data = \Symfony\Component\Yaml\Yaml::parseFile($this->phpbb_root_path . '/config/default/container/tables.yml'); $tables_data = \Symfony\Component\Yaml\Yaml::parseFile($this->phpbb_root_path . '/config/default/container/tables.yml');
$tables = []; $tables = [];
foreach ($tables_data['parameters'] as $parameter => $table) foreach ($tables_data['parameters'] as $parameter => $table)

View file

@ -332,6 +332,7 @@ class manager
$tpl_fields[] = [ $tpl_fields[] = [
'PROFILE_FIELD_IDENT' => $field_ident, 'PROFILE_FIELD_IDENT' => $field_ident,
'PROFILE_FIELD_ICON' => $field_data['field_icon'],
'PROFILE_FIELD_TYPE' => $field_data['field_type'], 'PROFILE_FIELD_TYPE' => $field_data['field_type'],
'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']), 'PROFILE_FIELD_NAME' => $profile_field->get_field_name($field_data['lang_name']),
'PROFILE_FIELD_EXPLAIN' => $this->language->lang($field_data['lang_explain']), 'PROFILE_FIELD_EXPLAIN' => $this->language->lang($field_data['lang_explain']),
@ -484,6 +485,7 @@ class manager
$tpl_fields['row'] += [ $tpl_fields['row'] += [
"PROFILE_{$ident_upper}_IDENT" => $ident, "PROFILE_{$ident_upper}_IDENT" => $ident,
"PROFILE_{$ident_upper}_ICON" => $ident_ary['data']['field_icon'],
"PROFILE_{$ident_upper}_VALUE" => $value, "PROFILE_{$ident_upper}_VALUE" => $value,
"PROFILE_{$ident_upper}_VALUE_RAW" => $value_raw, "PROFILE_{$ident_upper}_VALUE_RAW" => $value_raw,
"PROFILE_{$ident_upper}_CONTACT" => $contact_url, "PROFILE_{$ident_upper}_CONTACT" => $contact_url,
@ -498,6 +500,7 @@ class manager
$tpl_fields['blockrow'][] = [ $tpl_fields['blockrow'][] = [
'PROFILE_FIELD_IDENT' => $ident, 'PROFILE_FIELD_IDENT' => $ident,
'PROFILE_FIELD_ICON' => $ident_ary['data']['field_icon'],
'PROFILE_FIELD_VALUE' => $value, 'PROFILE_FIELD_VALUE' => $value,
'PROFILE_FIELD_VALUE_RAW' => $value_raw, 'PROFILE_FIELD_VALUE_RAW' => $value_raw,
'PROFILE_FIELD_CONTACT' => $contact_url, 'PROFILE_FIELD_CONTACT' => $contact_url,

View file

@ -71,7 +71,10 @@
<div> <div>
<!-- ENDIF --> <!-- ENDIF -->
<a href="<!-- IF contact.U_CONTACT -->{contact.U_CONTACT}<!-- ELSE -->{contact.U_PROFILE_AUTHOR}<!-- ENDIF -->" title="{contact.NAME}"<!-- IF $S_LAST_CELL --> class="last-cell"<!-- ENDIF -->> <a href="<!-- IF contact.U_CONTACT -->{contact.U_CONTACT}<!-- ELSE -->{contact.U_PROFILE_AUTHOR}<!-- ENDIF -->" title="{contact.NAME}"<!-- IF $S_LAST_CELL --> class="last-cell"<!-- ENDIF -->>
{% if contact.ID == 'pm' %} {% if contact.ICON %}
{% set color = contact.ICON_COLOR ? ({style: 'color: #' ~ contact.ICON_COLOR}) : [] %}
{{ Icon('font', contact.ICON, '', true, '', color) }}
{% elseif contact.ID == 'pm' %}
{{ Icon('font', 'message', '', true, 'far contact-icon') }} {{ Icon('font', 'message', '', true, 'far contact-icon') }}
{% elseif contact.ID == 'email' %} {% elseif contact.ID == 'email' %}
{{ Icon('font', 'at', '', true, 'fas contact-icon') }} {{ Icon('font', 'at', '', true, 'fas contact-icon') }}

View file

@ -193,7 +193,10 @@
<!-- ENDIF --> <!-- ENDIF -->
<a href="<!-- IF postrow.contact.U_CONTACT -->{postrow.contact.U_CONTACT}<!-- ELSE -->{postrow.U_POST_AUTHOR}<!-- ENDIF -->" title="{postrow.contact.NAME}"<!-- IF $S_LAST_CELL --> class="last-cell"<!-- ENDIF -->> <a href="<!-- IF postrow.contact.U_CONTACT -->{postrow.contact.U_CONTACT}<!-- ELSE -->{postrow.U_POST_AUTHOR}<!-- ENDIF -->" title="{postrow.contact.NAME}"<!-- IF $S_LAST_CELL --> class="last-cell"<!-- ENDIF -->>
{% EVENT viewtopic_body_contact_icon_prepend %} {% EVENT viewtopic_body_contact_icon_prepend %}
{% if postrow.contact.ID == 'pm' %} {% if postrow.contact.ICON %}
{% set color = postrow.contact.ICON_COLOR ? ({style: 'color: #' ~ contact.ICON_COLOR}) : [] %}
{{ Icon('font', contact.ICON, '', true, '', color) }}
{% elseif postrow.contact.ID == 'pm' %}
{{ Icon('font', 'message', '', true, 'far contact-icon') }} {{ Icon('font', 'message', '', true, 'far contact-icon') }}
{% elseif postrow.contact.ID == 'email' %} {% elseif postrow.contact.ID == 'email' %}
{{ Icon('font', 'at', '', true, 'fas contact-icon') }} {{ Icon('font', 'at', '', true, 'fas contact-icon') }}

View file

@ -2193,8 +2193,11 @@ for ($i = 0, $end = count($post_list); $i < $end; ++$i)
if ($field_data['S_PROFILE_CONTACT']) if ($field_data['S_PROFILE_CONTACT'])
{ {
$icon_data = json_decode($field_data['PROFILE_FIELD_ICON'], true);
$template->assign_block_vars('postrow.contact', array( $template->assign_block_vars('postrow.contact', array(
'ID' => $field_data['PROFILE_FIELD_IDENT'], 'ID' => $field_data['PROFILE_FIELD_IDENT'],
'ICON' => $icon_data['name'],
'ICON_COLOR'=> $icon_data['color'],
'NAME' => $field_data['PROFILE_FIELD_NAME'], 'NAME' => $field_data['PROFILE_FIELD_NAME'],
'U_CONTACT' => $field_data['PROFILE_FIELD_CONTACT'], 'U_CONTACT' => $field_data['PROFILE_FIELD_CONTACT'],
)); ));

View file

@ -28,10 +28,12 @@ class phpbb_dbal_auto_increment_test extends phpbb_database_test_case
{ {
parent::setUp(); parent::setUp();
$table_prefix = 'prefix_';
$this->db = $this->new_dbal(); $this->db = $this->new_dbal();
$this->db_doctrine = $this->new_doctrine_dbal(); $this->db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->tools = $factory->get($this->db_doctrine); $this->tools = $factory->get($this->db_doctrine);
$this->tools->set_table_prefix($table_prefix);
$this->table_data = array( $this->table_data = array(
'COLUMNS' => array( 'COLUMNS' => array(

View file

@ -35,12 +35,15 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
protected function setUp(): void protected function setUp(): void
{ {
parent::setUp(); parent::setUp();
$table_prefix = 'prefix_';
$this->db = $this->new_dbal(); $this->db = $this->new_dbal();
$this->doctrine_db = $this->new_doctrine_dbal(); $this->doctrine_db = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->tools = $factory->get($this->doctrine_db); $this->tools = $factory->get($this->doctrine_db);
$this->tools->set_table_prefix($table_prefix);
$this->table_data = array( $this->table_data = array(
'COLUMNS' => array( 'COLUMNS' => array(
@ -232,23 +235,25 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_column_change_with_index() public function test_column_change_with_index()
{ {
$short_table_name = \phpbb\db\doctrine\table_helper::generate_shortname('table_name');
// Create column // Create column
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012', array('DECIMAL', 0))); $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012', array('DECIMAL', 0)));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
// Create index over the column // Create index over the column
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_i_bug_12012'));
$this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012', array('c_bug_12012', 'c_bool'))); $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'i_bug_12012', array('c_bug_12012', 'c_bool')));
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_i_bug_12012'));
// Change type from int to string // Change type from int to string
$this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12012', array('VCHAR:100', ''))); $this->assertTrue($this->tools->sql_column_change('prefix_table_name', 'c_bug_12012', array('VCHAR:100', '')));
// Remove the index // Remove the index
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_i_bug_12012'));
$this->assertTrue($this->tools->sql_index_drop('prefix_table_name', 'i_bug_12012')); $this->assertTrue($this->tools->sql_index_drop('prefix_table_name', 'i_bug_12012'));
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'i_bug_12012')); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_i_bug_12012'));
// Remove the column // Remove the column
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012')); $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012'));
@ -301,19 +306,21 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_column_remove_with_index() public function test_column_remove_with_index()
{ {
$short_table_name = \phpbb\db\doctrine\table_helper::generate_shortname('table_name');
// Create column // Create column
$this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); $this->assertFalse($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
$this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012_2', array('UINT', 4))); $this->assertTrue($this->tools->sql_column_add('prefix_table_name', 'c_bug_12012_2', array('UINT', 4)));
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
// Create index over the column // Create index over the column
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_bug_12012_2'));
$this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_2', array('c_bug_12012_2', 'c_bool'))); $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_2', array('c_bug_12012_2', 'c_bool')));
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_2')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_bug_12012_2'));
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_bug_12012_3'));
$this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_3', array('c_bug_12012_2'))); $this->assertTrue($this->tools->sql_create_index('prefix_table_name', 'bug_12012_3', array('c_bug_12012_2')));
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'bug_12012_3')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_bug_12012_3'));
// Remove the column // Remove the column
$this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2')); $this->assertTrue($this->tools->sql_column_exists('prefix_table_name', 'c_bug_12012_2'));
@ -443,24 +450,24 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
public function test_index_exists() public function test_index_exists()
{ {
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'i_simple')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', \phpbb\db\doctrine\table_helper::generate_shortname('table_name') . '_i_simple'));
} }
public function test_unique_index_exists() public function test_unique_index_exists()
{ {
$this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq')); $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', \phpbb\db\doctrine\table_helper::generate_shortname('table_name') . '_i_uniq'));
} }
public function test_create_index_against_index_exists() public function test_create_index_against_index_exists()
{ {
$this->tools->sql_create_index('prefix_table_name', 'fookey', array('c_timestamp', 'c_decimal')); $this->tools->sql_create_index('prefix_table_name', 'fookey', array('c_timestamp', 'c_decimal'));
$this->assertTrue($this->tools->sql_index_exists('prefix_table_name', 'fookey')); $this->assertTrue($this->tools->sql_index_exists('prefix_table_name', \phpbb\db\doctrine\table_helper::generate_shortname('table_name') . '_fookey'));
} }
public function test_create_unique_index_against_unique_index_exists() public function test_create_unique_index_against_unique_index_exists()
{ {
$this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id')); $this->tools->sql_create_unique_index('prefix_table_name', 'i_uniq_ts_id', array('c_timestamp', 'c_id'));
$this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', 'i_uniq_ts_id')); $this->assertTrue($this->tools->sql_unique_index_exists('prefix_table_name', \phpbb\db\doctrine\table_helper::generate_shortname('table_name') . '_i_uniq_ts_id'));
} }
public function test_create_int_default_null() public function test_create_int_default_null()
@ -493,27 +500,28 @@ class phpbb_dbal_db_tools_test extends phpbb_database_test_case
$table_suffix = str_repeat('a', 25 - strlen($table_prefix)); $table_suffix = str_repeat('a', 25 - strlen($table_prefix));
$table_name = $table_prefix . $table_suffix; $table_name = $table_prefix . $table_suffix;
$short_table_name = \phpbb\db\doctrine\table_helper::generate_shortname($table_suffix);
$this->tools->sql_create_table($table_name, $this->table_data); $this->tools->sql_create_table($table_name, $this->table_data);
// Index name and table suffix and table prefix have > maximum index length chars in total. // Index name and table suffix and table prefix have > maximum index length chars in total.
// Index name and table suffix have <= maximum index length chars in total. // Index name and table suffix have <= maximum index length chars in total.
$long_index_name = str_repeat('i', $max_index_length - strlen($table_suffix)); $long_index_name = str_repeat('i', $max_index_length - strlen($table_suffix));
$this->assertFalse($this->tools->sql_index_exists($table_name, $long_index_name)); $this->assertFalse($this->tools->sql_index_exists($table_name, $short_table_name . '_' . $long_index_name));
$this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp'))); $this->assertTrue($this->tools->sql_create_index($table_name, $long_index_name, array('c_timestamp')));
$this->assertTrue($this->tools->sql_index_exists($table_name, $long_index_name)); $this->assertTrue($this->tools->sql_index_exists($table_name, $short_table_name . '_' . $long_index_name));
// Index name and table suffix have > maximum index length chars in total. // Index name and table suffix have > maximum index length chars in total.
$very_long_index_name = str_repeat('i', $max_index_length); $very_long_index_name = str_repeat('i', $max_index_length);
$this->assertFalse($this->tools->sql_index_exists($table_name, $very_long_index_name)); $this->assertFalse($this->tools->sql_index_exists($table_name, $short_table_name . '_' . $very_long_index_name));
$this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp'))); $this->assertTrue($this->tools->sql_create_index($table_name, $very_long_index_name, array('c_timestamp')));
$this->assertTrue($this->tools->sql_index_exists($table_name, $very_long_index_name)); $this->assertTrue($this->tools->sql_index_exists($table_name, $short_table_name . '_' . $very_long_index_name));
$this->tools->sql_table_drop($table_name); $this->tools->sql_table_drop($table_name);
// Index name has > maximum index length chars - that should not be possible. // Index name has > maximum index length chars - that should not be possible.
$too_long_index_name = str_repeat('i', $max_index_length + 1); $too_long_index_name = str_repeat('i', $max_index_length + 1);
$this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $too_long_index_name)); $this->assertFalse($this->tools->sql_index_exists('prefix_table_name', $short_table_name . '_' . $too_long_index_name));
$this->setExpectedTriggerError(E_USER_ERROR); // TODO: Do we want to keep this limitation, if yes reimplement the user check $this->setExpectedTriggerError(E_USER_ERROR); // TODO: Do we want to keep this limitation, if yes reimplement the user check
/* https://github.com/phpbb/phpbb/blob/aee5e373bca6cd20d44b99585d3b758276a2d7e6/phpBB/phpbb/db/tools/tools.php#L1488-L1517 */ /* https://github.com/phpbb/phpbb/blob/aee5e373bca6cd20d44b99585d3b758276a2d7e6/phpBB/phpbb/db/tools/tools.php#L1488-L1517 */
$this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp')); $this->tools->sql_create_index('prefix_table_name', $too_long_index_name, array('c_timestamp'));

View file

@ -0,0 +1,65 @@
<?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.
*
*/
class phpbb_dbal_migration_schema_index extends \phpbb\db\migration\migration
{
function update_schema()
{
return [
'add_tables' => [
$this->table_prefix . 'foobar1' => [
'COLUMNS' => [
'user_id' => ['UINT', 0],
'username' => ['VCHAR:50', 0],
],
'KEYS' => [
'tstidx_user_id' => ['UNIQUE', 'user_id'],
'tstidx_username' => ['INDEX', 'username'],
],
],
$this->table_prefix . 'foobar2' => [
'COLUMNS' => [
'ban_userid' => ['ULINT', 0],
'ban_ip' => ['VCHAR:40', ''],
'ban_reason' => ['VCHAR:100', ''],
],
'KEYS' => [
'tstidx_ban_userid' => ['UNIQUE', 'ban_userid'],
'tstidxban_data' => ['INDEX', ['ban_ip', 'ban_reason']],
],
],
],
'rename_index' => [
$this->table_prefix . 'foobar1' => [
'tstidx_user_id' => 'fbr1_user_id',
'tstidx_username' => 'fbr1_username',
],
$this->table_prefix . 'foobar2' => [
'tstidx_ban_userid' => 'fbr2_ban_userid',
'tstidxban_data' => 'fbr2_ban_data',
],
],
];
}
function revert_schema()
{
return [
'drop_tables' => [
$this->table_prefix . 'foobar1',
$this->table_prefix . 'foobar2',
],
];
}
}

View file

@ -24,6 +24,7 @@ require_once __DIR__ . '/migration/revert_table_with_dependency.php';
require_once __DIR__ . '/migration/fail.php'; require_once __DIR__ . '/migration/fail.php';
require_once __DIR__ . '/migration/installed.php'; require_once __DIR__ . '/migration/installed.php';
require_once __DIR__ . '/migration/schema.php'; require_once __DIR__ . '/migration/schema.php';
require_once __DIR__ . '/migration/schema_index.php';
class phpbb_dbal_migrator_test extends phpbb_database_test_case class phpbb_dbal_migrator_test extends phpbb_database_test_case
{ {
@ -52,12 +53,15 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
protected function setUp(): void protected function setUp(): void
{ {
global $table_prefix;
parent::setUp(); parent::setUp();
$this->db = $this->new_dbal(); $this->db = $this->new_dbal();
$this->doctrine_db = $this->new_doctrine_dbal(); $this->doctrine_db = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->doctrine_db); $this->db_tools = $factory->get($this->doctrine_db);
$this->db_tools->set_table_prefix($table_prefix);
$this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config'); $this->config = new \phpbb\config\db($this->db, new phpbb_mock_cache, 'phpbb_config');
@ -416,4 +420,86 @@ class phpbb_dbal_migrator_test extends phpbb_database_test_case
$this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1')); $this->assertFalse($this->db_tools->sql_column_exists('phpbb_config', 'test_column1'));
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar')); $this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar'));
} }
public function test_rename_index()
{
$this->migrator->set_migrations(array('phpbb_dbal_migration_schema_index'));
while (!$this->migrator->finished())
{
$this->migrator->update();
}
$this->assertTrue($this->db_tools->sql_unique_index_exists('phpbb_foobar1', 'fbr1_user_id'));
$this->assertTrue($this->db_tools->sql_index_exists('phpbb_foobar1', 'fbr1_username'));
$this->assertTrue($this->db_tools->sql_unique_index_exists('phpbb_foobar2', 'fbr2_ban_userid'));
$this->assertTrue($this->db_tools->sql_index_exists('phpbb_foobar2', 'fbr2_ban_data'));
while ($this->migrator->migration_state('phpbb_dbal_migration_schema_index'))
{
$this->migrator->revert('phpbb_dbal_migration_schema_index');
}
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar1'));
$this->assertFalse($this->db_tools->sql_table_exists('phpbb_foobar2'));
}
public function test_schema_generator(): array
{
global $phpbb_root_path, $phpEx;
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx);
$finder = $finder_factory->get();
$migrator_classes = $finder->core_path('phpbb/db/migration/data/')->get_classes();
$schema_generator = new \phpbb\db\migration\schema_generator(
$migrator_classes,
$this->config,
$this->db,
$this->db_tools,
$phpbb_root_path,
$phpEx,
'phpbb_',
self::get_core_tables()
);
$db_table_schema = $schema_generator->get_schema();
$this->assertNotEmpty($db_table_schema);
return $db_table_schema;
}
/**
* @depends test_schema_generator
*/
public function test_table_indexes(array $db_table_schema)
{
$table_keys = [];
foreach ($db_table_schema as $table_name => $table_data)
{
if (isset($table_data['KEYS']))
{
foreach ($table_data['KEYS'] as $key_name => $key_data)
{
$table_keys[$table_name][] = $key_name;
}
}
}
$this->assertNotEmpty($table_keys);
$table_names = array_merge(array_keys($db_table_schema), ['phpbb_custom_table']);
$short_table_names = \phpbb\db\doctrine\table_helper::map_short_table_names($table_names, 'phpbb_');
$this->assertEquals('phpbb_custom_table', array_search(\phpbb\db\doctrine\table_helper::generate_shortname('custom_table'), $short_table_names));
$this->assertEquals($short_table_names['phpbb_custom_table'], \phpbb\db\doctrine\table_helper::generate_shortname('custom_table'));
foreach ($table_keys as $table_name => $key_names)
{
$index_prefix = $short_table_names[$table_name] . '_';
foreach ($key_names as $key_name)
{
$this->assertEquals(0, strpos($key_name, $index_prefix), "$key_name does not contain $index_prefix");
}
}
}
} }

View file

@ -154,6 +154,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
{ {
$phpbb_root_path = __DIR__ . './../../phpBB/'; $phpbb_root_path = __DIR__ . './../../phpBB/';
$php_ext = 'php'; $php_ext = 'php';
$table_prefix = 'phpbb_';
$config = new \phpbb\config\config(array('version' => PHPBB_VERSION)); $config = new \phpbb\config\config(array('version' => PHPBB_VERSION));
$db = $this->new_dbal(); $db = $this->new_dbal();
@ -162,7 +163,7 @@ class phpbb_extension_manager_test extends phpbb_database_test_case
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $php_ext); $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $php_ext);
$db_tools = $factory->get($db_doctrine); $db_tools = $factory->get($db_doctrine);
$table_prefix = 'phpbb_'; $db_tools->set_table_prefix($table_prefix);
$container = new phpbb_mock_container_builder(); $container = new phpbb_mock_container_builder();

View file

@ -37,6 +37,7 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
{ {
parent::setUp(); parent::setUp();
$this->table_prefix = 'phpbb_';
$this->config = new \phpbb\config\config(array( $this->config = new \phpbb\config\config(array(
'version' => '3.1.0', 'version' => '3.1.0',
)); ));
@ -45,13 +46,13 @@ class phpbb_extension_metadata_manager_test extends phpbb_database_test_case
$phpbb_dispatcher = new phpbb_mock_event_dispatcher(); $phpbb_dispatcher = new phpbb_mock_event_dispatcher();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->db_doctrine); $this->db_tools = $factory->get($this->db_doctrine);
$this->db_tools->set_table_prefix($this->table_prefix);
$finder_factory = $this->createMock('\phpbb\finder\factory'); $finder_factory = $this->createMock('\phpbb\finder\factory');
$this->phpbb_root_path = __DIR__ . '/'; $this->phpbb_root_path = __DIR__ . '/';
$this->phpEx = 'php'; $this->phpEx = 'php';
$this->cache = new \phpbb\cache\service(new phpbb_mock_cache(), $this->config, $this->db, $phpbb_dispatcher, $this->phpbb_root_path, $this->phpEx); $this->cache = new \phpbb\cache\service(new phpbb_mock_cache(), $this->config, $this->db, $phpbb_dispatcher, $this->phpbb_root_path, $this->phpEx);
$this->table_prefix = 'phpbb_';
$container = new phpbb_mock_container_builder(); $container = new phpbb_mock_container_builder();
$cache_path = $this->phpbb_root_path . 'cache/twig'; $cache_path = $this->phpbb_root_path . 'cache/twig';

View file

@ -0,0 +1,95 @@
<?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.
*
*/
/**
* @group functional
*/
class phpbb_functional_profile_field_contact_icon_test extends phpbb_functional_test_case
{
protected function setUp(): void
{
parent::setUp();
$this->login();
$this->admin_login();
$this->add_lang('acp/profile');
}
public function test_add_contact_field_icon()
{
// Custom profile fields page
$crawler = self::request('GET', 'adm/index.php?i=acp_profile&mode=profile&sid=' . $this->sid);
// Get any contact profile field, f.e. phpbb_twitter
$twitter_field = $crawler->filter('tbody tr')
->reduce(
function ($node, $i) {
$text = $node->text();
return (strpos($text, 'phpbb_twitter') !== false);
});
$twitter_edit_url = $twitter_field->filter('.actions a')->eq(2)->attr('href');
$crawler = self::request('GET', 'adm/' . $twitter_edit_url . '&sid=' . $this->sid);
$this->assertStringContainsString('phpbb_twitter', $crawler->text());
$form = $crawler->selectButton('Profile type specific options')->form([
'field_icon' => 'twitter',
'field_icon_color' => '1da1f2',
]);
$crawler= self::submit($form);
$this->assertStringContainsString('Profile type specific options', $crawler->text());
$form = $crawler->selectButton('Save')->form();
$crawler= self::submit($form);
$this->assertContainsLang('CHANGED_PROFILE_FIELD', $crawler->text());
// Ensure contact filed icon was saved correctly
$crawler = self::request('GET', 'adm/' . $twitter_edit_url . '&sid=' . $this->sid);
$this->assertEquals('twitter', $crawler->filter('#field_icon')->attr('value'));
$this->assertEquals('1da1f2', $crawler->filter('#contact_field_icon_bgcolor')->attr('value'));
$this->assertEquals(1, $crawler->filter('i.fa-twitter')->count());
$this->assertStringContainsString('#1da1f2;', $crawler->filter('i.fa-twitter')->attr('style'));
}
/**
* @depends test_add_contact_field_icon
*/
public function test_display_field_icon()
{
$this->add_lang('ucp');
// Set Twitter profile field
$crawler = self::request('GET', 'ucp.php?i=ucp_profile&mode=profile_info');
$this->assertContainsLang('UCP_PROFILE_PROFILE_INFO', $crawler->filter('#cp-main h2')->text());
$form = $crawler->selectButton('Submit')->form([
'pf_phpbb_twitter' => 'phpbb_twitter',
]);
$crawler = self::submit($form);
$this->assertContainsLang('PROFILE_UPDATED', $crawler->filter('#message')->text());
// Ensure Twitter icon displays in topic
$crawler = self::request('GET', 'viewtopic.php?t=1');
$this->assertEquals('Twitter', $crawler->filter('#profile1 a[title="Twitter"]')->attr('title'));
$this->assertStringContainsString('#1da1f2', $crawler->filter('#profile1 a[title="Twitter"] > i.fa-twitter')->attr('style'));
// Ensure Twitter icon displays on view private message screen
$message_id = $this->create_private_message('Self PM', 'Self PM', [2]);
$crawler = self::request('GET', 'ucp.php?i=pm&mode=view&p=' . $message_id . '&sid=' . $this->sid);
$this->assertEquals('Twitter', $crawler->filter('.profile-contact a[title="Twitter"]')->attr('title'));
$this->assertStringContainsString('#1da1f2', $crawler->filter('.profile-contact a[title="Twitter"] > i.fa-twitter')->attr('style'));
}
}

View file

@ -55,6 +55,10 @@ class migrations_check_config_added_test extends phpbb_test_case
{ {
global $phpbb_root_path, $phpEx; global $phpbb_root_path, $phpEx;
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = new \phpbb\config\config([ $this->config = new \phpbb\config\config([
'search_type' => '\phpbb\search\fulltext_mysql', 'search_type' => '\phpbb\search\fulltext_mysql',
]); ]);
@ -63,9 +67,7 @@ class migrations_check_config_added_test extends phpbb_test_case
$this->db_doctrine = $this->createMock(\Doctrine\DBAL\Connection::class); $this->db_doctrine = $this->createMock(\Doctrine\DBAL\Connection::class);
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->db_doctrine); $this->db_tools = $factory->get($this->db_doctrine);
$this->table_prefix = 'phpbb_'; $this->db_tools->set_table_prefix($this->table_prefix);
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$tools = [ $tools = [
new \phpbb\db\migration\tool\config($this->config), new \phpbb\db\migration\tool\config($this->config),

View file

@ -23,6 +23,8 @@ class get_callable_from_step_test extends phpbb_database_test_case
$db = $this->new_dbal(); $db = $this->new_dbal();
$db_doctrine = $this->new_doctrine_dbal(); $db_doctrine = $this->new_doctrine_dbal();
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix($table_prefix);
$user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock(); $user = $this->getMockBuilder('\phpbb\user')->disableOriginalConstructor()->getMock();
$user->ip = '127.0.0.1'; $user->ip = '127.0.0.1';
$module_manager = new \phpbb\module\module_manager( $module_manager = new \phpbb\module\module_manager(
@ -38,7 +40,7 @@ class get_callable_from_step_test extends phpbb_database_test_case
new phpbb_mock_container_builder(), new phpbb_mock_container_builder(),
new \phpbb\config\config(array()), new \phpbb\config\config(array()),
$db, $db,
$factory->get($db_doctrine), $db_tools,
'phpbb_migrations', 'phpbb_migrations',
$phpbb_root_path, $phpbb_root_path,
$php_ext, $php_ext,

View file

@ -30,14 +30,16 @@ class schema_generator_test extends phpbb_test_case
parent::setUp(); parent::setUp();
$this->table_prefix = 'phpbb_';
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
$this->config = new \phpbb\config\config(array()); $this->config = new \phpbb\config\config(array());
$this->db = new \phpbb\db\driver\sqlite3(); $this->db = new \phpbb\db\driver\sqlite3();
$this->doctrine_db = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file()); $this->doctrine_db = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$this->db_tools = $factory->get($this->doctrine_db); $this->db_tools = $factory->get($this->doctrine_db);
$this->table_prefix = 'phpbb_'; $this->db_tools->set_table_prefix($this->table_prefix);
$this->phpbb_root_path = $phpbb_root_path;
$this->php_ext = $phpEx;
} }
protected function get_schema_generator(array $class_names) protected function get_schema_generator(array $class_names)

View file

@ -88,6 +88,7 @@ abstract class phpbb_database_test_case extends TestCase
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file()); $doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine, true); $db_tools = $factory->get($doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, self::get_core_tables()); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, self::get_core_tables());
file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema())); file_put_contents(self::$schema_file, json_encode($schema_generator->get_schema()));

View file

@ -327,6 +327,8 @@ class phpbb_database_test_connection_manager
*/ */
protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db, \Doctrine\DBAL\Connection $doctrine) protected function load_schema_from_file($directory, \phpbb\db\driver\driver_interface $db, \Doctrine\DBAL\Connection $doctrine)
{ {
global $table_prefix;
$schema = $this->dbms['SCHEMA']; $schema = $this->dbms['SCHEMA'];
if ($this->config['dbms'] == 'phpbb\db\driver\mysql') if ($this->config['dbms'] == 'phpbb\db\driver\mysql')
@ -363,7 +365,7 @@ class phpbb_database_test_connection_manager
} }
else else
{ {
global $phpbb_root_path, $phpEx, $table_prefix; global $phpbb_root_path, $phpEx;
$finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx); $finder = new \phpbb\finder\finder(null, false, $phpbb_root_path, $phpEx);
$classes = $finder->core_path('phpbb/db/migration/data/') $classes = $finder->core_path('phpbb/db/migration/data/')
@ -373,6 +375,7 @@ class phpbb_database_test_connection_manager
$doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file()); $doctrine = \phpbb\db\doctrine\connection_factory::get_connection(new phpbb_mock_config_php_file());
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine, true); $db_tools = $factory->get($doctrine, true);
$db_tools->set_table_prefix($table_prefix);
$tables = phpbb_database_test_case::get_core_tables(); $tables = phpbb_database_test_case::get_core_tables();
$schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables); $schema_generator = new \phpbb\db\migration\schema_generator($classes, new \phpbb\config\config(array()), $db, $db_tools, $phpbb_root_path, $phpEx, $table_prefix, $tables);
@ -381,6 +384,7 @@ class phpbb_database_test_connection_manager
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$db_tools = $factory->get($doctrine); $db_tools = $factory->get($doctrine);
$db_tools->set_table_prefix($table_prefix);
foreach ($db_table_schema as $table_name => $table_data) foreach ($db_table_schema as $table_name => $table_data)
{ {
$db_tools->sql_create_table( $db_tools->sql_create_table(

View file

@ -286,6 +286,7 @@ class phpbb_functional_test_case extends phpbb_test_case
$factory = new \phpbb\db\tools\factory(); $factory = new \phpbb\db\tools\factory();
$finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx); $finder_factory = new \phpbb\finder\factory(null, false, $phpbb_root_path, $phpEx);
$db_tools = $factory->get($db_doctrine); $db_tools = $factory->get($db_doctrine);
$db_tools->set_table_prefix(self::$config['table_prefix']);
$container = new phpbb_mock_container_builder(); $container = new phpbb_mock_container_builder();
$migrator = new \phpbb\db\migrator( $migrator = new \phpbb\db\migrator(