Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
01/18/2011 10:46:09 PM (14 years ago)
Author:
boonebgorges
Message:

Modifies upgrade routine so that a site's front-end can continue to be accessible after a BP upgrade but before the wizard has been completed. Adds upgrade nags to the Dashboard. Fixes #2789. Props r-a-y and DJPaul for earlier patches and help testing

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-core/admin/bp-core-update.php

    r3728 r3736  
    11<?php
    2 
    3 if ( !defined( 'BP_ROOT_BLOG' ) )
    4     define( 'BP_ROOT_BLOG', 1 );
    5 
    6 require_once( dirname( dirname( __FILE__ ) ) . '/bp-core-wpabstraction.php' );
    7 
    8 register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
    9 
    10 // Install site options on activation
    11 bp_core_activate_site_options( array( 'bp-disable-account-deletion' => 0, 'bp-disable-avatar-uploads' => 0, 'bp-disable-blogforum-comments' => 0,  'bp-disable-forum-directory' => 0,  'bp-disable-profile-sync' => 0 ) );
    12 
    13 /**
    14  * When switching from single to multisite we need to copy blog options to
    15  * site options.
    16  *
    17  * @package BuddyPress Core
    18  */
    19 function bp_core_activate_site_options( $keys = array() ) {
    20     global $bp;
    21 
    22     $bp->site_options = bp_core_get_site_options();
    23 
    24     if ( !empty( $keys ) && is_array( $keys ) ) {
    25         $errors = false;
    26 
    27         foreach ( $keys as $key => $default ) {
    28             if ( empty( $bp->site_options[ $key ] ) ) {
    29                 $bp->site_options[ $key ] = get_blog_option( BP_ROOT_BLOG, $key, $default );
    30 
    31                 if ( !update_site_option( $key, $bp->site_options[ $key ] ) )
    32                     $errors = true;
    33             }
    34         }
    35 
    36         if ( empty( $errors ) )
    37             return true;
    38     }
    39 
    40     return false;
    41 }
    422
    433class BP_Core_Setup_Wizard {
     
    11575                $steps[] = __( 'Database Update', 'buddypress' );
    11676
    117             if ( $this->current_version < 1225 )
     77            if ( $this->current_version < 1225 || ( function_exists( 'bp_core_get_page_meta' ) && !bp_core_get_page_meta() ) )
    11878                $steps[] = __( 'Pages', 'buddypress' );
    11979
     
    152112                break;
    153113        }
    154 
     114       
    155115        if ( !$result && $this->current_step )
    156116            $this->current_step--;
     
    461421
    462422        // Check for defined slugs
    463         if ( defined( 'BP_MEMBERS_SLUG' ) )
     423        if ( defined( 'BP_MEMBERS_SLUG' ) && BP_MEMBERS_SLUG )
    464424            $members_slug = constant( 'BP_MEMBERS_SLUG' );
    465425        else
    466426            $members_slug = __( 'members', 'buddypress' );
    467427
    468         if ( defined( 'BP_GROUPS_SLUG' ) )
     428        if ( defined( 'BP_GROUPS_SLUG' ) && BP_GROUPS_SLUG )
    469429            $groups_slug = constant( 'BP_GROUPS_SLUG' );
    470430        else
    471431            $groups_slug = __( 'groups', 'buddypress' );
    472432
    473         if ( defined( 'BP_ACTIVITY_SLUG' ) )
     433        if ( defined( 'BP_ACTIVITY_SLUG' ) && BP_ACTIVITY_SLUG )
    474434            $activity_slug = constant( 'BP_ACTIVITY_SLUG' );
    475435        else
    476436            $activity_slug = __( 'activity', 'buddypress' );
    477437
    478         if ( defined( 'BP_FORUMS_SLUG' ) )
     438        if ( defined( 'BP_FORUMS_SLUG' ) && BP_FORUMS_SLUG )
    479439            $forums_slug = constant( 'BP_FORUMS_SLUG' );
    480440        else
    481441            $forums_slug = __( 'forums', 'buddypress' );
    482442
    483         if ( defined( 'BP_BLOGS_SLUG' ) )
     443        if ( defined( 'BP_BLOGS_SLUG' ) && BP_BLOGS_SLUG )
    484444            $blogs_slug = constant( 'BP_BLOGS_SLUG' );
    485445        else
    486446            $blogs_slug = __( 'blogs', 'buddypress' );
    487447
    488         if ( defined( 'BP_REGISTER_SLUG' ) )
     448        if ( defined( 'BP_REGISTER_SLUG' ) && BP_REGISTER_SLUG )
    489449            $register_slug = constant( 'BP_REGISTER_SLUG' );
    490450        else
    491451            $register_slug = __( 'register', 'buddypress' );
    492452
    493         if ( defined( 'BP_ACTIVATION_SLUG' ) )
     453        if ( defined( 'BP_ACTIVATION_SLUG' ) && BP_ACTIVATION_SLUG )
    494454            $activation_slug = constant( 'BP_ACTIVATION_SLUG' );
    495455        else
     
    787747    }
    788748
    789     function step_finish() {
     749    function step_finish() {           
     750        // Update the DB version in the database
     751        update_site_option( 'bp-db-version', constant( 'BP_DB_VERSION' ) );
     752        delete_site_option( 'bp-core-db-version' );
     753   
    790754        if ( !current_user_can( 'activate_plugins' ) )
    791755            return false;
     
    829793            if ( $this->current_version < 1225 )
    830794                $this->update_1_3();
    831 
     795               
    832796            return true;
    833797        }
     
    918882
    919883            // Delete any existing pages
    920             $existing_pages = get_option( 'bp-pages' );
     884            $existing_pages = bp_core_update_get_page_meta( 'bp-pages' );
    921885
    922886            foreach ( (array)$existing_pages as $page_id )
     
    10611025        if ( isset( $_POST['submit'] ) ) {
    10621026            check_admin_referer( 'bpwizard_finish' );
    1063 
     1027           
    10641028            // Delete the setup cookie
    10651029            @setcookie( 'bp-wizard-step', '', time() - 3600, COOKIEPATH );
     
    11221086add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu', 'bp_core_setup_wizard_init', 7 );
    11231087
    1124 
    11251088function bp_core_install( $disabled = false ) {
    11261089    global $wpdb;
     
    11991162
    12001163/**
    1201  * bp_core_add_admin_menu_page()
    1202  *
    12031164 * A better version of add_admin_menu_page() that allows positioning of menus.
    12041165 *
    12051166 * @package BuddyPress Core
    12061167 */
    1207 function bp_core_add_admin_menu_page( $args = '' ) {
     1168function bp_core_update_add_admin_menu_page( $args = '' ) {
    12081169    global $menu, $admin_page_hooks, $_registered_pages;
    12091170
     
    12721233 * @uses add_submenu_page() WP function to add a submenu item
    12731234 */
    1274 function bp_core_add_admin_menu() {
     1235function bp_core_update_add_admin_menu() {
    12751236    global $bp_wizard;
    12761237
     1238    // Only load this version of the menu if this is an upgrade or a new installation
     1239    if ( ( !defined( 'BP_IS_UPGRADE' ) || !BP_IS_UPGRADE ) && ( !defined( 'BP_IS_INSTALL' ) || !BP_IS_INSTALL ) )
     1240        return false;
     1241   
    12771242    if ( !current_user_can( 'activate_plugins' ) )
    12781243        return false;
     
    12841249
    12851250    // Add the administration tab under the "Site Admin" tab for site administrators
    1286     bp_core_add_admin_menu_page( array(
     1251    bp_core_update_add_admin_menu_page( array(
    12871252        'menu_title'   => __( 'BuddyPress', 'buddypress' ),
    12881253        'page_title'   => __( 'BuddyPress', 'buddypress' ),
     
    12961261
    12971262    // Add a hook for css/js
    1298     add_action( "admin_print_styles-$hook", 'bp_core_add_admin_menu_styles' );
     1263    add_action( "admin_print_styles-$hook", 'bp_core_update_add_admin_menu_styles' );
    12991264}
    1300 add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu',  'bp_core_add_admin_menu', 9 );
    1301 
    1302 function bp_core_add_admin_menu_styles() {
     1265add_action( is_multisite() ? 'network_admin_menu' : 'admin_menu',  'bp_core_update_add_admin_menu', 9 );
     1266
     1267function bp_core_update_add_admin_menu_styles() {
    13031268    if ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG )
    13041269        wp_enqueue_style( 'bp-admin-css', apply_filters( 'bp_core_admin_css', plugins_url( $path = '/buddypress' ) . '/bp-core/css/admin.dev.css' ) );
     
    13291294<?php
    13301295}
    1331 add_action( 'admin_head', 'bp_core_add_admin_menu_styles' );
     1296add_action( 'admin_head', 'bp_core_update_add_admin_menu_styles' );
     1297
     1298/**
     1299 * Fetches BP pages from the meta table, depending on setup
     1300 *
     1301 * @package BuddyPress Core
     1302 * @since 1.3
     1303 *
     1304 * @return array $page_ids
     1305 */
     1306function bp_core_update_get_page_meta() {
     1307    if ( !defined( 'BP_ENABLE_MULTIBLOG' ) && is_multisite() )
     1308        $page_ids = get_blog_option( BP_ROOT_BLOG, 'bp-pages' );
     1309    else
     1310        $page_ids = get_option( 'bp-pages' );
     1311
     1312    return $page_ids;
     1313}
     1314
     1315/**
     1316 * Adds an admin nag about running the BP upgrade/install wizard
     1317 *
     1318 * @package BuddyPress Core
     1319 * @since 1.3
     1320 * @global $pagenow The current admin page
     1321 */
     1322function bp_core_update_nag() {
     1323    global $pagenow;
     1324
     1325    if ( !is_super_admin() )
     1326        return;
     1327   
     1328    if ( 'admin.php' == $pagenow && ( empty( $_GET['page'] ) || 'bp-wizard' == $_GET['page'] ) )
     1329        return;
     1330   
     1331    if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )
     1332        $msg = sprintf( __( 'BuddyPress has been updated! Please run the <a href="%s">upgrade wizard</a>.', 'buddypress' ), admin_url( 'admin.php?page=bp-wizard' ) );
     1333    else if ( defined( 'BP_IS_INSTALL' ) && BP_IS_INSTALL )
     1334        $msg = sprintf( __( 'BuddyPress has been installed! Please run the <a href="%s">upgrade wizard</a>.', 'buddypress' ), admin_url( 'admin.php?page=bp-wizard' ) );
     1335                 
     1336    echo "<div class='update-nag'>$msg</div>";
     1337}
     1338add_action( 'admin_notices', 'bp_core_update_nag', 5 );
     1339
    13321340
    13331341?>
Note: See TracChangeset for help on using the changeset viewer.