From af110f4820bbb0ac04ffe2262948c6b99b55bf49 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Mon, 18 Feb 2019 18:13:22 +0100 Subject: [PATCH] minor fix notification direct assignment Former-commit-id: 59ffb2338377ac2c3270681e6905f5d853add16b --- .../include/functions_messages.php | 58 +++++++++++-------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/pandora_console/include/functions_messages.php b/pandora_console/include/functions_messages.php index 9266733a68..3fb907ab06 100644 --- a/pandora_console/include/functions_messages.php +++ b/pandora_console/include/functions_messages.php @@ -356,49 +356,59 @@ function messages_get_count( if (!empty($incl_read)) { // Do not filter. - $read = ''; + $read = ' 1=1 '; } else { // Retrieve only unread messages. - $read = 'where t.read is null'; + $read = ' t.read is null'; } if ($ignore_source === true) { + $source_select = ''; $source_sql = ''; + $source_extra = ''; } else { + $source_select = ',IF(ns.user_editable,nsu.enabled,ns.enabled) as enabled'; + + // Row in tnotification_source_user could exist or not. $source_sql = sprintf( - 'INNER JOIN tnotification_source ns - ON tm.id_source = ns.id - AND ns.enabled = 1 - INNER JOIN tnotification_source_user nsu - ON nsu.id_source=ns.id - AND nsu.enabled = 1 - AND nsu.id_user = "%s"', + 'INNER JOIN ( + tnotification_source ns + LEFT JOIN tnotification_source_user nsu + ON ns.id=nsu.id_source + AND nsu.id_user="test") + ON tm.id_source=ns.id', $user ); + $source_extra = 'AND (t.enabled=1 OR t.enabled is null)'; } $sql = sprintf( - 'SELECT count(*) FROM ( - SELECT DISTINCT tm.*, utimestamp_read > 0 as "read" - FROM tmensajes tm - %s - LEFT JOIN tnotification_user nu - ON tm.id_mensaje=nu.id_mensaje - AND nu.id_user="%s" - LEFT JOIN (tnotification_group ng - INNER JOIN tusuario_perfil up - ON ng.id_group=up.id_grupo - AND up.id_grupo=ng.id_group - ) ON tm.id_mensaje=ng.id_mensaje + 'SELECT count(*) as "n" FROM ( + SELECT + tm.*, + utimestamp_read > 0 as "read" + %s + FROM tmensajes tm + %s + LEFT JOIN tnotification_user nu + ON tm.id_mensaje=nu.id_mensaje + AND nu.id_user="%s" + LEFT JOIN (tnotification_group ng + INNER JOIN tusuario_perfil up + ON ng.id_group=up.id_grupo + AND up.id_grupo=ng.id_group) + ON tm.id_mensaje=ng.id_mensaje WHERE utimestamp_erased is null AND (nu.id_user="%s" OR up.id_usuario="%s" OR ng.id_group=0) - ) t - %s', + ) t + WHERE %s %s', + $source_select, $source_sql, $user, $user, $user, - $read + $read, + $source_extra ); return (int) db_get_sql($sql);