1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-29 10:39:19 +02:00

fix pruning of users

git-svn-id: file:///svn/phpbb/trunk@5696 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
Meik Sievertsen 2006-03-22 11:13:33 +00:00
parent 6e166aa889
commit 267e4d4616
2 changed files with 41 additions and 52 deletions

@ -17,9 +17,10 @@ class acp_prune
function main($id, $mode) function main($id, $mode)
{ {
global $user, $phpEx, $SID, $phpbb_admin_path; global $user, $phpEx, $SID, $phpbb_admin_path, $phpbb_root_path;
$user->add_lang('acp/prune'); $user->add_lang('acp/prune');
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
switch ($mode) switch ($mode)
{ {
@ -258,63 +259,48 @@ class acp_prune
$where_sql = ''; $where_sql = '';
$user_ids = $usernames = array(); $user_ids = $usernames = array();
if ($row = $db->sql_fetchrow($result)) while ($row = $db->sql_fetchrow($result))
{ {
do if (!in_array($row['user_id'], $bot_ids))
{ {
if (!in_array($row['user_id'], $bot_ids)) $user_ids[] = $row['user_id'];
{ $usernames[$row['user_id']] = $row['username'];
$where_sql .= (($where_sql != '') ? ', ' : '') . $row['user_id'];
$user_ids[] = $row['user_id'];
$usernames[] = $row['username'];
}
}
while ($row = $db->sql_fetchrow($result));
if ($where_sql)
{
$where_sql = " AND user_id IN ($where_sql)";
} }
} }
$db->sql_freeresult($result); $db->sql_freeresult($result);
if ($where_sql) if (sizeof($user_ids))
{ {
$sql = ''; if ($action == 'deactivate')
{
foreach ($user_ids as $user_id)
{
user_active_flip($user_id, USER_NORMAL, false, false, true);
}
if ($action == 'delete') $l_log = 'LOG_PRUNE_USER_DEAC';
}
else if ($action == 'delete')
{ {
if ($deleteposts) if ($deleteposts)
{ {
delete_posts('poster_id', $user_ids, true); foreach ($user_ids as $user_id)
{
user_delete('remove', $user_id);
}
$l_log = 'LOG_PRUNE_USER_DEL_DEL'; $l_log = 'LOG_PRUNE_USER_DEL_DEL';
} }
else else
{ {
for ($i = 0, $size = sizeof($user_ids); $i < $size; $i++) foreach ($user_ids as $user_id)
{ {
$sql = 'UPDATE ' . POSTS_TABLE . ' user_delete('retain', $user_id, $usernames[$user_id]);
SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($usernames[$i]) . "'
WHERE user_id = " . $user_ids[$i];
$db->sql_query($sql);
} }
$l_log = 'LOG_PRUNE_USER_DEL_ANON'; $l_log = 'LOG_PRUNE_USER_DEL_ANON';
} }
$sql = 'DELETE FROM ' . USERS_TABLE;
} }
else if ($action == 'deactivate')
{
$sql = 'UPDATE ' . USERS_TABLE . "
SET user_active = 0";
$l_log = 'LOG_PRUNE_USER_DEAC';
}
$sql .= ' WHERE user_id <> ' . ANONYMOUS . "
$where_sql";
$db->sql_query($sql);
add_log('admin', $l_log, implode(', ', $usernames)); add_log('admin', $l_log, implode(', ', $usernames));
} }

@ -95,7 +95,7 @@ function user_update_name($old_name, $new_name)
/** /**
* Remove User * Remove User
*/ */
function user_delete($mode, $user_id) function user_delete($mode, $user_id, $post_username = false)
{ {
global $config, $db, $user, $auth; global $config, $db, $user, $auth;
@ -105,12 +105,12 @@ function user_delete($mode, $user_id)
{ {
case 'retain': case 'retain':
$sql = 'UPDATE ' . FORUMS_TABLE . ' $sql = 'UPDATE ' . FORUMS_TABLE . '
SET forum_last_poster_id = ' . ANONYMOUS . " SET forum_last_poster_id = ' . ANONYMOUS . (($post_username !== false) ? ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "'" : '') . "
WHERE forum_last_poster_id = $user_id"; WHERE forum_last_poster_id = $user_id";
$db->sql_query($sql); $db->sql_query($sql);
$sql = 'UPDATE ' . POSTS_TABLE . ' $sql = 'UPDATE ' . POSTS_TABLE . '
SET poster_id = ' . ANONYMOUS . " SET poster_id = ' . ANONYMOUS . (($post_username !== false) ? ", post_username = '" . $db->sql_escape($post_username) . "'" : '') . "
WHERE poster_id = $user_id"; WHERE poster_id = $user_id";
$db->sql_query($sql); $db->sql_query($sql);
@ -120,7 +120,7 @@ function user_delete($mode, $user_id)
$db->sql_query($sql); $db->sql_query($sql);
$sql = 'UPDATE ' . TOPICS_TABLE . ' $sql = 'UPDATE ' . TOPICS_TABLE . '
SET topic_last_poster_id = ' . ANONYMOUS . " SET topic_last_poster_id = ' . ANONYMOUS . (($post_username !== false) ? ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "'" : '') . "
WHERE topic_last_poster_id = $user_id"; WHERE topic_last_poster_id = $user_id";
$db->sql_query($sql); $db->sql_query($sql);
break; break;
@ -213,7 +213,7 @@ function user_delete($mode, $user_id)
* Flips user_type from active to inactive and vice versa, handles * Flips user_type from active to inactive and vice versa, handles
* group membership updates * group membership updates
*/ */
function user_active_flip($user_id, $user_type, $user_actkey = false, $username = false) function user_active_flip($user_id, $user_type, $user_actkey = false, $username = false, $no_log = false)
{ {
global $db, $user, $auth; global $db, $user, $auth;
@ -274,18 +274,21 @@ function user_active_flip($user_id, $user_type, $user_actkey = false, $username
$auth->acl_clear_prefetch($user_id); $auth->acl_clear_prefetch($user_id);
if ($username === false) if (!$no_log)
{ {
$sql = 'SELECT username if ($username === false)
FROM ' . USERS_TABLE . " {
WHERE user_id = $user_id"; $sql = 'SELECT username
$result = $db->sql_query($sql); FROM ' . USERS_TABLE . "
$username = $db->sql_fetchfield('username', 0, $result); WHERE user_id = $user_id";
$db->sql_freeresult($result); $result = $db->sql_query($sql);
} $username = $db->sql_fetchfield('username', 0, $result);
$db->sql_freeresult($result);
}
$log = ($user_type == USER_NORMAL) ? 'LOG_USER_INACTIVE' : 'LOG_USER_ACTIVE'; $log = ($user_type == USER_NORMAL) ? 'LOG_USER_INACTIVE' : 'LOG_USER_ACTIVE';
add_log('admin', $log, $username); add_log('admin', $log, $username);
}
return false; return false;
} }