Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/24/2011 05:12:13 PM (15 years ago)
Author:
boonebgorges
Message:

Ensures that upgrades from BP 1.2.x are recognized as upgrades, and previous component settings are saved. Fixes #3153. Props cnorris23

File:
1 edited

Legend:

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

    r4487 r4556  
    1515
    1616        function __construct() {
    17                 // Look for current DB version
    18                 if ( !$this->database_version = get_site_option( 'bp-db-version' ) ) {
    19                         if ( $this->database_version = get_option( 'bp-db-version' ) ) {
    20                                 $this->is_network_activate = true;
    21                         } else {
    22                                 if ( !$this->current_step() ) {
    23                                         setcookie( 'bp-wizard-step', 0, time() + 60 * 60 * 24, COOKIEPATH );
    24                                         $_COOKIE['bp-wizard-step'] = 0;
    25                                 }
    26                         }
     17                global $bp;
     18
     19                // Ensure that we have access to some utility functions
     20                include( BP_PLUGIN_DIR . '/bp-core/bp-core-functions.php' );
     21
     22                // Get current DB version
     23                $this->database_version = !empty( $bp->database_version ) ? (int) $bp->database_version : 0;
     24
     25                if ( !empty( $bp->is_network_activate ) ) {
     26                        $this->is_network_activate = $bp->is_network_activate;
     27
     28                } elseif ( !$this->current_step() ) {
     29                        setcookie( 'bp-wizard-step', 0, time() + 60 * 60 * 24, COOKIEPATH );
     30                        $_COOKIE['bp-wizard-step'] = 0;
    2731                }
    2832
    2933                $this->new_version  = constant( 'BP_DB_VERSION' );
    30                 $this->setup_type   = ( empty( $this->database_version ) && !(int)get_site_option( 'bp-core-db-version' ) ) ? 'install' : 'update';
     34                $this->setup_type   = !empty( $bp->maintenance_mode ) ? $bp->maintenance_mode : '';
    3135                $this->current_step = $this->current_step();
     36
     37                // Remove the admin menu while we update/install
     38                remove_action( bp_core_admin_hook(), 'bp_core_add_admin_menu', 9 );
    3239
    3340                // Call the save method that will save data and modify $current_step
     
    7279                                $steps[] = __( 'Multisite Update', 'buddypress' );
    7380
    74                         if ( $this->database_version < $this->new_version )
     81                        if ( $this->database_version < (int) $this->new_version )
    7582                                $steps[] = __( 'Database Update', 'buddypress' );
    7683
    77                         if ( $this->database_version < 1225 || !bp_core_get_page_meta() )
     84                        if ( $this->database_version < 1801 || !bp_core_get_page_meta() )
    7885                                $steps[] = __( 'Pages', 'buddypress' );
    7986
     
    265272
    266273                // Call up old bp-pages to see if a page has been previously linked to Blogs
    267                 $page_blog_id           = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    268                 $existing_pages_data    = get_blog_option( $page_blog_id, 'bp-pages' );
    269                 $existing_pages         = $existing_pages_data[$page_blog_id];
     274                $page_blog_id        = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     275                $existing_pages_data = get_blog_option( $page_blog_id, 'bp-pages' );
     276                $existing_pages      = $existing_pages_data[$page_blog_id];
    270277
    271278                if ( !empty( $existing_pages['blogs'] ) )
     
    719726
    720727        function step_db_update_save() {
     728                global $bp;
     729
    721730                if ( isset( $_POST['submit'] ) ) {
    722731                        check_admin_referer( 'bpwizard_db_update' );
     
    725734                        bp_core_install();
    726735
    727                         if ( $this->database_version < 1225 )
     736                        if ( $this->database_version < 1801 )
    728737                                $this->update_1_3();
     738
     739                        // Update the active components option early if we're updating
     740                        if ( 'update' == $this->setup_type )
     741                                update_site_option( 'bp-active-components', $bp->active_components );
    729742
    730743                        return true;
     
    740753                        check_admin_referer( 'bpwizard_ms_update' );
    741754
    742                         if ( !$active_components = get_option( 'bp-active-components' ) )
     755                        if ( !$active_components = get_site_option( 'bp-active-components' ) )
    743756                                $active_components = array();
    744757
    745758                        // Transfer important settings from blog options to site options
    746759                        $options = array(
    747                                 'bp-db-version'         => $this->database_version,
    748                                 'bp-active-components'  => $active_components,
    749                                 'avatar-default'        => get_option( 'avatar-default' )
     760                                'bp-db-version'        => $this->database_version,
     761                                'bp-active-components' => $active_components,
     762                                'avatar-default'       => get_option( 'avatar-default' )
    750763                        );
    751764                        bp_core_activate_site_options( $options );
     
    759772
    760773                                // Move bp-pages data from the blog options table to site options
    761                                 $page_blog_id           = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    762                                 $existing_pages_data    = get_blog_option( $page_blog_id, 'bp-pages' );
    763                                 $existing_pages         = $existing_pages_data[$page_blog_id];
    764 
    765                                 $bp_pages               = $this->setup_pages( (array)$_POST['bp_pages'] );
    766                                 $bp_pages               = array_merge( (array)$existing_pages, (array)$bp_pages );
     774                                $page_blog_id        = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     775                                $existing_pages_data = get_blog_option( $page_blog_id, 'bp-pages' );
     776                                $existing_pages      = $existing_pages_data[$page_blog_id];
     777
     778                                $bp_pages            = $this->setup_pages( (array)$_POST['bp_pages'] );
     779                                $bp_pages            = array_merge( (array)$existing_pages, (array)$bp_pages );
    767780
    768781                                $existing_pages_data[$page_blog_id] = $bp_pages;
     
    822835                                wp_delete_post( $page_id, true );
    823836
    824                         $blog_pages     = $this->setup_pages( (array)$_POST['bp_pages'] );
    825                         $page_blog_id   = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
    826                         $bp_pages       = array( $page_blog_id => $blog_pages );
     837                        $blog_pages   = $this->setup_pages( (array)$_POST['bp_pages'] );
     838                        $page_blog_id = is_multisite() && defined( 'BP_ENABLE_MULTIBLOG' ) && BP_ENABLE_MULTIBLOG ? get_current_blog_id() : BP_ROOT_BLOG;
     839                        $bp_pages     = array( $page_blog_id => $blog_pages );
    827840
    828841                        update_site_option( 'bp-pages', $bp_pages );
     
    9951008
    9961009                        // Update the DB version in the database
    997                         update_site_option( 'bp-db-version', constant( 'BP_DB_VERSION' ) );
     1010                        update_site_option( 'bp-db-version', $this->new_version );
    9981011                        delete_site_option( 'bp-core-db-version' );
    9991012
     
    11811194 */
    11821195function bp_core_update_add_admin_menu() {
    1183         global $bp, $bp_wizard;
     1196        global $bp_wizard;
    11841197
    11851198        // Only load this version of the menu if this is an upgrade or a new installation
    1186         if ( empty( $bp->maintenence_mode ) )
     1199        if ( empty( $bp_wizard->setup_type ) )
    11871200                return false;
    11881201
     
    11901203                return false;
    11911204
    1192         if ( '' == get_site_option( 'bp-db-version' ) && !(int)get_site_option( 'bp-core-db-version' ) && !$bp_wizard->is_network_activate )
     1205        if ( 'install' == $bp_wizard->setup_type )
    11931206                $status = __( 'Setup', 'buddypress' );
    11941207        else
     
    12781291 */
    12791292function bp_core_update_nag() {
    1280         global $bp, $pagenow;
     1293        global $bp_wizard, $pagenow;
     1294
     1295        if ( empty( $bp_wizard->setup_type ) )
     1296                return;
    12811297
    12821298        if ( !is_super_admin() )
     
    12881304        $url = bp_core_update_do_network_admin() ? network_admin_url( 'admin.php?page=bp-wizard' ) : admin_url( 'admin.php?page=bp-wizard' );
    12891305
    1290         switch( $bp->maintenence_mode ) {
     1306        switch( $bp_wizard->setup_type ) {
    12911307                case 'update':
    12921308                        $msg = sprintf( __( 'BuddyPress has been updated! Please run the <a href="%s">update wizard</a>.', 'buddypress' ), $url );
Note: See TracChangeset for help on using the changeset viewer.