Skip to:
Content

bbPress.org

Changeset 3731


Ignore:
Timestamp:
02/16/2012 09:50:10 PM (14 years ago)
Author:
johnjamesjacoby
Message:

First pass at network updater. See #1725.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/plugin/bbp-admin/bbp-admin.php

    r3718 r3731  
    120120        // Add sample permalink filter
    121121        add_filter( 'post_type_link',     'bbp_filter_sample_permalink',        10, 4 );
     122
     123        /** Network Admin *****************************************************/
     124
     125        // Add menu item to settings menu
     126        add_action( 'network_admin_menu',  array( $this, 'network_admin_menus' ) );
     127
     128        /** Dependencies ******************************************************/
     129
     130        // Allow plugins to modify these actions
     131        do_action_ref_array( 'bbp_admin_loaded', array( &$this ) );
    122132    }
    123133
     
    129139     */
    130140    private function includes() {
    131 
    132         // Include the files
    133141        require( $this->admin_dir . 'bbp-tools.php'     );
    134142        require( $this->admin_dir . 'bbp-settings.php'  );
     
    163171
    164172    /**
    165      * Add the navigational menu elements
     173     * Add the admin menus
    166174     *
    167175     * @since bbPress (r2646)
     
    178186
    179187        // Forums settings
    180         add_options_page   ( __( 'Forums',  'bbpress' ), __( 'Forums',  'bbpress' ), 'manage_options', 'bbpress', 'bbp_admin_settings' );
     188        add_options_page(
     189            __( 'Forums',  'bbpress' ),
     190            __( 'Forums',  'bbpress' ),
     191            'manage_options',
     192            'bbpress',
     193            'bbp_admin_settings'
     194        );
     195
     196        // Update single forum
     197        add_dashboard_page(
     198            __( 'Update Forum', 'bbpress' ),
     199            __( 'Update Forum', 'bbpress' ),
     200            ( is_multisite() ? 'manage_network' : 'manage_options' ),
     201            'bbpress',
     202            array( $this, 'update_screen' )
     203        );
     204    }
     205
     206    /**
     207     * Add the network admin menus
     208     *
     209     * @since bbPress (r3689)
     210     * @uses add_submenu_page() To add the Update Forums page in Updates
     211     */
     212    public function network_admin_menus() {
     213        add_submenu_page(
     214            'upgrade.php',
     215            __( 'Update Forums', 'bbpress' ),
     216            __( 'Update Forums', 'bbpress' ),
     217            'manage_network',
     218            'bbpress',
     219            array( $this, 'network_update_screen' )
     220        );
    181221    }
    182222
     
    229269
    230270        // Allow global access setting
    231         if ( function_exists( 'wp_editor' ) ) {
    232             add_settings_field( '_bbp_use_wp_editor', __( 'Fancy Editor',  'bbpress' ), 'bbp_admin_setting_callback_use_wp_editor', 'bbpress', 'bbp_main' );
    233             register_setting  ( 'bbpress',            '_bbp_use_wp_editor',             'intval'                                                          );
    234         }
     271        add_settings_field( '_bbp_use_wp_editor', __( 'Fancy Editor',  'bbpress' ), 'bbp_admin_setting_callback_use_wp_editor', 'bbpress', 'bbp_main' );
     272        register_setting  ( 'bbpress',            '_bbp_use_wp_editor',             'intval'                                                          );
    235273
    236274        /** Per Page Section **************************************************/
     
    694732        // Load the admin CSS styling
    695733        wp_admin_css_color( 'bbpress', __( 'Green', 'bbpress' ), $css_file, array( '#222222', '#006600', '#deece1', '#6eb469' ) );
     734    }
     735
     736    /**
     737     * Update all bbPress forums across all sites
     738     *
     739     * @since bbPress (r3689)
     740     *
     741     * @global WPDB $wpdb
     742     * @uses get_blog_option()
     743     * @uses wp_remote_get()
     744     */
     745    public static function update_screen() {
     746
     747        // Get action
     748        $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
     749
     750        <div class="wrap">
     751            <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
     752            <h2><?php _e( 'Update Forum', 'bbpress' ); ?></h2>
     753
     754        <?php
     755
     756        // Taking action
     757        switch ( $action ) {
     758            case 'bbpress-update' :
     759
     760                // @todo more update stuff here, evaluate performance
     761
     762                // Remove roles and caps
     763                bbp_remove_roles();
     764                bbp_remove_caps();
     765
     766                // Make sure roles, capabilities, and options exist
     767                bbp_add_roles();
     768                bbp_add_caps();
     769                bbp_add_options();
     770
     771                // Ensure any new permalinks are created
     772                flush_rewrite_rules();
     773
     774                // Ensure proper version in the DB
     775                bbp_version_bump();
     776
     777                ?>
     778           
     779                <p><?php _e( 'All done!', 'bbpress' ); ?></p>
     780                <a class="button" href="index.php?page=bbpress"><?php _e( 'Go Back', 'bbpress' ); ?></a>
     781
     782                <?php
     783
     784                break;
     785
     786            case 'show' :
     787            default : ?>
     788
     789                <p><?php _e( 'You can update your forum through this page. Hit the link below to update.', 'bbpress' ); ?></p>
     790                <p><a class="button" href="index.php?page=bbpress&amp;action=bbpress-update"><?php _e( 'Update Forum', 'bbpress' ); ?></a></p>
     791
     792            <?php break;
     793
     794        } ?>
     795
     796        </div><?php
     797    }
     798
     799    /**
     800     * Update all bbPress forums across all sites
     801     *
     802     * @since bbPress (r3689)
     803     *
     804     * @global WPDB $wpdb
     805     * @uses get_blog_option()
     806     * @uses wp_remote_get()
     807     */
     808    public static function network_update_screen() {
     809        global $wpdb;
     810
     811        // Get action
     812        $action = isset( $_GET['action'] ) ? $_GET['action'] : ''; ?>
     813
     814        <div class="wrap">
     815            <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div>
     816            <h2><?php _e( 'Update Forums', 'bbpress' ); ?></h2>
     817
     818        <?php
     819
     820        // Taking action
     821        switch ( $action ) {
     822            case 'bbpress-update' :
     823
     824                // Site counter
     825                $n = isset( $_GET['n'] ) ? intval( $_GET['n'] ) : 0;
     826
     827                // Get blogs 5 at a time
     828                $blogs = $wpdb->get_results( "SELECT * FROM {$wpdb->blogs} WHERE site_id = '{$wpdb->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A );
     829
     830                // No blogs so all done!
     831                if ( empty( $blogs ) ) : ?>
     832
     833                    <p><?php _e( 'All done!', 'bbpress' ); ?></p>
     834                    <a class="button" href="update-core.php?page=bbpress"><?php _e( 'Go Back', 'bbpress' ); ?></a>
     835
     836                    <?php break; ?>
     837
     838                <?php
     839
     840                // Still have sites to loop through
     841                else : ?>
     842
     843                    <ul>
     844
     845                        <?php foreach ( (array) $blogs as $details ) :
     846
     847                            $siteurl = get_blog_option( $details['blog_id'], 'siteurl' ); ?>
     848
     849                            <li><?php echo $siteurl; ?></li>
     850
     851                            <?php
     852
     853                            // Get the response of the bbPress update on this site
     854                            $response = wp_remote_get(
     855                                trailingslashit( $siteurl ) . 'wp-admin/index.php?page=bbpress&step=bbpress-update',
     856                                array( 'timeout' => 120, 'httpversion' => '1.1' )
     857                            );
     858
     859                            // Site errored out, no response?
     860                            if ( is_wp_error( $response ) )
     861                                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() ) );
     862
     863                            // Do some actions to allow plugins to do things too
     864                            do_action( 'after_bbpress_upgrade', $response             );
     865                            do_action( 'bbp_upgrade_site',      $details[ 'blog_id' ] );
     866
     867                        endforeach; ?>
     868
     869                    </ul>
     870
     871                    <p>
     872                        <?php _e( 'If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress' ); ?>
     873                        <a class="button" href="update-core.php?page=bbpress&amp;action=bbpress-update&amp;n=<?php echo ( $n + 5 ); ?>"><?php _e( 'Next Forums', 'bbpress' ); ?></a>
     874                    </p>
     875                    <script type='text/javascript'>
     876                        <!--
     877                        function nextpage() {
     878                            location.href = 'update-core.php?page=bbpress&action=bbpress-update&n=<?php echo ( $n + 5 ) ?>';
     879                        }
     880                        setTimeout( 'nextpage()', 250 );
     881                        //-->
     882                    </script><?php
     883
     884                endif;
     885
     886                break;
     887
     888            case 'show' :
     889            default : ?>
     890
     891                <p><?php _e( 'You can update all the forums on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.', 'bbpress' ); ?></p>
     892                <p><a class="button" href="update-core.php?page=bbpress&amp;action=bbpress-update"><?php _e( 'Update Forums', 'bbpress' ); ?></a></p>
     893
     894            <?php break;
     895
     896        } ?>
     897
     898        </div><?php
    696899    }
    697900}
Note: See TracChangeset for help on using the changeset viewer.