From 8e2f12fdf0120480d129aa32b284f575f55c934d Mon Sep 17 00:00:00 2001 From: plegall Date: Tue, 19 Oct 2021 16:28:52 +0200 Subject: [PATCH] fixes #1529 rewrite list of filter users for activities * migration task to update activity.performed_by (with object_id) for logout action (was always user guest instead of the real user) * activities: use the actual regrouped lines to list filter users (instead of performing a separate SQL query) --- .../themes/default/template/user_activity.tpl | 11 +---- include/functions.inc.php | 9 +++- include/ws_functions/pwg.php | 48 ++++++++----------- install/db/162-database.php | 25 ++++++++++ 4 files changed, 54 insertions(+), 39 deletions(-) create mode 100644 install/db/162-database.php diff --git a/admin/themes/default/template/user_activity.tpl b/admin/themes/default/template/user_activity.tpl index abde225e5..aa50b58d9 100644 --- a/admin/themes/default/template/user_activity.tpl +++ b/admin/themes/default/template/user_activity.tpl @@ -547,15 +547,8 @@ function lineConstructor(line) { newLine.find(".date-hour").html(line.hour); /* User _Section */ - - if (line.user_id != 2) { - newLine.find(".user-name").html(line.username); - newLine.find(".user-pic").html(get_initials(line.username)); - } else { - newLine.find(".user-name").html(line.details.users_string); - newLine.find(".user-pic").html(get_initials(line.details.users_string)); - } - + newLine.find(".user-name").html(line.username); + newLine.find(".user-pic").html(get_initials(line.username)); /* Detail_section */ newLine.find(".detail-item-1").html(line.ip_address); diff --git a/include/functions.inc.php b/include/functions.inc.php index 6c324b145..907012af6 100644 --- a/include/functions.inc.php +++ b/include/functions.inc.php @@ -582,11 +582,18 @@ function pwg_activity($object, $object_id, $action, $details=array()) foreach ($object_ids as $loop_object_id) { + $performed_by = $user['id']; + + if ('logout' == $action) + { + $performed_by = $loop_object_id; + } + $inserts[] = array( 'object' => $object, 'object_id' => $loop_object_id, 'action' => $action, - 'performed_by' => $user['id'], + 'performed_by' => $performed_by, 'session_idx' => session_id(), 'ip_address' => $ip_address, 'details' => $details_insert, diff --git a/include/ws_functions/pwg.php b/include/ws_functions/pwg.php index ca893c7a9..55c7efdbf 100644 --- a/include/ws_functions/pwg.php +++ b/include/ws_functions/pwg.php @@ -442,10 +442,8 @@ SELECT session_idx, ip_address, occured_on, - details, - '.$conf['user_fields']['username'].' AS username + details FROM '.ACTIVITY_TABLE.' - JOIN '.USERS_TABLE.' AS u ON performed_by = u.'.$conf['user_fields']['id'].' ORDER BY activity_id DESC ;'; @@ -466,11 +464,6 @@ SELECT $detailsType = 'script'; } - if ('user' == $row['object']) - { - $user_ids[ $row['object_id'] ] = 1; - } - $line_key = $row['session_idx'].'~'.$row['object'].'~'.$row['action'].'~'; // idx~photo~add if ($line_key === $current_key) @@ -491,13 +484,13 @@ SELECT 'ip_address' => $row['ip_address'], 'date' => format_date($date), 'hour' => $hour, - 'username' => $row['username'], 'user_id' => $row['performed_by'], 'detailsType' => $detailsType, 'details' => $details, 'counter' => 1, ); - + + @$user_ids[ $row['performed_by'] ]++; $current_key = $line_key; $line_id++; } @@ -515,17 +508,6 @@ SELECT WHERE `'.$conf['user_fields']['id'].'` IN ('.implode(',', array_keys($user_ids)).') ;'; $username_of = query2array($query, 'user_id', 'username'); - - $query = ' -SELECT - performed_by, - count(*) as nb_lines - FROM '.ACTIVITY_TABLE.' - GROUP BY - performed_by - ;'; - - $user_id_list = query2array($query, 'performed_by', 'nb_lines'); } foreach ($output_lines as $idx => $output_line) @@ -542,18 +524,26 @@ SELECT $output_lines[$idx]['details']['users_string'] = implode(', ', $output_lines[$idx]['details']['users']); } } - } - $filterable_users = array(); - foreach ($user_id_list as $key => $value) { - if (isset($username_of[$key])) { - $filterable_users[$username_of[$key]] = $value; - } else { - $filterable_users['user#'.$key] = $value; + $output_lines[$idx]['username'] = 'user#'.$output_lines[$idx]['user_id']; + if (isset($username_of[ $output_lines[$idx]['user_id'] ])) + { + $output_lines[$idx]['username'] = $username_of[ $output_lines[$idx]['user_id'] ]; } } - unset($filterable_users['guest']); + $filterable_users = array(); + foreach ($user_ids as $key => $value) + { + if (isset($username_of[$key])) + { + $filterable_users[$username_of[$key]] = $value; + } + else + { + $filterable_users['user#'.$key] = $value; + } + } // return $output_lines; return array( diff --git a/install/db/162-database.php b/install/db/162-database.php new file mode 100644 index 000000000..efdd084b0 --- /dev/null +++ b/install/db/162-database.php @@ -0,0 +1,25 @@ +