From e7e0ab9d0b33121e38a236879fcca417072140f6 Mon Sep 17 00:00:00 2001 From: Josh Woody Date: Mon, 17 May 2010 12:12:00 -0500 Subject: [feature/prune-users] Rework user_delete() functions_user.php user_delete now uses fewer queries to delete a set of users of size > 1 by accepting an array of users rather than a single user at a time. This required changing the third parameter, however the function retains its former behavior with the old-style parameters. PHPBB3-9622 --- phpBB/includes/functions_user.php | 265 +++++++++++++++++++++----------------- 1 file changed, 147 insertions(+), 118 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 317578cd54..0886e8aabf 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -330,20 +330,32 @@ function user_add($user_row, $cp_data = false) /** * Remove User +* @param $mode Either 'retain' or 'remove' */ -function user_delete($mode, $user_id, $post_username = false) +function user_delete($mode, $user_ids, $retain_username = true) { global $cache, $config, $db, $user, $auth; global $phpbb_root_path, $phpEx; + $db->sql_transaction('begin'); + + $user_rows = array(); + if (!is_array($user_ids)) + { + $user_ids = array($user_ids); + } + $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); $result = $db->sql_query($sql); - $user_row = $db->sql_fetchrow($result); + while ($row = $db->sql_fetchrow($result)) + { + $user_rows[$row['user_id']] = $row; + } $db->sql_freeresult($result); - if (!$user_row) + if (!$user_rows) { return false; } @@ -351,7 +363,8 @@ function user_delete($mode, $user_id, $post_username = 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 . ' + WHERE ' . $db->sql_in_set('r.user_id', $user_ids) . //r.user_id = ' . $user_id . ' + ' AND p.post_id = r.post_id'; $result = $db->sql_query($sql); @@ -405,135 +418,157 @@ function user_delete($mode, $user_id, $post_username = false) } // 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); - } + $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $user_ids)); - switch ($mode) + // Some things need to be done in the loop (if the query changes based + // on which user is currently being deleted) + $added_guest_posts = 0; + foreach ($user_rows as $user_id => $user_row) { - case 'retain': + if ($user_row['user_avatar'] && $user_row['user_avatar_type'] == AVATAR_UPLOAD) + { + avatar_delete('user', $user_row); + } - $db->sql_transaction('begin'); + // 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); + } - if ($post_username === false) - { - $post_username = $user->lang['GUEST']; - } + switch ($mode) + { + case 'retain': + if ($retain_username === false) + { + $post_username = $user->lang['GUEST']; + } + else + { + $post_username = $user_row['username']; + } - // 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 = '' - WHERE forum_last_poster_id = $user_id"; - $db->sql_query($sql); + // If the user is inactive and newly registered we assume no posts from the user, and save the queries + if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) + { + } + else + { + // When we delete these users and retain the posts, we must assign all the data to the guest user + $sql = 'UPDATE ' . FORUMS_TABLE . ' + SET forum_last_poster_id = ' . ANONYMOUS . ", forum_last_poster_name = '" . $db->sql_escape($post_username) . "', forum_last_poster_colour = '' + WHERE forum_last_poster_id = $user_id"; + $db->sql_query($sql); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "' - WHERE poster_id = $user_id"; - $db->sql_query($sql); + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET poster_id = ' . ANONYMOUS . ", post_username = '" . $db->sql_escape($post_username) . "' + WHERE poster_id = $user_id"; + $db->sql_query($sql); - $sql = 'UPDATE ' . POSTS_TABLE . ' - SET post_edit_user = ' . ANONYMOUS . " - WHERE post_edit_user = $user_id"; - $db->sql_query($sql); + $sql = 'UPDATE ' . TOPICS_TABLE . ' + SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' + WHERE topic_poster = $user_id"; + $db->sql_query($sql); - $sql = 'UPDATE ' . TOPICS_TABLE . ' - SET topic_poster = ' . ANONYMOUS . ", topic_first_poster_name = '" . $db->sql_escape($post_username) . "', topic_first_poster_colour = '' - WHERE 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 = '' + WHERE topic_last_poster_id = $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 = '' - WHERE topic_last_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 - $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' - SET poster_id = ' . ANONYMOUS . " - WHERE poster_id = $user_id"; - $db->sql_query($sql); + if ($user_row['user_posts']) + { + $added_guest_posts += $user_row['user_posts']; + } + } + break; - // Since we change every post by this author, we need to count this amount towards the anonymous user + case 'remove': + // there is nothing variant specific to deleting posts + break; + } + } - // 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); - } - } + // Now do the invariant tasks + // all queries performed in one call of this function are in a single transaction + // so this is kosher + if ($mode == 'retain') + { + // Assign more data to the Anonymous user + $sql = 'UPDATE ' . ATTACHMENTS_TABLE . ' + SET poster_id = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('poster_id', $user_ids); + $db->sql_query($sql); - $db->sql_transaction('commit'); + $sql = 'UPDATE ' . POSTS_TABLE . ' + SET post_edit_user = ' . ANONYMOUS . ' + WHERE ' . $db->sql_in_set('post_edit_user', $user_ids); + $db->sql_query($sql); - break; + $sql = 'UPDATE ' . USERS_TABLE . ' + SET user_posts = user_posts + ' . $added_guest_posts . ' + WHERE user_id = ' . ANONYMOUS; + $db->sql_query($sql); + } + else if ($mode == 'remove') + { + if (!function_exists('delete_posts')) + { + include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); + } - case 'remove': + // Find any topics whose only posts are being deleted, and remove them from the topics table + $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts + FROM ' . POSTS_TABLE . ' + WHERE ' . $db->sql_in_set('poster_id', $user_ids) . ' + GROUP BY topic_id'; + $result = $db->sql_query($sql); - if (!function_exists('delete_posts')) - { - include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); - } + $topic_id_ary = array(); + while ($row = $db->sql_fetchrow($result)) + { + $topic_id_ary[$row['topic_id']] = $row['total_posts']; + } + $db->sql_freeresult($result); - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts - FROM ' . POSTS_TABLE . " - WHERE poster_id = $user_id - GROUP BY topic_id"; + if (sizeof($topic_id_ary)) + { + $sql = 'SELECT topic_id, topic_replies, topic_replies_real + FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); $result = $db->sql_query($sql); - $topic_id_ary = array(); + $del_topic_ary = array(); while ($row = $db->sql_fetchrow($result)) { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; + if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) + { + $del_topic_ary[] = $row['topic_id']; + } } $db->sql_freeresult($result); - if (sizeof($topic_id_ary)) + if (sizeof($del_topic_ary)) { - $sql = 'SELECT topic_id, topic_replies, topic_replies_real - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); - $result = $db->sql_query($sql); - - $del_topic_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) - { - $del_topic_ary[] = $row['topic_id']; - } - } - $db->sql_freeresult($result); - - if (sizeof($del_topic_ary)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); - $db->sql_query($sql); - } + $sql = 'DELETE FROM ' . TOPICS_TABLE . ' + WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); + $db->sql_query($sql); } + } - // Delete posts, attachments, etc. - delete_posts('poster_id', $user_id); - - break; + // actually do the meat of the work if we are deleting all the users' posts + // delete_posts can handle any number of IDs in its second argument + delete_posts('poster_id', $user_ids); } - $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); + // Delete the miscellaneous (non-post) data for the user foreach ($table_ary as $table) { $sql = "DELETE FROM $table - WHERE user_id = $user_id"; + WHERE " . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); } @@ -541,35 +576,35 @@ function user_delete($mode, $user_id, $post_username = false) // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' - WHERE reportee_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); //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; + WHERE ' . $db->sql_in_set('user_id', $user_ids); //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; + WHERE ' . $db->sql_in_set('user_id', $user_ids) . //user_id = ' . $user_id . ' + ' OR ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); // Delete the user_id from the banlist $sql = 'DELETE FROM ' . BANLIST_TABLE . ' - WHERE ban_userid = ' . $user_id; + WHERE ' . $db->sql_in_set('ban_userid', $user_ids); $db->sql_query($sql); // Delete the user_id from the session table $sql = 'DELETE FROM ' . SESSIONS_TABLE . ' - WHERE session_user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('session_user_id', $user_ids); $db->sql_query($sql); // Remove any undelivered mails... $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE author_id = ' . $user_id . ' + WHERE ' . $db->sql_in_set('author_id', $user_ids) . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $result = $db->sql_query($sql); @@ -589,24 +624,24 @@ function user_delete($mode, $user_id, $post_username = false) } $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE author_id = ' . $user_id . ' + WHERE ' . $db->sql_in_set('author_id', $user_id) . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $db->sql_query($sql); // Delete all to-information $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE user_id = ' . $user_id; + WHERE ' . $db->sql_in_set('user_id', $user_ids); $db->sql_query($sql); // Set the remaining author id to anonymous - this way users are still able to read messages from users being removed $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE author_id = ' . $user_id; + WHERE ' . $db->sql_in_set('author_id', $user_ids); $db->sql_query($sql); $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE author_id = ' . $user_id; + WHERE ' . $db->sql_in_set('author_id', $user_id); $db->sql_query($sql); foreach ($undelivered_user as $_user_id => $ary) @@ -626,17 +661,11 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); // Reset newest user info if appropriate - if ($config['newest_user_id'] == $user_id) + if (in_array($config['newest_user_id'], $user_ids)) { 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; } -- cgit v1.2.1 From 04a6303527d9bf29114b51001d06af5235ea0847 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 03:01:38 -0400 Subject: [feature/prune-users] Apply e6ed55a9c1ceb07ab2e87d4a53f9e688fda319c5. This was done in PHPBB3-9872. PHPBB3-9622 --- phpBB/includes/functions_user.php | 41 +-------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 0886e8aabf..9b16a56b1c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -518,46 +518,7 @@ function user_delete($mode, $user_ids, $retain_username = true) include($phpbb_root_path . 'includes/functions_admin.' . $phpEx); } - // Find any topics whose only posts are being deleted, and remove them from the topics table - $sql = 'SELECT topic_id, COUNT(post_id) AS total_posts - FROM ' . POSTS_TABLE . ' - WHERE ' . $db->sql_in_set('poster_id', $user_ids) . ' - GROUP BY topic_id'; - $result = $db->sql_query($sql); - - $topic_id_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - $topic_id_ary[$row['topic_id']] = $row['total_posts']; - } - $db->sql_freeresult($result); - - if (sizeof($topic_id_ary)) - { - $sql = 'SELECT topic_id, topic_replies, topic_replies_real - FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', array_keys($topic_id_ary)); - $result = $db->sql_query($sql); - - $del_topic_ary = array(); - while ($row = $db->sql_fetchrow($result)) - { - if (max($row['topic_replies'], $row['topic_replies_real']) + 1 == $topic_id_ary[$row['topic_id']]) - { - $del_topic_ary[] = $row['topic_id']; - } - } - $db->sql_freeresult($result); - - if (sizeof($del_topic_ary)) - { - $sql = 'DELETE FROM ' . TOPICS_TABLE . ' - WHERE ' . $db->sql_in_set('topic_id', $del_topic_ary); - $db->sql_query($sql); - } - } - - // actually do the meat of the work if we are deleting all the users' posts + // Delete posts, attachments, etc. // delete_posts can handle any number of IDs in its second argument delete_posts('poster_id', $user_ids); } -- cgit v1.2.1 From 44f524aa5049459c0b272ed98daaf84444030010 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 12:56:42 -0400 Subject: [feature/prune-users] Call sql_is_set for user ids once in user_delete. PHPBB3-9622 --- phpBB/includes/functions_user.php | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index de01c3e5cb..d67ada026a 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -345,9 +345,11 @@ function user_delete($mode, $user_ids, $retain_username = true) $user_ids = array($user_ids); } + $user_id_sql = $db->sql_in_set('user_id', $user_ids); + $sql = 'SELECT * FROM ' . USERS_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_ids); + WHERE ' . $user_id_sql; $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { @@ -418,7 +420,7 @@ function user_delete($mode, $user_ids, $retain_username = true) } // Remove reports - $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE ' . $db->sql_in_set('user_id', $user_ids)); + $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE ' . $user_id_sql); // Some things need to be done in the loop (if the query changes based // on which user is currently being deleted) @@ -529,7 +531,7 @@ function user_delete($mode, $user_ids, $retain_username = true) foreach ($table_ary as $table) { $sql = "DELETE FROM $table - WHERE " . $db->sql_in_set('user_id', $user_ids); + WHERE " . $user_id_sql; $db->sql_query($sql); } @@ -537,18 +539,18 @@ function user_delete($mode, $user_ids, $retain_username = true) // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_ids); //reportee_id = ' . $user_id; + WHERE ' . $user_id_sql; //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 ' . $db->sql_in_set('user_id', $user_ids); //user_id = ' . $user_id; + WHERE ' . $user_id_sql; //user_id = ' . $user_id; $db->sql_query($sql); // Delete the user_id from the zebra table $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_ids) . //user_id = ' . $user_id . ' + WHERE ' . $user_id_sql . //user_id = ' . $user_id . ' ' OR ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); @@ -591,7 +593,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // Delete all to-information $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE ' . $db->sql_in_set('user_id', $user_ids); + WHERE ' . $user_id_sql; $db->sql_query($sql); // Set the remaining author id to anonymous - this way users are still able to read messages from users being removed -- cgit v1.2.1 From 0f17d5d493738b832f4d9d010e94d4d7fa113c89 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 13:13:59 -0400 Subject: [feature/prune-users] Replaced missed occurrences of $user_id with $user_ids. PHPBB3-9622 --- phpBB/includes/functions_user.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d67ada026a..b21be08307 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -587,7 +587,7 @@ function user_delete($mode, $user_ids, $retain_username = true) } $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE ' . $db->sql_in_set('author_id', $user_id) . ' + WHERE ' . $db->sql_in_set('author_id', $user_ids) . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $db->sql_query($sql); @@ -604,7 +604,7 @@ function user_delete($mode, $user_ids, $retain_username = true) $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE ' . $db->sql_in_set('author_id', $user_id); + WHERE ' . $db->sql_in_set('author_id', $user_ids); $db->sql_query($sql); foreach ($undelivered_user as $_user_id => $ary) -- cgit v1.2.1 From f65556e6defb2750fcf680bd29e56f2416176fe1 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 13:16:15 -0400 Subject: [feature/prune-users] Call sql_is_set once for author ids in user_delete. PHPBB3-9622 --- phpBB/includes/functions_user.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index b21be08307..3926de2b12 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -537,6 +537,8 @@ function user_delete($mode, $user_ids, $retain_username = true) $cache->destroy('sql', MODERATOR_CACHE_TABLE); + $author_id_sql = $db->sql_in_set('author_id', $user_ids); + // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE ' . $user_id_sql; //reportee_id = ' . $user_id; @@ -567,7 +569,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // Remove any undelivered mails... $sql = 'SELECT msg_id, user_id FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE ' . $db->sql_in_set('author_id', $user_ids) . ' + WHERE ' . $author_id_sql . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $result = $db->sql_query($sql); @@ -587,7 +589,7 @@ function user_delete($mode, $user_ids, $retain_username = true) } $sql = 'DELETE FROM ' . PRIVMSGS_TO_TABLE . ' - WHERE ' . $db->sql_in_set('author_id', $user_ids) . ' + WHERE ' . $author_id_sql . ' AND folder_id = ' . PRIVMSGS_NO_BOX; $db->sql_query($sql); @@ -599,12 +601,12 @@ function user_delete($mode, $user_ids, $retain_username = true) // Set the remaining author id to anonymous - this way users are still able to read messages from users being removed $sql = 'UPDATE ' . PRIVMSGS_TO_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE ' . $db->sql_in_set('author_id', $user_ids); + WHERE ' . $author_id_sql; $db->sql_query($sql); $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' SET author_id = ' . ANONYMOUS . ' - WHERE ' . $db->sql_in_set('author_id', $user_ids); + WHERE ' . $author_id_sql; $db->sql_query($sql); foreach ($undelivered_user as $_user_id => $ary) -- cgit v1.2.1 From e23868f3e2e95ea5b6bc5d4a14fc48f8bce99615 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 13:17:45 -0400 Subject: [feature/prune-users] Fixed user id check in undelivered users loop. There is now $user_ids instead of one $user_id. PHPBB3-9622 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3926de2b12..2ac8ff0eec 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -611,7 +611,7 @@ function user_delete($mode, $user_ids, $retain_username = true) foreach ($undelivered_user as $_user_id => $ary) { - if ($_user_id == $user_id) + if (in_array($_user_id, $user_ids)) { continue; } -- cgit v1.2.1 From 9f32cae5f9b4e3524dd82be266ed638152920ebb Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 8 May 2011 13:28:09 -0400 Subject: [feature/prune_users] Moved set_config_count out of user loop. PHPBB3-9622 --- phpBB/includes/functions_user.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 2ac8ff0eec..e9655ba736 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -422,6 +422,8 @@ function user_delete($mode, $user_ids, $retain_username = true) // Remove reports $db->sql_query('DELETE FROM ' . REPORTS_TABLE . ' WHERE ' . $user_id_sql); + $num_users_delta = 0; + // Some things need to be done in the loop (if the query changes based // on which user is currently being deleted) $added_guest_posts = 0; @@ -435,7 +437,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // 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); + --$num_users_delta; } switch ($mode) @@ -492,6 +494,11 @@ function user_delete($mode, $user_ids, $retain_username = true) } } + if ($num_users_delta != 0) + { + set_config_count('num_users', $num_users_delta, true); + } + // Now do the invariant tasks // all queries performed in one call of this function are in a single transaction // so this is kosher -- cgit v1.2.1 From 15d2f294c664e11fb1f2bc84238067cf71a544e6 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 20:56:00 -0400 Subject: [feature/prune-users] Cosmetic changes per bantu's review. PHPBB3-9622 --- phpBB/includes/functions_user.php | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index e9655ba736..c78949342b 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -365,8 +365,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // 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 ' . $db->sql_in_set('r.user_id', $user_ids) . //r.user_id = ' . $user_id . ' - ' + WHERE ' . $db->sql_in_set('r.user_id', $user_ids) . ' AND p.post_id = r.post_id'; $result = $db->sql_query($sql); @@ -554,13 +553,13 @@ function user_delete($mode, $user_ids, $retain_username = true) // Change user_id to anonymous for this users triggered events $sql = 'UPDATE ' . LOG_TABLE . ' SET user_id = ' . ANONYMOUS . ' - WHERE ' . $user_id_sql; //user_id = ' . $user_id; + WHERE ' . $user_id_sql; $db->sql_query($sql); // Delete the user_id from the zebra table $sql = 'DELETE FROM ' . ZEBRA_TABLE . ' - WHERE ' . $user_id_sql . //user_id = ' . $user_id . ' - ' OR ' . $db->sql_in_set('zebra_id', $user_ids); + WHERE ' . $user_id_sql . ' + OR ' . $db->sql_in_set('zebra_id', $user_ids); $db->sql_query($sql); // Delete the user_id from the banlist -- cgit v1.2.1 From 953e829b527acd6de80fee93bb1bfd08c6010c51 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 20:57:35 -0400 Subject: [feature/prune-users] Non-cosmetic changes per bantu's review. PHPBB3-9622 --- phpBB/includes/functions_user.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c78949342b..09a6394323 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -353,7 +353,7 @@ function user_delete($mode, $user_ids, $retain_username = true) $result = $db->sql_query($sql); while ($row = $db->sql_fetchrow($result)) { - $user_rows[$row['user_id']] = $row; + $user_rows[(int) $row['user_id']] = $row; } $db->sql_freeresult($result); @@ -451,11 +451,10 @@ function user_delete($mode, $user_ids, $retain_username = true) $post_username = $user_row['username']; } - // If the user is inactive and newly registered we assume no posts from the user, and save the queries - if ($user_row['user_type'] == USER_INACTIVE && $user_row['user_inactive_reason'] == INACTIVE_REGISTER && !$user_row['user_posts']) - { - } - else + // If the user is inactive and newly registered + // we assume no posts from the user, and save + // the queries + if ($user_row['user_type'] != USER_INACTIVE || $user_row['user_inactive_reason'] != INACTIVE_REGISTER || $user_row['user_posts']) { // When we delete these users and retain the posts, we must assign all the data to the guest user $sql = 'UPDATE ' . FORUMS_TABLE . ' -- cgit v1.2.1 From 138d2e2a4cbfbac0b6bc04d81b618fac62a69fb9 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 20:59:37 -0400 Subject: [feature/prune-users] Fix incorrect condition when deleting log entries. The original commit incorrectly replaced reportee_id with user_id. Change it back to reportee_id. The comment was correct. PHPBB3-9622 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 09a6394323..ff6b60633a 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -546,7 +546,7 @@ function user_delete($mode, $user_ids, $retain_username = true) // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' - WHERE ' . $user_id_sql; //reportee_id = ' . $user_id; + WHERE ' . $db->sql_in_set('reportee_id', $user_ids); $db->sql_query($sql); // Change user_id to anonymous for this users triggered events -- cgit v1.2.1 From 7c752aa3defa92128bb1e38ff3305a978d37e4d3 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Sun, 25 Mar 2012 21:08:06 -0400 Subject: [feature/prune-users] Use a map instead of performing array scans. PHPBB3-9622 --- phpBB/includes/functions_user.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index ff6b60633a..940018ebad 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -614,9 +614,11 @@ function user_delete($mode, $user_ids, $retain_username = true) WHERE ' . $author_id_sql; $db->sql_query($sql); + $user_ids_map = array_flip($user_ids); + foreach ($undelivered_user as $_user_id => $ary) { - if (in_array($_user_id, $user_ids)) + if (isset($user_ids_map[$_user_id])) { continue; } @@ -631,7 +633,7 @@ function user_delete($mode, $user_ids, $retain_username = true) $db->sql_transaction('commit'); // Reset newest user info if appropriate - if (in_array($config['newest_user_id'], $user_ids)) + if (isset($user_ids_map[$config['newest_user_id']])) { update_last_username(); } -- cgit v1.2.1 From b76454dd835d24e14ebd2cfeba1508f9cf1fc12e Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Thu, 19 Apr 2012 20:27:21 -0400 Subject: [feature/prune-users] Use empty for checking array size. PHPBB3-9622 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 940018ebad..3db0d9ba96 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -357,7 +357,7 @@ function user_delete($mode, $user_ids, $retain_username = true) } $db->sql_freeresult($result); - if (!$user_rows) + if (empty($user_rows)) { return false; } -- cgit v1.2.1 From 77845c147818b4199005363a3168bbb44dc46641 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:55:17 +0100 Subject: [feature/events] Adding ledge user_update_name Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6e658b4ef4..b50dcac49c 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -112,7 +112,7 @@ function update_last_username() */ function user_update_name($old_name, $new_name) { - global $config, $db, $cache; + global $config, $db, $cache, $phpbb_dispatcher; $update_ary = array( FORUMS_TABLE => array('forum_last_poster_name'), @@ -137,6 +137,11 @@ function user_update_name($old_name, $new_name) set_config('newest_username', $new_name, true); } + $vars = array('old_name', 'new_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.user_update_name', $event); + extract($event->get_data_filtered($vars)); + // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); } -- cgit v1.2.1 From 5b226c400280588349eb3a4cab9780ae98d20c0f Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:58:22 +0100 Subject: [feature/events] Adding ledges user_delete Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index b50dcac49c..32529ec308 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -336,7 +336,7 @@ function user_add($user_row, $cp_data = false) */ function user_delete($mode, $user_id, $post_username = false) { - global $cache, $config, $db, $user, $auth; + global $cache, $config, $db, $user, $auth, $phpbb_dispatcher; global $phpbb_root_path, $phpEx; $sql = 'SELECT * @@ -540,6 +540,11 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); + $vars = array('mode', 'user_id', 'post_username'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.user_delete', $event); + extract($event->get_data_filtered($vars)); + // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) { -- cgit v1.2.1 From ae49d6dca2fd17b2b4735c2026871d1a9250b4ad Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 20:59:15 +0100 Subject: [feature/events] Adding ledge group_delete Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 32529ec308..0e751ba890 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2769,7 +2769,7 @@ function avatar_remove_db($avatar_name) */ function group_delete($group_id, $group_name = false) { - global $db, $phpbb_root_path, $phpEx; + global $db, $phpbb_root_path, $phpEx, $phpbb_dispatcher; if (!$group_name) { @@ -2818,6 +2818,11 @@ function group_delete($group_id, $group_name = false) $teampage->delete_group($group_id); unset($teampage); + $vars = array('group_id', 'group_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_delete', $event); + extract($event->get_data_filtered($vars)); + // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " WHERE group_id = $group_id"; -- cgit v1.2.1 From d4ace75370febea0f9a18ed2f744bee8caecedb2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:00:20 +0100 Subject: [feature/events] Adding ledge group_user_del Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 0e751ba890..a32f14e48f 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2955,7 +2955,7 @@ function group_user_add($group_id, $user_id_ary = false, $username_ary = false, */ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, $group_name = false) { - global $db, $auth, $config; + global $db, $auth, $config, $phpbb_dispatcher; if ($config['coppa_enable']) { @@ -3054,6 +3054,11 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, } unset($special_group_data); + $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_user_del', $event); + extract($event->get_data_filtered($vars)); + $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id AND " . $db->sql_in_set('user_id', $user_id_ary); -- cgit v1.2.1 From 4d87b2254c7762db129b2706b372538451279d13 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Thu, 15 Mar 2012 21:01:49 +0100 Subject: [feature/events] Adding ledge group_set_user_default Used by phpBB Gallery PHPBB3-9550 --- phpBB/includes/functions_user.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index a32f14e48f..82400de932 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3376,7 +3376,7 @@ function group_validate_groupname($group_id, $group_name) */ function group_set_user_default($group_id, $user_id_ary, $group_attributes = false, $update_listing = false) { - global $cache, $db; + global $cache, $db, $phpbb_dispatcher; if (empty($user_id_ary)) { @@ -3472,6 +3472,11 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); + $event = new phpbb_event_data(compact($vars)); + $phpbb_dispatcher->dispatch('core.group_set_user_default', $event); + extract($event->get_data_filtered($vars)); + if ($update_listing) { group_update_listings($group_id); -- cgit v1.2.1 From 8af7d225ef481cd26e6fd7862847183d25727117 Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Tue, 20 Mar 2012 11:23:03 +0000 Subject: [feature/events] Change to use the new method of adding events PHPBB3-9550 --- phpBB/includes/functions_user.php | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 82400de932..761ce6436a 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,9 +138,7 @@ function user_update_name($old_name, $new_name) } $vars = array('old_name', 'new_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.user_update_name', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars), $vars)); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); @@ -541,9 +539,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); $vars = array('mode', 'user_id', 'post_username'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.user_delete', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars), $vars)); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) @@ -2819,9 +2815,7 @@ function group_delete($group_id, $group_name = false) unset($teampage); $vars = array('group_id', 'group_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_delete', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars), $vars)); // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " @@ -3055,9 +3049,7 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, unset($special_group_data); $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_user_del', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars), $vars)); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id @@ -3473,9 +3465,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - $event = new phpbb_event_data(compact($vars)); - $phpbb_dispatcher->dispatch('core.group_set_user_default', $event); - extract($event->get_data_filtered($vars)); + extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars), $vars)); if ($update_listing) { -- cgit v1.2.1 From 3f1b4e83aef7f7344cd551463b59de71bb4bd6fe Mon Sep 17 00:00:00 2001 From: Michael Cullum Date: Sat, 31 Mar 2012 13:39:41 +0100 Subject: [feature/events] Removing the third trigger_event parameter PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 761ce6436a..cf6a99c2b7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,7 +138,7 @@ function user_update_name($old_name, $new_name) } $vars = array('old_name', 'new_name'); - extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars))); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); @@ -539,7 +539,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); $vars = array('mode', 'user_id', 'post_username'); - extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars))); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) @@ -2815,7 +2815,7 @@ function group_delete($group_id, $group_name = false) unset($teampage); $vars = array('group_id', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars))); // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " @@ -3049,7 +3049,7 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, unset($special_group_data); $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars))); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id @@ -3465,7 +3465,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars), $vars)); + extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars))); if ($update_listing) { -- cgit v1.2.1 From c903b1512c9926dfbc54e4e48233904385c137c6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 16:53:20 +0200 Subject: [feature/php-events] Fix docs and naming of core.update_username PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index cf6a99c2b7..eef75b8430 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -137,8 +137,16 @@ function user_update_name($old_name, $new_name) set_config('newest_username', $new_name, true); } + /** + * Update username when it is changed + * + * @event core.update_username + * @var string old_name The old username that is replaced + * @var string new_name The new username + * @since 3.1-A1 + */ $vars = array('old_name', 'new_name'); - extract($phpbb_dispatcher->trigger_event('core.user_update_name', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.update_username', compact($vars))); // Because some tables/caches use username-specific data we need to purge this here. $cache->destroy('sql', MODERATOR_CACHE_TABLE); -- cgit v1.2.1 From ec957350c14c8b0bb6dc4768b5ad363a39715cab Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:02:18 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_user_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index eef75b8430..de65d86e3f 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -546,8 +546,17 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); + /** + * Event after an user is deleted + * + * @event core.delete_user_after + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_id ID of the deleted user + * @var mixed post_username Guest username that is being used or false + * @since 3.1-A1 + */ $vars = array('mode', 'user_id', 'post_username'); - extract($phpbb_dispatcher->trigger_event('core.user_delete', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.delete_user_after', compact($vars))); // Reset newest user info if appropriate if ($config['newest_user_id'] == $user_id) -- cgit v1.2.1 From 3affe7f229f4c8a3bb4ddb1abd79aca0dc0c15a9 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 17:03:04 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index de65d86e3f..8f91a66549 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -357,6 +357,18 @@ function user_delete($mode, $user_id, $post_username = false) return false; } + /** + * Event before an user is deleted + * + * @event core.delete_user_before + * @var string mode Mode of deletion (retain/delete posts) + * @var int user_id ID of the deleted user + * @var mixed post_username Guest username that is being used or false + * @since 3.1-A1 + */ + $vars = array('mode', 'user_id', 'post_username'); + extract($phpbb_dispatcher->trigger_event('core.delete_user_before', compact($vars))); + // 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 -- cgit v1.2.1 From 8d3389448bf65f1bfc78efbfc80d0b658661f3da Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 18:54:00 +0200 Subject: [feature/php-events] Fix docs and naming of core.delete_group_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 8f91a66549..c78c74bd76 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2843,9 +2843,6 @@ function group_delete($group_id, $group_name = false) $teampage->delete_group($group_id); unset($teampage); - $vars = array('group_id', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_delete', compact($vars))); - // Delete group $sql = 'DELETE FROM ' . GROUPS_TABLE . " WHERE group_id = $group_id"; @@ -2856,6 +2853,17 @@ function group_delete($group_id, $group_name = false) WHERE group_id = $group_id"; $db->sql_query($sql); + /** + * Event after a group is deleted + * + * @event core.delete_group_after + * @var int group_id ID of the deleted group + * @var string group_name Name of the deleted group + * @since 3.1-A1 + */ + $vars = array('group_id', 'group_name'); + extract($phpbb_dispatcher->trigger_event('core.delete_group_after', compact($vars))); + // Re-cache moderators if (!function_exists('cache_moderators')) { -- cgit v1.2.1 From 3ced9f58ea5493e13796766d55059b70bc6d6a3e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:27:58 +0200 Subject: [feature/php-events] Fix docs and naming of core.group_delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index c78c74bd76..d65d59f6c5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3085,8 +3085,18 @@ function group_user_del($group_id, $user_id_ary = false, $username_ary = false, } unset($special_group_data); - $vars = array('group_id', 'user_id_ary', 'username_ary', 'group_name'); - extract($phpbb_dispatcher->trigger_event('core.group_user_del', compact($vars))); + /** + * Event before users are removed from a group + * + * @event core.group_delete_user_before + * @var int group_id ID of the group from which users are deleted + * @var string group_name Name of the group + * @var array user_id_ary IDs of the users which are removed + * @var array username_ary names of the users which are removed + * @since 3.1-A1 + */ + $vars = array('group_id', 'group_name', 'user_id_ary', 'username_ary'); + extract($phpbb_dispatcher->trigger_event('core.group_delete_user_before', compact($vars))); $sql = 'DELETE FROM ' . USER_GROUP_TABLE . " WHERE group_id = $group_id -- cgit v1.2.1 From a05cd6d837ad9d2202561ded9c100a9b1350c0c2 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Sat, 28 Jul 2012 19:50:58 +0200 Subject: [feature/php-events] Fix docs and naming of core.user_set_default_group PHPBB3-9550 --- phpBB/includes/functions_user.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index d65d59f6c5..733a6fd9bd 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3511,8 +3511,19 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } } + /** + * Event when the default group is set for an array of user + * + * @event core.user_set_default_group + * @var int group_id ID of the group + * @var array user_id_ary IDs of the users + * @var array group_attributes Group attributes which were changed + * @var array update_listing Update the list of moderators and foes + * @var array sql_ary User attributes which were changed + * @since 3.1-A1 + */ $vars = array('group_id', 'user_id_ary', 'group_attributes', 'update_listing', 'sql_ary'); - extract($phpbb_dispatcher->trigger_event('core.group_set_user_default', compact($vars))); + extract($phpbb_dispatcher->trigger_event('core.user_set_default_group', compact($vars))); if ($update_listing) { -- cgit v1.2.1 From a3b87f1e953e4f79478d8e7eb65ca9855140243a Mon Sep 17 00:00:00 2001 From: Fyorl Date: Wed, 15 Aug 2012 15:07:42 +0100 Subject: [ticket/10939] Modified functions_user.php to not use $_FILES PHPBB3-10939 --- phpBB/includes/functions_user.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 6e658b4ef4..405c5ef5d1 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -2059,13 +2059,14 @@ function avatar_remote($data, &$error) */ function avatar_upload($data, &$error) { - global $phpbb_root_path, $config, $db, $user, $phpEx; + global $phpbb_root_path, $config, $db, $user, $phpEx, $request; // Init upload class include_once($phpbb_root_path . 'includes/functions_upload.' . $phpEx); $upload = new fileupload('AVATAR_', array('jpg', 'jpeg', 'gif', 'png'), $config['avatar_filesize'], $config['avatar_min_width'], $config['avatar_min_height'], $config['avatar_max_width'], $config['avatar_max_height'], (isset($config['mime_triggers']) ? explode('|', $config['mime_triggers']) : false)); - if (!empty($_FILES['uploadfile']['name'])) + $uploadfile = $request->file('uploadfile'); + if (!empty($uploadfile['name'])) { $file = $upload->form_upload('uploadfile'); } @@ -2288,7 +2289,7 @@ function avatar_get_dimensions($avatar, $avatar_type, &$error, $current_x = 0, $ */ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = null) { - global $config, $phpbb_root_path, $auth, $user, $db; + global $config, $phpbb_root_path, $auth, $user, $db, $request; $data = array( 'uploadurl' => request_var('uploadurl', ''), @@ -2330,7 +2331,8 @@ function avatar_process_user(&$error, $custom_userdata = false, $can_upload = nu $can_upload = ($config['allow_avatar_upload'] && file_exists($phpbb_root_path . $config['avatar_path']) && phpbb_is_writable($phpbb_root_path . $config['avatar_path']) && $change_avatar && (@ini_get('file_uploads') || strtolower(@ini_get('file_uploads')) == 'on')) ? true : false; } - if ((!empty($_FILES['uploadfile']['name']) || $data['uploadurl']) && $can_upload) + $uploadfile = $request->file('uploadfile'); + if ((!empty($uploadfile['name']) || $data['uploadurl']) && $can_upload) { list($sql_ary['user_avatar_type'], $sql_ary['user_avatar'], $sql_ary['user_avatar_width'], $sql_ary['user_avatar_height']) = avatar_upload($data, $error); } -- cgit v1.2.1 From aea60f9323e8753535d0dbf5ffa1ffa09ff3c02e Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:08:28 +0200 Subject: [feature/php-events] Fix doc of core.update_username PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 733a6fd9bd..a561daa334 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -138,7 +138,7 @@ function user_update_name($old_name, $new_name) } /** - * Update username when it is changed + * Update a username when it is changed * * @event core.update_username * @var string old_name The old username that is replaced -- cgit v1.2.1 From 74d9ef0becb1558d12a7372ba68553421963ccbe Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:08:59 +0200 Subject: [feature/php-events] Fix doc of core.delete_user_before PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index a561daa334..1a75e96dd6 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -358,7 +358,7 @@ function user_delete($mode, $user_id, $post_username = false) } /** - * Event before an user is deleted + * Event before a user is deleted * * @event core.delete_user_before * @var string mode Mode of deletion (retain/delete posts) -- cgit v1.2.1 From 48b54ed1e0e5b354618fb92f9559b653e61fb530 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:09:29 +0200 Subject: [feature/php-events] Fix doc of core.delete_user_after PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 1a75e96dd6..3de7b5d7c7 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -559,7 +559,7 @@ function user_delete($mode, $user_id, $post_username = false) $db->sql_transaction('commit'); /** - * Event after an user is deleted + * Event after a user is deleted * * @event core.delete_user_after * @var string mode Mode of deletion (retain/delete posts) -- cgit v1.2.1 From 365d95c1fee2b5e73dd16d0d741df6cc64956ed7 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Mon, 20 Aug 2012 10:11:52 +0200 Subject: [feature/php-events] Fix doc of core.user_set_default_group PHPBB3-9550 --- phpBB/includes/functions_user.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 3de7b5d7c7..9e33a5122e 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -3512,7 +3512,7 @@ function group_set_user_default($group_id, $user_id_ary, $group_attributes = fal } /** - * Event when the default group is set for an array of user + * Event when the default group is set for an array of users * * @event core.user_set_default_group * @var int group_id ID of the group -- cgit v1.2.1 From 4f6f0c08979d420a47f5cc4bcab2709d27853222 Mon Sep 17 00:00:00 2001 From: David King Date: Tue, 21 Aug 2012 17:04:16 -0400 Subject: [feature/add_events] Event to modify the data array for when a user is added PHPBB3-9550 --- phpBB/includes/functions_user.php | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 9e33a5122e..f4ecb7cdc3 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -255,6 +255,16 @@ function user_add($user_row, $cp_data = false) } } + /** + * Use this event to modify the values to be inserted when a user is added + * + * @event core.user_add_modify_data + * @var array sql_ary Array of data to be inserted when a user is added + * @since 3.1-A1 + */ + $vars = array('sql_ary'); + extract($phpbb_dispatcher->trigger_event('core.user_add_modify_data', compact($vars))); + $sql = 'INSERT INTO ' . USERS_TABLE . ' ' . $db->sql_build_array('INSERT', $sql_ary); $db->sql_query($sql); -- cgit v1.2.1 From 46597be1a372f1215ffc18cfd645c1e977b44d84 Mon Sep 17 00:00:00 2001 From: David King Date: Wed, 22 Aug 2012 08:37:33 -0400 Subject: [feature/add_events] Globalize event dispatcher object in some functions PHPBB3-9550 --- phpBB/includes/functions_user.php | 1 + 1 file changed, 1 insertion(+) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index f4ecb7cdc3..f843902dd5 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -162,6 +162,7 @@ function user_update_name($old_name, $new_name) function user_add($user_row, $cp_data = false) { global $db, $user, $auth, $config, $phpbb_root_path, $phpEx; + global $phpbb_dispatcher; if (empty($user_row['username']) || !isset($user_row['group_id']) || !isset($user_row['user_email']) || !isset($user_row['user_type'])) { -- cgit v1.2.1 From 443af0ad5679c054502a0b5a8ec778c1bbd9e9d0 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Tue, 6 Nov 2012 11:15:41 -0500 Subject: [feature/prune-users] $author_id_sql is no longer needed here. PHPBB3-9622 --- phpBB/includes/functions_user.php | 2 -- 1 file changed, 2 deletions(-) (limited to 'phpBB/includes/functions_user.php') diff --git a/phpBB/includes/functions_user.php b/phpBB/includes/functions_user.php index 42b613c4f0..0e347fe477 100644 --- a/phpBB/includes/functions_user.php +++ b/phpBB/includes/functions_user.php @@ -574,8 +574,6 @@ function user_delete($mode, $user_ids, $retain_username = true) $cache->destroy('sql', MODERATOR_CACHE_TABLE); - $author_id_sql = $db->sql_in_set('author_id', $user_ids); - // Delete user log entries about this user $sql = 'DELETE FROM ' . LOG_TABLE . ' WHERE ' . $db->sql_in_set('reportee_id', $user_ids); -- cgit v1.2.1