Skip to:
Content

BuddyPress.org

Changeset 3736


Ignore:
Timestamp:
01/18/2011 10:46:09 PM (16 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

Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-blogs.php

    r3728 r3736  
    1414        if ( !defined( 'BP_BLOGS_SLUG' ) && isset( $bp->pages->blogs->slug ) )
    1515                define ( 'BP_BLOGS_SLUG', bp_core_component_slug_from_root_slug( $bp->pages->blogs->slug ) );
    16         else if( !defined( 'BP_BLOGS_SLUG' ) )
     16        else if ( !defined( 'BP_BLOGS_SLUG' ) )
    1717                define ( 'BP_BLOGS_SLUG', 'blogs' );
    1818
    1919        // For internal identification
    2020        $bp->blogs->id   = 'blogs';
    21         $bp->blogs->name = $bp->pages->blogs->name;
     21        $bp->blogs->name = !empty( $bp->pages->blogs->name ) ? $bp->pages->blogs->name : 'blogs';
    2222
    2323        // Slugs
    2424        $bp->blogs->slug      = BP_BLOGS_SLUG;
    25         $bp->blogs->root_slug = $bp->pages->blogs->slug;
     25        $bp->blogs->root_slug = !empty( $bp->pages->blogs->slug ) ? $bp->pages->blogs->slug : BP_BLOGS_SLUG;
    2626
    2727        // Tables
     
    558558function bp_blogs_remove_post( $post_id, $blog_id = false, $user_id = false ) {
    559559        global $current_blog, $bp;
     560       
     561        if ( empty( $current_blog->blog_id ) )
     562                return false;
    560563
    561564        $post_id = (int)$post_id;
  • trunk/bp-core.php

    r3734 r3736  
    4444        require ( BP_PLUGIN_DIR . '/bp-core/bp-core-adminbar.php' );
    4545
    46 // Register BuddyPress themes contained within the bp-theme folder
    47 register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
    48 
    4946/** "And now for something completely different" ******************************/
    5047
     
    208205 * These can be overridden manually by defining these slugs in wp-config.php.
    209206 *
     207 * The fallback values are only used during initial BP page creation, when no slugs have been
     208 * explicitly defined.
     209 *
    210210 * @package BuddyPress Core Core
    211211 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
     
    216216        if ( !defined( 'BP_MEMBERS_SLUG' ) )
    217217                define( 'BP_MEMBERS_SLUG', $bp->pages->members->slug );
    218 
     218       
    219219        if ( !defined( 'BP_REGISTER_SLUG' ) )
    220220                define( 'BP_REGISTER_SLUG', $bp->pages->register->slug );
    221 
     221       
    222222        if ( !defined( 'BP_ACTIVATION_SLUG' ) )
    223223                define( 'BP_ACTIVATION_SLUG', $bp->pages->activate->slug );
     224       
    224225}
    225226add_action( 'bp_setup_globals', 'bp_core_define_slugs' );
     
    258259        $page_ids = bp_core_get_page_meta();
    259260
    260         if ( empty( $page_ids ) )
    261                 return false;
     261        $pages = new stdClass;
     262
     263        // When upgrading to BP 1.3+ from a version of BP that does not use WP pages, $bp->pages
     264        // must be populated with dummy info to avoid crashing the site while the db is upgraded
     265        if ( empty( $page_ids ) ) {
     266                $dummy_components = array(
     267                        'members',
     268                        'groups',
     269                        'activity',
     270                        'forums',
     271                        'activate',
     272                        'register',
     273                        'blogs'
     274                );
     275               
     276                foreach ( $dummy_components as $dc ) {
     277                        $pages->{$dc}->name     = $dc;
     278                        $pages->{$dc}->slug     = $dc;
     279                        $pages->{$dc}->id       = $dc;
     280                }
     281               
     282                return $pages;
     283        }
    262284
    263285        $posts_table_name = is_multisite() && !defined( 'BP_ENABLE_MULTIBLOG' ) ? $wpdb->get_blog_prefix( BP_ROOT_BLOG ) . 'posts' : $wpdb->posts;
     
    266288
    267289        $page_names = $wpdb->get_results( $wpdb->prepare( "SELECT ID, post_name, post_parent FROM {$posts_table_name} WHERE ID IN ({$page_ids_sql}) " ) );
    268         $pages = new stdClass;
    269290
    270291        foreach ( (array)$page_ids as $key => $page_id ) {
     
    348369        if ( !is_super_admin() )
    349370                return false;
     371       
     372        // Don't add this version of the admin menu if a BP upgrade is in progress
     373        // See bp_core_update_add_admin_menu()
     374        if ( defined( 'BP_IS_UPGRADE' ) && BP_IS_UPGRADE )
     375                return false;
    350376
    351377        // Add the administration tab under the "Site Admin" tab for site administrators
  • 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?>
  • trunk/bp-loader.php

    r3728 r3736  
    1111
    1212define( 'BP_VERSION', '1.3-bleeding' );
    13 define( 'BP_DB_VERSION', 1225 );
     13define( 'BP_DB_VERSION', 3705 );
    1414
    1515// Define on which blog ID BuddyPress should run
     
    1717        define( 'BP_ROOT_BLOG', 1 );
    1818
    19 /***
    20  * Check if this is the first time BuddyPress has been loaded, or the first time
    21  * since an update. If so, load the install/update routine only.
    22  */
    23 if ( get_site_option( 'bp-db-version' ) < constant( 'BP_DB_VERSION' ) ) {
     19// Register BuddyPress themes contained within the bp-themes folder
     20register_theme_directory( WP_PLUGIN_DIR . '/buddypress/bp-themes' );
     21         
     22// Test to see whether this is a new installation or an upgraded version of BuddyPress
     23$bp_db_version = get_site_option( 'bp-db-version' );
     24if ( ! $bp_db_version )
     25        $bp_db_version = get_site_option( 'bp-core-db-version' );  // BP 1.2 option name
     26         
     27if ( ! $bp_db_version ) {
     28        // This is a new installation. Run the wizard before loading BP core files
     29        define( 'BP_IS_INSTALL', true );
    2430        require_once( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-update.php' );
    25 
    26 /***
    27  * If the install or update routine is completed and everything is up to date
    28  * continue loading BuddyPress as normal.
    29  */
    3031} else {
    3132        /***
     
    6566        if ( !isset( $bp_deactivated['bp-xprofile.php'] ) && file_exists( BP_PLUGIN_DIR . '/bp-xprofile.php') )
    6667                include( BP_PLUGIN_DIR . '/bp-xprofile.php' );
     68               
     69        // If this is an upgrade, load the upgrade file
     70        if ( $bp_db_version < constant( 'BP_DB_VERSION' ) ) {
     71                define( 'BP_IS_UPGRADE', true );
     72                require_once( WP_PLUGIN_DIR . '/buddypress/bp-core/admin/bp-core-update.php' );
     73        }
    6774
    6875        add_action( 'plugins_loaded', 'bp_loaded', 20 );
     
    136143}
    137144
    138 // Activation Function
     145/**
     146 * Defines BP's activation routine.
     147 *
     148 * Most of BP's crucial setup is handled by the setup wizard. This function takes care of some
     149 * issues with incompatible legacy themes, and provides a hook for other functions to know that
     150 * BP has been activated.
     151 *
     152 * @package BuddyPress Core
     153*/
    139154function bp_loader_activate() {
    140155        // Force refresh theme roots.
    141156        delete_site_transient( 'theme_roots' );
     157
     158        if ( !function_exists( 'get_blog_option' ) )
     159                require ( WP_PLUGIN_DIR . '/buddypress/bp-core/bp-core-wpabstraction.php' );
    142160
    143161        // Switch the user to the new bp-default if they are using the old
  • trunk/bp-themes/bp-default/functions.php

    r3724 r3736  
    3636if ( ! isset( $content_width ) )
    3737        $content_width = 591;
    38 
    39 /**
    40  * Temporary work-around to prevent errors with bp-default being active
    41  * when BuddyPress is not installed.
    42  */
    43 if ( !constant( 'BP_VERSION' ) || !get_site_option( 'bp-db-version' ) ) {
    44         switch_theme( 'twentyten', 'twentyten' );
    45         wp_redirect( $_SERVER['HTTP_REFERER'] );
    46         exit;
    47 }
    4838
    4939if ( !function_exists( 'bp_dtheme_setup' ) ) :
Note: See TracChangeset for help on using the changeset viewer.