/** * @dataProvider delete_user_pms_data */ public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) { global $db; $db = $this->new_dbal(); phpbb_delete_user_pms($delete_user); $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs, $db->sql_fetchrowset($result)); $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs_to, $db->sql_fetchrowset($result)); }
/** * @dataProvider delete_user_pms_data */ public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) { global $db, $phpbb_container; $db = $this->new_dbal(); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); phpbb_delete_user_pms($delete_user); $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs, $db->sql_fetchrowset($result)); $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs_to, $db->sql_fetchrowset($result)); }
/** * @dataProvider delete_user_pms_data */ public function test_delete_user_pms($delete_user, $remaining_privmsgs, $remaining_privmsgs_to) { global $db, $phpbb_container, $phpbb_root_path; $db = $this->new_dbal(); $phpbb_container = new phpbb_mock_container_builder(); $phpbb_container->set('notification_manager', new phpbb_mock_notification_manager()); // Works as a workaround for tests $phpbb_container->set('attachment.manager', new \phpbb\attachment\delete(new \phpbb\config\config(array()), $db, new \phpbb_mock_event_dispatcher(), new \phpbb\filesystem\filesystem(), new \phpbb\attachment\resync($db), $phpbb_root_path)); phpbb_delete_user_pms($delete_user); $sql = 'SELECT msg_id FROM ' . PRIVMSGS_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs, $db->sql_fetchrowset($result)); $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE; $result = $db->sql_query($sql); $this->assertEquals($remaining_privmsgs_to, $db->sql_fetchrowset($result)); }
/** * Remove User */ function user_delete($mode, $user_id, $post_username = false) { global $cache, $config, $db, $user, $auth; global $phpbb_root_path, $phpEx; $sql = 'SELECT * FROM ' . USERS_TABLE . ' WHERE user_id = ' . $user_id; $result = $db->sql_query($sql); $user_row = $db->sql_fetchrow($result); $db->sql_freeresult($result); if (!$user_row) { return false; } // Before we begin, we will remove the reports the user issued. $sql = 'SELECT r.post_id, p.topic_id FROM ' . REPORTS_TABLE . ' r, ' . POSTS_TABLE . ' p WHERE r.user_id = ' . $user_id . ' AND p.post_id = r.post_id'; $result = $db->sql_query($sql); $report_posts = $report_topics = array(); while ($row = $db->sql_fetchrow($result)) { $report_posts[] = $row['post_id']; $report_topics[] = $row['topic_id']; } $db->sql_freeresult($result); if (sizeof($report_posts)) { $report_posts = array_unique($report_posts); $report_topics = array_unique($report_topics); // Get a list of topics that still contain reported posts $sql = 'SELECT DISTINCT topic_id FROM ' . POSTS_TABLE . ' WHERE ' . $db->sql_in_set('topic_id', $report_topics) . ' AND post_reported = 1 AND ' . $db->sql_in_set('post_id', $report_posts, true); $result = $db->sql_query($sql); $keep_report_topics = array(); while ($row = $db->sql_fetchrow($result)) { $keep_report_topics[] = $row['topic_id']; } $db->sql_freeresult($result); if (sizeof($keep_report_topics)) { $report_topics = array_diff($report_topics, $keep_report_topics); } unset($keep_report_topics); // Now set the flags back $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_reported = 0 WHERE ' . $db->sql_in_set('post_id', $report_posts); $db->sql_query($sql); if (sizeof($report_topics)) { $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_reported = 0 WHERE ' . $db->sql_in_set('topic_id', $report_topics); $db->sql_query($sql); } } // Remove reports $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE user_id = ' . $user_id); if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD) { avatar_delete('user', $user_row); } switch ($mode) { case 'retain': $db->sql_transaction('begin'); if ($post_username === false) { $post_username = $user->lang['GUEST']; } // If the user is inactive and newly registered we assume no posts from this user being there... if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) { } else { $sql = 'UPDATE ' . FORUMS_TABLE . ' SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = ''\n\t\t\t\t\tWHERE forum_last_poster_id = {$user_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . POSTS_TABLE . ' SET poster_id = ' . ANONYMOUS . ", post_username = '******'\n\t\t\t\t\tWHERE poster_id = {$user_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . POSTS_TABLE . ' SET post_edit_user = '******'UPDATE ' . TOPICS_TABLE . ' SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = ''\n\t\t\t\t\tWHERE topic_poster = {$user_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . TOPICS_TABLE . ' SET topic_last_poster_id = ' . ANONYMOUS . ", topic_last_poster_name = '" . $db->sql_escape($post_username) . "', topic_last_poster_colour = ''\n\t\t\t\t\tWHERE topic_last_poster_id = {$user_id}"; $db->sql_query($sql); $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' SET poster_id = ' . ANONYMOUS . "\n\t\t\t\t\tWHERE poster_id = {$user_id}"; $db->sql_query($sql); // Since we change every post by this author, we need to count this amount towards the anonymous user // Update the post count for the anonymous user if ($user_row['user_posts']) { $sql = 'UPDATE ' . USERS_TABLE . ' SET user_posts = user_posts + ' . $user_row['user_posts'] . ' WHERE user_id = ' . ANONYMOUS; $db->sql_query($sql); } } $db->sql_transaction('commit'); break; case 'remove': if (!function_exists('delete_posts')) { include $phpbb_root_path . 'includes/functions_admin.' . $phpEx; } // Delete posts, attachments, etc. delete_posts('poster_id', $user_id); break; } $db->sql_transaction('begin'); $table_ary = array(USERS_TABLE, USER_GROUP_TABLE, TOPICS_WATCH_TABLE, FORUMS_WATCH_TABLE, ACL_USERS_TABLE, TOPICS_TRACK_TABLE, TOPICS_POSTED_TABLE, FORUMS_TRACK_TABLE, PROFILE_FIELDS_DATA_TABLE, MODERATOR_CACHE_TABLE, DRAFTS_TABLE, BOOKMARKS_TABLE, SESSIONS_KEYS_TABLE, PRIVMSGS_FOLDER_TABLE, PRIVMSGS_RULES_TABLE); foreach ($table_ary as $table) { $sql = "DELETE FROM {$table}\n\t\t\tWHERE user_id = {$user_id}"; $db->sql_query($sql); } $cache->destroy('sql', MODERATOR_CACHE_TABLE); // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE reportee_id = ' . $user_id; $db->sql_query($sql); // Change user_id to anonymous for this users triggered events $sql = 'UPDATE ' . LOG_TABLE . ' SET user_id = ' . ANONYMOUS . ' WHERE user_id = ' . $user_id; $db->sql_query($sql); // Delete the user_id from the zebra table $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' WHERE user_id = ' . $user_id . ' OR zebra_id = ' . $user_id; $db->sql_query($sql); // Delete the user_id from the banlist $sql = 'DELETE FROM ' . BANLIST_TABLE . ' WHERE ban_userid = ' . $user_id; $db->sql_query($sql); // Delete the user_id from the session table $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' WHERE session_user_id = ' . $user_id; $db->sql_query($sql); // Clean the private messages tables from the user if (!function_exists('phpbb_delete_user_pms')) { include $phpbb_root_path . 'includes/functions_privmsgs.' . $phpEx; } phpbb_delete_user_pms($user_id); $db->sql_transaction('commit'); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) { update_last_username(); } // Decrement number of users if this user is active if ($user_row['user_type'] != USER_INACTIVE && $user_row['user_type'] != USER_IGNORE) { set_config_count('num_users', -1, true); } return false; }