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)
This commit is contained in:
plegall 2021-10-19 16:28:52 +02:00
parent f0110cead6
commit 8e2f12fdf0
4 changed files with 54 additions and 39 deletions

View file

@ -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));
}
/* Detail_section */
newLine.find(".detail-item-1").html(line.ip_address);

View file

@ -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,

View file

@ -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,19 +524,27 @@ SELECT
$output_lines[$idx]['details']['users_string'] = implode(', ', $output_lines[$idx]['details']['users']);
}
}
$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'] ];
}
}
$filterable_users = array();
foreach ($user_id_list as $key => $value) {
if (isset($username_of[$key])) {
foreach ($user_ids as $key => $value)
{
if (isset($username_of[$key]))
{
$filterable_users[$username_of[$key]] = $value;
} else {
}
else
{
$filterable_users['user#'.$key] = $value;
}
}
unset($filterable_users['guest']);
// return $output_lines;
return array(
'result_lines' => $output_lines,

View file

@ -0,0 +1,25 @@
<?php
// +-----------------------------------------------------------------------+
// | This file is part of Piwigo. |
// | |
// | For copyright and license information, please view the COPYING.txt |
// | file that was distributed with this source code. |
// +-----------------------------------------------------------------------+
if (!defined('PHPWG_ROOT_PATH'))
{
die('Hacking attempt!');
}
$upgrade_description = 'change activity.performed_by for logout';
$query = '
UPDATE '.PREFIX_TABLE.'activity
SET performed_by = object_id
WHERE action = \'logout\'
;';
pwg_query($query);
echo "\n".$upgrade_description."\n";
?>