function bb_delete_user($user_id, $reassign = 0) { global $nxt_users_object, $bbdb; if (!($user = bb_get_user($user_id))) { return false; } if ($reassign) { if (!($new_user = bb_get_user($reassign))) { return false; } $bbdb->update($bbdb->posts, array('poster_id' => $new_user->ID), array('poster_id' => $user->ID)); $bbdb->update($bbdb->term_relationships, array('user_id' => $new_user->ID), array('user_id' => $user->ID)); $bbdb->update($bbdb->topics, array('topic_poster' => $new_user->ID, 'topic_poster_name' => $new_user->user_login), array('topic_poster' => $user->ID)); $bbdb->update($bbdb->topics, array('topic_last_poster' => $new_user->ID, 'topic_last_poster_name' => $new_user->user_login), array('topic_last_poster' => $user->ID)); bb_update_topics_replied($new_user->ID); nxt_cache_flush('bb_post'); nxt_cache_flush('bb_thread'); nxt_cache_flush('bb_topic_tag'); nxt_cache_flush('bb_topic'); } do_action('bb_delete_user', $user->ID, $reassign); $nxt_users_object->delete_user($user->ID); return true; }
function bb_upgrade_all() { if (!ini_get('safe_mode')) { set_time_limit(600); } $_do_user_operations = true; if (bb_get_option('nxt_table_prefix') || defined('BB_SCHEMA_IGNORE_nxt_USERS_TABLES') && BB_SCHEMA_IGNORE_nxt_USERS_TABLES) { $_do_user_operations = false; } $bb_upgrade = array(); // Pre DB Delta if ($_do_user_operations) { $bb_upgrade['messages'][] = bb_upgrade_160(); // Break blocked users $bb_upgrade['messages'][] = bb_upgrade_170(); // Escaping in usermeta $bb_upgrade['messages'][] = bb_upgrade_180(); // Delete users for real } $bb_upgrade['messages'][] = bb_upgrade_190(); // Move topic_resolved to topicmeta $bb_upgrade['messages'][] = bb_upgrade_200(); // Indices $bb_upgrade['messages'][] = bb_upgrade_210(); // Convert text slugs to varchar slugs $bb_upgrade['messages'][] = bb_upgrade_220(); // remove bb_tagged primary key, add new column and primary key require_once BACKPRESS_PATH . 'class.bp-sql-schema-parser.php'; require_once BB_PATH . 'bb-admin/includes/defaults.bb-schema.php'; $delta = BP_SQL_Schema_Parser::delta($bbdb, $bb_queries, $bb_schema_ignore); if (is_array($delta)) { $bb_upgrade['messages'] = array_merge($bb_upgrade['messages'], $delta['messages']); $bb_upgrade['errors'] = $delta['errors']; } else { $bb_upgrade['errors'] = array(); } // Post DB Delta $bb_upgrade['messages'][] = bb_upgrade_1000(); // Make forum and topic slugs $bb_upgrade['messages'][] = bb_upgrade_1010(); // Make sure all forums have a valid parent if ($_do_user_operations) { $bb_upgrade['messages'][] = bb_upgrade_1020(); // Add a user_nicename to existing users } $bb_upgrade['messages'][] = bb_upgrade_1030(); // Move admin_email option to from_email $bb_upgrade['messages'][] = bb_upgrade_1040(); // Activate Akismet and bozo plugins and convert active plugins to new convention on upgrade only $bb_upgrade['messages'][] = bb_upgrade_1050(); // Update active theme if present $bb_upgrade['messages'][] = bb_upgrade_1070(); // trim whitespace from raw_tag $bb_upgrade['messages'][] = bb_upgrade_1080(); // Convert tags to taxonomy if ($_do_user_operations) { $bb_upgrade['messages'][] = bb_upgrade_1090(); // Add display names } $bb_upgrade['messages'][] = bb_upgrade_1100(); // Replace forum_stickies index with stickies (#876) $bb_upgrade['messages'][] = bb_upgrade_1110(); // Create plugin directory (#1083) $bb_upgrade['messages'][] = bb_upgrade_1120(); // Create theme directory (#1083) $bb_upgrade['messages'][] = bb_upgrade_1130(); // Add subscriptions option and set it to true (#1268) bb_update_db_version(); nxt_cache_flush(); $bb_upgrade['messages'] = array_filter($bb_upgrade['messages']); $bb_upgrade['errors'] = array_filter($bb_upgrade['errors']); return $bb_upgrade; }
function step_components_save() { if (isset($_POST['submit']) && isset($_POST['bp_components'])) { check_admin_referer('bpwizard_components'); $active_components = array(); // Settings form submitted, now save the settings. foreach ((array) $_POST['bp_components'] as $key => $value) { $active_components[$key] = 1; } bp_update_option('bp-active-components', $active_components); nxt_cache_flush(); bp_core_install(); return true; } return false; }
$bbdb->show_errors(); $upgrade_log = array(__('Beginning upgrade…')); if (is_array($messages['messages'])) { $upgrade_log = array_merge($upgrade_log, $messages['messages']); } $upgrade_log[] = '>>> ' . __('Done'); $error_log = array(); if (is_array($messages['errors'])) { $error_log = $messages['errors']; } if (bb_get_option('bb_db_version') === bb_get_option_from_db('bb_db_version') && !count($error_log)) { $step = 'complete'; } else { $step = 'error'; } nxt_cache_flush(); } } bb_install_header(__('bbPress database upgrade'), false, true); ?> <script type="text/javascript" charset="utf-8"> function toggleAdvanced(toggle, target) { var toggleObj = document.getElementById(toggle); var targetObj = document.getElementById(target); if (toggleObj.checked) { targetObj.style.display = 'block'; } else { targetObj.style.display = 'none'; } } </script>
function bb_move_forum_topics($from_forum_id, $to_forum_id) { global $bbdb; $from_forum_id = (int) $from_forum_id; $to_forum_id = (int) $to_forum_id; add_filter('get_forum_where', 'bb_no_where'); // Just in case $from_forum = bb_get_forum($from_forum_id); if (!($to_forum = bb_get_forum($to_forum_id))) { return false; } $posts = $to_forum->posts + ($from_forum ? $from_forum->posts : 0); $topics = $to_forum->topics + ($from_forum ? $from_forum->topics : 0); $bbdb->update($bbdb->forums, compact('topics', 'posts'), array('forum_id' => $to_forum_id)); $bbdb->update($bbdb->forums, array('topics' => 0, 'posts' => 0), array('forum_id' => $from_forum_id)); $bbdb->update($bbdb->posts, array('forum_id' => $to_forum_id), array('forum_id' => $from_forum_id)); $topic_ids = $bbdb->get_col($bbdb->prepare("SELECT topic_id FROM {$bbdb->topics} WHERE forum_id = %d", $from_forum_id)); $return = $bbdb->update($bbdb->topics, array('forum_id' => $to_forum_id), array('forum_id' => $from_forum_id)); nxt_cache_flush('bb_post'); if ($topic_ids) { foreach ($topic_ids as $topic_id) { // should maybe just flush these groups nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); } } nxt_cache_delete($from_forum_id, 'bb_forum'); nxt_cache_delete($to_forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); return $return; }
function bb_move_topic($topic_id, $forum_id) { global $bbdb; $topic = get_topic($topic_id); $forum = bb_get_forum($forum_id); $topic_id = (int) $topic->topic_id; $forum_id = (int) $forum->forum_id; if ($topic && $forum && $topic->forum_id != $forum_id) { $bbdb->update($bbdb->posts, compact('forum_id'), compact('topic_id')); $bbdb->update($bbdb->topics, compact('forum_id'), compact('topic_id')); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1, posts = posts + %d WHERE forum_id = %d", $topic->topic_posts, $forum_id)); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics - 1, posts = posts - %d WHERE forum_id = %d", $topic->topic_posts, $topic->forum_id)); nxt_cache_flush('bb_post'); nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($forum_id, 'bb_forum'); nxt_cache_flush('bb_forums'); nxt_cache_flush('bb_query'); nxt_cache_flush('bb_cache_posts_post_ids'); do_action('bb_move_topic', $topic_id, $forum_id, $topic->forum_id); return $forum_id; } return false; }
/** * Deletes usermeta for the user when the user is deleted. * * @package BuddyPress Core * @param $user_id The user id for the user to delete usermeta for * @uses bp_delete_user_meta() deletes a row from the nxt_usermeta table based on meta_key */ function bp_core_remove_data($user_id) { // Remove usermeta bp_delete_user_meta($user_id, 'last_activity'); // Flush the cache to remove the user from all cached objects nxt_cache_flush(); }
/** * Run NXTClass Upgrade functions. * * {@internal Missing Long Description}} * * @since 2.1.0 * * @return null */ function nxt_upgrade() { global $nxt_current_db_version, $nxt_db_version, $nxtdb; $nxt_current_db_version = __get_option('db_version'); // We are up-to-date. Nothing to do. if ($nxt_db_version == $nxt_current_db_version) { return; } if (!is_blog_installed()) { return; } nxt_check_mysql_version(); nxt_cache_flush(); pre_schema_upgrade(); make_db_current_silent(); upgrade_all(); if (is_multisite() && is_main_site()) { upgrade_network(); } nxt_cache_flush(); if (is_multisite()) { if ($nxtdb->get_row("SELECT blog_id FROM {$nxtdb->blog_versions} WHERE blog_id = '{$nxtdb->blogid}'")) { $nxtdb->query("UPDATE {$nxtdb->blog_versions} SET db_version = '{$nxt_db_version}' WHERE blog_id = '{$nxtdb->blogid}'"); } else { $nxtdb->query("INSERT INTO {$nxtdb->blog_versions} ( `blog_id` , `db_version` , `last_updated` ) VALUES ( '{$nxtdb->blogid}', '{$nxt_db_version}', NOW());"); } } }
function bb_delete_post($post_id, $new_status = 0) { global $bbdb, $topic, $bb_post; $post_id = (int) $post_id; $bb_post = bb_get_post($post_id); $new_status = (int) $new_status; $old_status = (int) $bb_post->post_status; add_filter('get_topic_where', 'bb_no_where'); $topic = get_topic($bb_post->topic_id); $topic_id = (int) $topic->topic_id; if ($bb_post) { $uid = (int) $bb_post->poster_id; if ($new_status == $old_status) { return; } _bb_delete_post($post_id, $new_status); if (0 == $old_status) { bb_update_topicmeta($topic_id, 'deleted_posts', $topic->deleted_posts + 1); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts - 1 WHERE forum_id = %d", $topic->forum_id)); } else { if (0 == $new_status) { bb_update_topicmeta($topic_id, 'deleted_posts', $topic->deleted_posts - 1); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET posts = posts + 1 WHERE forum_id = %d", $topic->forum_id)); } } $posts = (int) $bbdb->get_var($bbdb->prepare("SELECT COUNT(*) FROM {$bbdb->posts} WHERE topic_id = %d AND post_status = 0", $topic_id)); $bbdb->update($bbdb->topics, array('topic_posts' => $posts), compact('topic_id')); if (0 == $posts) { if (0 == $topic->topic_status || 1 == $new_status) { bb_delete_topic($topic_id, $new_status); } } else { if (0 != $topic->topic_status) { $bbdb->update($bbdb->topics, array('topic_status' => 0), compact('topic_id')); $bbdb->query($bbdb->prepare("UPDATE {$bbdb->forums} SET topics = topics + 1 WHERE forum_id = %d", $topic->forum_id)); } bb_topic_set_last_post($topic_id); bb_update_post_positions($topic_id); bb_update_topic_voices($topic_id); } $user = bb_get_user($uid); $user_posts = new BB_Query('post', array('post_author_id' => $user->ID, 'topic_id' => $topic_id)); if ($new_status && !$user_posts->results) { $topics_replied_key = $bbdb->prefix . 'topics_replied'; bb_update_usermeta($user->ID, $topics_replied_key, $user->{$topics_replied_key} - 1); } nxt_cache_delete($topic_id, 'bb_topic'); nxt_cache_delete($topic_id, 'bb_thread'); nxt_cache_flush('bb_forums'); nxt_cache_flush('bb_query'); nxt_cache_flush('bb_cache_posts_post_ids'); do_action('bb_delete_post', $post_id, $new_status, $old_status); return $post_id; } else { return false; } }
/** * Performs post-import cleanup of files and the cache */ function import_end() { nxt_import_cleanup($this->id); nxt_cache_flush(); foreach (get_taxonomies() as $tax) { delete_option("{$tax}_children"); _get_term_hierarchy($tax); } nxt_defer_term_counting(false); nxt_defer_comment_counting(false); echo '<p>' . __('All done.', 'nxtclass-importer') . ' <a href="' . admin_url() . '">' . __('Have fun!', 'nxtclass-importer') . '</a>' . '</p>'; echo '<p>' . __('Remember to update the passwords and roles of imported users.', 'nxtclass-importer') . '</p>'; do_action('import_end'); }