Skip to content
This repository has been archived by the owner on Oct 3, 2019. It is now read-only.

Commit

Permalink
Updater:
Browse files Browse the repository at this point in the history
* Move bbp_is_deactivation() check out of bbPress class, and into bbpress-functions.php loader.
* Enables all functions and actions to run at deactivation time, allowing caps to be removed, etc...
* Re-enable network updater for capable users. Check if bbPress is active before running versioner.
* Introduce bbp_delete_rewrite_rules() to force a flush on the following page-load without priming rules on the current one.

git-svn-id: http://bbpress.svn.wordpress.org/branches/plugin@4198 9866e705-20ec-0310-96e7-cbb4277adcfb
  • Loading branch information
johnjamesjacoby committed Sep 4, 2012
1 parent cf6bd0a commit d5e1674
Show file tree
Hide file tree
Showing 6 changed files with 78 additions and 40 deletions.
16 changes: 10 additions & 6 deletions bbp-admin/bbp-actions.php
Expand Up @@ -63,17 +63,17 @@
add_action( 'bbp_admin_menu', 'bbp_admin_separator' ); add_action( 'bbp_admin_menu', 'bbp_admin_separator' );


// Activation // Activation
add_action( 'bbp_activation', 'bbp_add_options', 1 ); add_action( 'bbp_activation', 'bbp_add_caps' );
add_action( 'bbp_activation', 'flush_rewrite_rules' ); add_action( 'bbp_activation', 'bbp_delete_rewrite_rules' );


// Deactivation // Deactivation
add_action( 'bbp_deactivation', 'flush_rewrite_rules' ); add_action( 'bbp_deactivation', 'bbp_remove_caps' );
add_action( 'bbp_deactivation', 'bbp_deactivated' ); add_action( 'bbp_deactivation', 'bbp_delete_rewrite_rules' );
add_action( 'bbp_deactivation', 'bbp_deactivated' );


// New Site // New Site
add_action( 'bbp_new_site', 'bbp_add_options', 6 ); add_action( 'bbp_new_site', 'bbp_add_caps', 6 );
add_action( 'bbp_new_site', 'bbp_create_initial_content', 8 ); add_action( 'bbp_new_site', 'bbp_create_initial_content', 8 );
add_action( 'bbp_new_site', 'flush_rewrite_rules' );


// Contextual Helpers // Contextual Helpers
add_action( 'load-settings_page_bbpress', 'bbp_admin_settings_help' ); add_action( 'load-settings_page_bbpress', 'bbp_admin_settings_help' );
Expand All @@ -100,6 +100,10 @@
*/ */
function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) { function bbp_new_site( $blog_id, $user_id, $domain, $path, $site_id, $meta ) {


// Bail if plugin is not network activated
if ( ! is_plugin_active_for_network( bbpress()->basename ) )
return;

// Switch to the new blog // Switch to the new blog
switch_to_blog( $blog_id ); switch_to_blog( $blog_id );


Expand Down
47 changes: 38 additions & 9 deletions bbp-admin/bbp-admin.php
Expand Up @@ -229,6 +229,19 @@ public function admin_menus() {
array( $this, 'credits_screen' ) array( $this, 'credits_screen' )
); );
} }

// Bail if plugin is not network activated
if ( ! is_plugin_active_for_network( bbpress()->basename ) )
return;

add_submenu_page(
'index.php',
__( 'Update Forums', 'bbpress' ),
__( 'Update Forums', 'bbpress' ),
'manage_network',
'bbp-update',
array( $this, 'update_screen' )
);
} }


