From 5cd0aad3c6329bcb67de3b2513aa61d397381e1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= Date: Sun, 28 Jul 2019 17:51:17 +0530 Subject: [PATCH 1/3] [ticket/16111] Add core.message_history_modify_sql_ary PHPBB3-16111 --- phpBB/includes/functions_privmsgs.php | 39 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index baadf5bdee..fe2308ec29 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1985,9 +1985,16 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode $recipients = array_unique($recipients); // Get History Messages (could be newer) - $sql = 'SELECT t.*, p.*, u.* - FROM ' . PRIVMSGS_TABLE . ' p, ' . PRIVMSGS_TO_TABLE . ' t, ' . USERS_TABLE . ' u - WHERE t.msg_id = p.msg_id + $sql_array = array( + 'SELECT' => 'SELECT t.*, p.*, u.*', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + PRIVMSGS_TO_TABLE => 't', + USERS_TABLE => 'u' + ) + ); + + $sql_where = 't.msg_id = p.msg_id AND p.author_id = u.user_id AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ') AND ' . $db->sql_in_set('t.author_id', $recipients, false, true) . " @@ -1998,14 +2005,34 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode if (!$message_row['root_level']) { - $sql .= " AND (p.root_level = $msg_id OR (p.root_level = 0 AND p.msg_id = $msg_id))"; + $sql_where .= " AND (p.root_level = $msg_id OR (p.root_level = 0 AND p.msg_id = $msg_id))"; } else { - $sql .= " AND (p.root_level = " . $message_row['root_level'] . ' OR p.msg_id = ' . $message_row['root_level'] . ')'; + $sql_where .= " AND (p.root_level = " . $message_row['root_level'] . ' OR p.msg_id = ' . $message_row['root_level'] . ')'; } - $sql .= ' ORDER BY p.message_time DESC'; + $sql_ary = array( + 'SELECT' => $sql_array['SELECT'], + 'FROM' => $sql_array['FROM'], + 'LEFT_JOIN' => array(), + + 'WHERE' => $sql_where, + + 'ORDER_BY' => 'p.message_time DESC', + ); + + /** + * Event to modify the SQL query before the message history in private message is queried + * + * @event core.message_history_modify_sql_ary + * @var array sql_ary The SQL array to get the data of the message history in private message + * @since 3.2.8-RC1 + */ + $vars = array('sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.message_history_modify_sql_ary', compact($vars))); + + $sql = $db->sql_build_query('SELECT', $sql_ary); $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); From 01d0457f6789dc4bee502b7b0337f29499e744c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= Date: Sun, 28 Jul 2019 18:06:16 +0530 Subject: [PATCH 2/3] [ticket/16111] Add core.message_history_modify_sql_ary PHPBB3-16111 --- phpBB/includes/functions_privmsgs.php | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index fe2308ec29..0806120f21 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -1985,15 +1985,6 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode $recipients = array_unique($recipients); // Get History Messages (could be newer) - $sql_array = array( - 'SELECT' => 'SELECT t.*, p.*, u.*', - 'FROM' => array( - PRIVMSGS_TABLE => 'p', - PRIVMSGS_TO_TABLE => 't', - USERS_TABLE => 'u' - ) - ); - $sql_where = 't.msg_id = p.msg_id AND p.author_id = u.user_id AND t.folder_id NOT IN (' . PRIVMSGS_NO_BOX . ', ' . PRIVMSGS_HOLD_BOX . ') @@ -2013,12 +2004,14 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode } $sql_ary = array( - 'SELECT' => $sql_array['SELECT'], - 'FROM' => $sql_array['FROM'], + 'SELECT' => 'SELECT t.*, p.*, u.*', + 'FROM' => array( + PRIVMSGS_TABLE => 'p', + PRIVMSGS_TO_TABLE => 't', + USERS_TABLE => 'u' + ), 'LEFT_JOIN' => array(), - 'WHERE' => $sql_where, - 'ORDER_BY' => 'p.message_time DESC', ); @@ -2033,6 +2026,8 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode extract($phpbb_dispatcher->trigger_event('core.message_history_modify_sql_ary', compact($vars))); $sql = $db->sql_build_query('SELECT', $sql_ary); + unset($sql_ary); + $result = $db->sql_query($sql); $row = $db->sql_fetchrow($result); From 8ac4f955ca10484bdda152e5449feecb126df235 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dark=E2=9D=B6?= Date: Sun, 28 Jul 2019 18:36:37 +0530 Subject: [PATCH 3/3] [ticket/16111] Add core.message_history_modify_sql_ary PHPBB3-16111 --- phpBB/includes/functions_privmsgs.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpBB/includes/functions_privmsgs.php b/phpBB/includes/functions_privmsgs.php index 0806120f21..f07512d623 100644 --- a/phpBB/includes/functions_privmsgs.php +++ b/phpBB/includes/functions_privmsgs.php @@ -2004,7 +2004,7 @@ function message_history($msg_id, $user_id, $message_row, $folder, $in_post_mode } $sql_ary = array( - 'SELECT' => 'SELECT t.*, p.*, u.*', + 'SELECT' => 't.*, p.*, u.*', 'FROM' => array( PRIVMSGS_TABLE => 'p', PRIVMSGS_TO_TABLE => 't',