1
0
mirror of https://github.com/phpbb/phpbb.git synced 2025-05-06 15:45:34 +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

View File

@ -17,9 +17,10 @@ class acp_prune
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');
include_once($phpbb_root_path . 'includes/functions_user.' . $phpEx);
switch ($mode)
{
@ -258,63 +259,48 @@ class acp_prune
$where_sql = '';
$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))
{
$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)";
$user_ids[] = $row['user_id'];
$usernames[$row['user_id']] = $row['username'];
}
}
$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)
{
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';
}
else
{
for ($i = 0, $size = sizeof($user_ids); $i < $size; $i++)
foreach ($user_ids as $user_id)
{
$sql = 'UPDATE ' . POSTS_TABLE . '
SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($usernames[$i]) . "'
WHERE user_id = " . $user_ids[$i];
$db->sql_query($sql);
user_delete('retain', $user_id, $usernames[$user_id]);
}
$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));
}

View File

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