/** /**
Expand All @@ -238,6 +251,11 @@ public function admin_menus() {
* @uses add_submenu_page() To add the Update Forums page in Updates * @uses add_submenu_page() To add the Update Forums page in Updates
*/ */
public function network_admin_menus() { public function network_admin_menus() {

// Bail if plugin is not network activated
if ( ! is_plugin_active_for_network( bbpress()->basename ) )
return;

add_submenu_page( add_submenu_page(
'upgrade.php', 'upgrade.php',
__( 'Update Forums', 'bbpress' ), __( 'Update Forums', 'bbpress' ),
Expand Down Expand Up @@ -1183,15 +1201,13 @@ public static function update_screen() {


// Taking action // Taking action
switch ( $action ) { switch ( $action ) {
case 'bbpress-update' : case 'bbp-update' :

// Ensure proper version in the DB
bbp_version_bump();


?> // Run the full updater
bbp_version_updater(); ?>


<p><?php _e( 'All done!', 'bbpress' ); ?></p> <p><?php _e( 'All done!', 'bbpress' ); ?></p>
<a class="button" href="index.php?page=bbpress-update"><?php _e( 'Go Back', 'bbpress' ); ?></a> <a class="button" href="index.php?page=bbp-update"><?php _e( 'Go Back', 'bbpress' ); ?></a>


<?php <?php


Expand All @@ -1201,7 +1217,7 @@ public static function update_screen() {
default : ?> default : ?>


<p><?php _e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p> <p><?php _e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
<p><a class="button" href="index.php?page=bbpress-update&amp;action=bbpress-update"><?php _e( 'Update Forum', 'bbpress' ); ?></a></p> <p><a class="button" href="index.php?page=bbp-update&amp;action=bbp-update"><?php _e( 'Update Forum', 'bbpress' ); ?></a></p>


<?php break; <?php break;


Expand Down Expand Up @@ -1266,14 +1282,27 @@ public static function network_update_screen() {


// Get the response of the bbPress update on this site // Get the response of the bbPress update on this site
$response = wp_remote_get( $response = wp_remote_get(
trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbpress-update&step=bbpress-update', trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbp-update&action=bbp-update',
array( 'timeout' => 120, 'httpversion' => '1.1' ) array( 'timeout' => 30, 'httpversion' => '1.1' )
); );


// Site errored out, no response? // Site errored out, no response?
if ( is_wp_error( $response ) ) if ( is_wp_error( $response ) )
wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>', 'bbpress' ), $siteurl, $response->get_error_message() ) ); wp_die( sprintf( __( 'Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: <em>%2$s</em>', 'bbpress' ), $siteurl, $response->get_error_message() ) );


// Switch to the new blog
switch_to_blog( $details[ 'blog_id' ] );

$basename = bbpress()->basename;

// Run the updater on this site
if ( is_plugin_active_for_network( $basename ) || is_plugin_active( $basename ) ) {
bbp_version_updater();
}

// restore original blog
restore_current_blog();

// Do some actions to allow plugins to do things too // Do some actions to allow plugins to do things too
do_action( 'after_bbpress_upgrade', $response ); do_action( 'after_bbpress_upgrade', $response );
do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] ); do_action( 'bbp_upgrade_site', $details[ 'blog_id' ] );
Expand Down
10 changes: 10 additions & 0 deletions bbp-includes/bbp-core-functions.php
Expand Up @@ -432,3 +432,13 @@ function bbp_get_user_subscriptions_rewrite_id() {
function bbp_get_view_rewrite_id() { function bbp_get_view_rewrite_id() {
return bbpress()->view_id; return bbpress()->view_id;
} }

/**
* Delete a blogs rewrite rules, so that they are automatically rebuilt on
* the subsequent page load.
*
* @since bbPress (r4198)
*/
function bbp_delete_rewrite_rules() {
delete_option( 'rewrite_rules' );
}
35 changes: 15 additions & 20 deletions bbp-includes/bbp-core-update.php
Expand Up @@ -134,27 +134,18 @@ function bbp_version_bump() {
* *
* @since bbPress (r3419) * @since bbPress (r3419)
* *
* @uses bbp_version_updater()
* @uses bbp_version_bump() * @uses bbp_version_bump()
* @uses bbp_deactivation() * @uses flush_rewrite_rules()
* @uses bbp_activation()
*/ */
function bbp_setup_updater() { function bbp_setup_updater() {


// Are we running an outdated version of bbPress? // Bail if no update needed
if ( bbp_is_update() ) { if ( ! bbp_is_update() )

return;
// Call the automated updater
bbp_version_updater();

// Bump the version
bbp_version_bump();

// Run the deactivation function to wipe roles, caps, and rewrite rules
bbp_deactivation();


// Run the activation function to reset roles, caps, and rewrite rules // Call the automated updater
bbp_activation(); bbp_version_updater();
}
} }


/** /**
Expand Down Expand Up @@ -230,10 +221,6 @@ function bbp_version_updater() {
// Get the raw database version // Get the raw database version
$raw_db_version = (int) bbp_get_db_version_raw(); $raw_db_version = (int) bbp_get_db_version_raw();


// Bail if no database version exists
if ( empty( $raw_db_version ) )
return;

/** 2.0 Branch ************************************************************/ /** 2.0 Branch ************************************************************/


// 2.0, 2.0.1, 2.0.2, 2.0.3 // 2.0, 2.0.1, 2.0.2, 2.0.3
Expand Down Expand Up @@ -274,4 +261,12 @@ function bbp_version_updater() {
bbp_remove_caps(); bbp_remove_caps();
bbp_add_caps(); bbp_add_caps();
} }

/** All done! *************************************************************/

// Bump the version
bbp_version_bump();

// Delete rewrite rules to force a flush
bbp_delete_rewrite_rules();
} }
4 changes: 4 additions & 0 deletions bbp-includes/bbp-template-loader.php
Expand Up @@ -119,6 +119,10 @@ function bbp_template_include_theme_supports( $template = '' ) {
function bbp_load_theme_functions() { function bbp_load_theme_functions() {
global $pagenow; global $pagenow;


// If bbPress is being deactivated, do not load any more files
if ( bbp_is_deactivation() )
return;

if ( ! defined( 'WP_INSTALLING' ) || ( !empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) { if ( ! defined( 'WP_INSTALLING' ) || ( !empty( $pagenow ) && ( 'wp-activate.php' !== $pagenow ) ) ) {
bbp_locate_template( 'bbpress-functions.php', true ); bbp_locate_template( 'bbpress-functions.php', true );
} }
Expand Down
6 changes: 1 addition & 5 deletions bbpress.php
Expand Up @@ -174,7 +174,7 @@ private function setup_globals() {
/** Versions **********************************************************/ /** Versions **********************************************************/


$this->version = '2.1.2-bleeding-r4181'; // bbPress version $this->version = '2.1.2-bleeding-r4181'; // bbPress version
$this->db_version = '213'; // bbPress DB version $this->db_version = '214'; // bbPress DB version


/** Paths *************************************************************/ /** Paths *************************************************************/


Expand Down Expand Up @@ -271,10 +271,6 @@ private function includes() {
require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts require( $this->plugin_dir . 'bbp-includes/bbp-core-shortcodes.php' ); // Shortcodes for use with pages and posts
require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php' ); // Database updater require( $this->plugin_dir . 'bbp-includes/bbp-core-update.php' ); // Database updater


// If bbPress is being deactivated, do not load any more files
if ( bbp_is_deactivation( $this->basename ) )
return;

/** Templates *********************************************************/ /** Templates *********************************************************/


require( $this->plugin_dir . 'bbp-includes/bbp-template-functions.php' ); // Template functions require( $this->plugin_dir . 'bbp-includes/bbp-template-functions.php' ); // Template functions
Expand Down

0 comments on commit d5e1674

Please sign in to comment.