diff --git a/phpBB/includes/acp/acp_extensions.php b/phpBB/includes/acp/acp_extensions.php index e08c2e341b..626f1b09c1 100644 --- a/phpBB/includes/acp/acp_extensions.php +++ b/phpBB/includes/acp/acp_extensions.php @@ -276,6 +276,12 @@ class acp_extensions { $this->template->assign_var('MIGRATOR_ERROR', $e->getLocalisedMessage($this->user)); } + catch (\Exception $e) + { + $stack_trace = phpbb_filter_root_path(str_replace("\n", '
', $e->getTraceAsString())); + $message = $e->getMessage(); + $this->template->assign_var('MIGRATOR_ERROR', '' . $message . '

' . $stack_trace); + } $this->tpl_name = 'acp_ext_enable'; diff --git a/phpBB/includes/functions.php b/phpBB/includes/functions.php index f725d5f996..72241b52f0 100644 --- a/phpBB/includes/functions.php +++ b/phpBB/includes/functions.php @@ -2716,7 +2716,7 @@ function get_backtrace() // Only show function arguments for include etc. // Other parameters may contain sensible information $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); } diff --git a/phpBB/install/startup.php b/phpBB/install/startup.php index b8ceb37342..0cff634795 100644 --- a/phpBB/install/startup.php +++ b/phpBB/install/startup.php @@ -107,7 +107,7 @@ function installer_msg_handler($errno, $msg_text, $errfile, $errline): bool { /** @var \phpbb\install\helper\iohandler\iohandler_interface $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); exit(); } diff --git a/phpBB/phpbb/db/migration/data/v400/rename_auth_role_id_index.php b/phpBB/phpbb/db/migration/data/v400/rename_auth_role_id_index.php new file mode 100644 index 0000000000..353f007e85 --- /dev/null +++ b/phpBB/phpbb/db/migration/data/v400/rename_auth_role_id_index.php @@ -0,0 +1,132 @@ + + * @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; + +class rename_auth_role_id_index extends migration +{ + public static function depends_on() + { + return [ + '\phpbb\db\migration\data\v400\dev', + ]; + } + + public function update_schema() + { + return [ + 'rename_index' => [ + $this->table_prefix . 'acl_groups' => [ + 'auth_role_id' => 'aclgrps_auth_role_id', + 'group_id' => 'aclgrps_group_id', + ], + $this->table_prefix . 'acl_users' => [ + 'auth_role_id' => 'aclusrs_auth_role_id', + 'user_id' => 'aclusrs_user_id', + ], + $this->table_prefix . 'attachments' => [ + 'poster_id' => 'attchmnts_poster_id', + 'topic_id' => 'attchmnts_topic_id', + ], + $this->table_prefix . 'forums' => [ + 'left_right_id' => 'frms_left_right_id', + ], + $this->table_prefix . 'forums_watch' => [ + 'forum_id' => 'frmswtch_forum_id', + 'user_id' => 'frmswtch_user_id', + ], + $this->table_prefix . 'log' => [ + 'forum_id' => 'log_forum_id', + 'topic_id' => 'log_topic_id', + 'user_id' => 'log_user_id', + ], + $this->table_prefix . 'login_attempts' => [ + 'user_id' => 'lgnatmpts_user_id', + ], + $this->table_prefix . 'moderator_cache' => [ + 'forum_id' => 'mdrtrcch_forum_id', + ], + $this->table_prefix . 'modules' => [ + 'left_right_id' => 'mdls_left_right_id', + ], + $this->table_prefix . 'oauth_states' => [ + 'provider' => 'oauthsts_provider', + 'user_id' => 'oauthsts_user_id', + ], + $this->table_prefix . 'oauth_tokens' => [ + 'provider' => 'oauthtkns_provider', + 'user_id' => 'oauthtkns_user_id', + ], + $this->table_prefix . 'poll_options' => [ + 'topic_id' => 'pllopts_topic_id', + ], + $this->table_prefix . 'poll_votes' => [ + 'topic_id' => 'pllvts_topic_id', + ], + $this->table_prefix . 'posts' => [ + 'forum_id' => 'psts_forum_id', + 'poster_id' => 'psts_poster_id', + 'topic_id' => 'psts_topic_id', + ], + $this->table_prefix . 'privmsgs' => [ + 'author_id' => 'pms_author_id', + ], + $this->table_prefix . 'privmsgs_folder' => [ + 'user_id' => 'pmsfldr_user_id', + ], + $this->table_prefix . 'privmsgs_rules' => [ + 'user_id' => 'pmsrls_user_id', + ], + $this->table_prefix . 'privmsgs_to' => [ + 'author_id' => 'pmsto_author_id', + ], + $this->table_prefix . 'reports' => [ + 'post_id' => 'rprts_post_id', + ], + $this->table_prefix . 'search_wordmatch' => [ + 'post_id' => 'wrdmtch_post_id', + ], + $this->table_prefix . 'topics' => [ + 'forum_id' => 'tpcs_forum_id', + ], + $this->table_prefix . 'topics_track' => [ + 'forum_id' => 'tpcstrk_forum_id', + 'topic_id' => 'tpcstrk_topic_id', + ], + $this->table_prefix . 'topics_watch' => [ + 'topic_id' => 'tpcswtch_topic_id', + 'user_id' => 'tpcswtch_user_id', + ], + $this->table_prefix . 'user_group' => [ + 'group_id' => 'usrgrp_group_id', + 'user_id' => 'usrgrp_user_id', + ], + $this->table_prefix . 'user_notifications' => [ + 'user_id' => 'usrntf_user_id', + ], + ], + ]; + } + + 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; + } +} diff --git a/phpBB/phpbb/db/migration/helper.php b/phpBB/phpbb/db/migration/helper.php index bce2efff51..44cd23462a 100644 --- a/phpBB/phpbb/db/migration/helper.php +++ b/phpBB/phpbb/db/migration/helper.php @@ -42,6 +42,7 @@ class helper 'add_primary_keys' => 2, // perform_schema_changes only uses one level, but second is in the function 'add_unique_index' => 2, 'add_index' => 2, + 'rename_index' => 1, ); foreach ($nested_level as $change_type => $data_depth) diff --git a/phpBB/phpbb/db/migration/schema_generator.php b/phpBB/phpbb/db/migration/schema_generator.php index ce07c30d45..90cfddbe5a 100644 --- a/phpBB/phpbb/db/migration/schema_generator.php +++ b/phpBB/phpbb/db/migration/schema_generator.php @@ -187,6 +187,7 @@ class schema_generator 'add_index' => 'KEYS', 'add_unique_index' => 'KEYS', 'drop_keys' => 'KEYS', + 'rename_index' => 'KEYS', ]; $schema_changes = $migration->update_schema(); @@ -206,6 +207,7 @@ class schema_generator { case 'add': case 'change': + case 'rename': $action = function(&$value, $changes, $value_transform = null) { 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 { - if ($change_type !== 'add') + if (!in_array($change_type, ['add', 'rename'])) { return null; } @@ -355,6 +357,23 @@ class schema_generator switch ($schema_type) { 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) { $value[$key] = ['INDEX', $change]; }; diff --git a/phpBB/phpbb/db/tools/doctrine.php b/phpBB/phpbb/db/tools/doctrine.php index aaf44aed68..73987d26ee 100644 --- a/phpBB/phpbb/db/tools/doctrine.php +++ b/phpBB/phpbb/db/tools/doctrine.php @@ -330,6 +330,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} */ @@ -458,34 +471,26 @@ class doctrine implements tools_interface */ protected function alter_schema(callable $callback) { - try + $current_schema = $this->get_schema(); + $new_schema = clone $current_schema; + call_user_func($callback, $new_schema); + + $comparator = new comparator(); + $schemaDiff = $comparator->compareSchemas($current_schema, $new_schema); + $queries = $schemaDiff->toSql($this->get_schema_manager()->getDatabasePlatform()); + + if ($this->return_statements) { - $current_schema = $this->get_schema(); - $new_schema = clone $current_schema; - call_user_func($callback, $new_schema); - - $comparator = new comparator(); - $schemaDiff = $comparator->compareSchemas($current_schema, $new_schema); - $queries = $schemaDiff->toSql($this->get_schema_manager()->getDatabasePlatform()); - - if ($this->return_statements) - { - return $queries; - } - - foreach ($queries as $query) - { - // executeQuery() must be used here because $query might return a result set, for instance REPAIR does - $this->connection->executeQuery($query); - } - - return true; + return $queries; } - catch (Exception $e) + + foreach ($queries as $query) { - // @todo: check if it makes sense to properly handle the exception - return [$e->getMessage()]; + // executeQuery() must be used here because $query might return a result set, for instance REPAIR does + $this->connection->executeQuery($query); } + + return true; } /** @@ -553,6 +558,11 @@ class doctrine implements tools_interface 'use_key' => true, 'per_table' => true, ], + 'rename_index' => [ + 'method' => 'schema_rename_index', + 'use_key' => true, + 'per_table' => true, + ], ]; foreach ($mapping as $action => $params) @@ -839,6 +849,27 @@ class doctrine implements tools_interface $table->addIndex($columns, $index_name); } + /** + * @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); + + if ($safe_check && !$table->hasIndex($index_name_old)) + { + return; + } + + $table->renameIndex($index_name_old, $index_name_new); + } + /** * @param Schema $schema * @param string $table_name diff --git a/phpBB/phpbb/db/tools/tools_interface.php b/phpBB/phpbb/db/tools/tools_interface.php index 0b8cefd8dd..09f47ed566 100644 --- a/phpBB/phpbb/db/tools/tools_interface.php +++ b/phpBB/phpbb/db/tools/tools_interface.php @@ -165,6 +165,17 @@ interface tools_interface */ 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 * diff --git a/phpBB/phpbb/install/installer.php b/phpBB/phpbb/install/installer.php index 23ab5df919..3664b39f2d 100644 --- a/phpBB/phpbb/install/installer.php +++ b/phpBB/phpbb/install/installer.php @@ -280,7 +280,9 @@ class installer } catch (\Exception $e) { - $this->iohandler->add_error_message($e->getMessage()); + $stack_trace = phpbb_filter_root_path(str_replace("\n", '
', $e->getTraceAsString())); + $message = $e->getMessage(); + $this->iohandler->add_error_message($message, $stack_trace); $this->iohandler->send_response(true); $fail_cleanup = true; }