Skip to:
Content

bbPress.org

Changeset 6681


Ignore:
Timestamp:
09/07/2017 08:24:05 AM (9 years ago)
Author:
johnjamesjacoby
Message:

Converter: progress bars and percentages.

This change incorporates 2 horizontal bars in the importer header area. One indicates how far the current step has progressed, and the other indicates total progress. Pretty sweet.

Trunk, for 2.6.

Location:
trunk/src
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bbpress.php

    r6677 r6681  
    204204                /** Versions **********************************************************/
    205205
    206                 $this->version    = '2.6-rc-6677';
     206                $this->version    = '2.6-rc-6682';
    207207                $this->db_version = '262';
    208208
  • trunk/src/includes/admin/assets/css/admin.css

    r6677 r6681  
    429429/* Converter */
    430430
     431#bbp-converter-monitor h2 {
     432        position: relative;
     433}
     434
    431435#bbp-converter-monitor .inside {
    432436        margin-bottom: 0;
    … …  
    468472        text-align: right;
    469473        font-weight: 600;
     474}
     475
     476div.bbp-converter-log .output {
     477        margin: 0 5px;
     478}
     479
     480div.bbp-converter-log .mini-step {
     481        padding: 3px 5px;
     482        vertical-align: middle;
     483        font-size: 8px;
     484        font-weight: 600;
     485        border-radius: 6px;
     486        background-color: #aaa;
     487        color: white;
     488}
     489
     490#bbp-converter-monitor .bbp-progress-bar {
     491        position: absolute;
     492        left: 0;
     493        height: 1px;
     494        width: 0;
     495        background-color: #00b9eb;
     496        transition-property: width;
     497        transition-timing-function: ease-out;
     498        transition-duration: 1s;
     499}
     500
     501#bbp-converter-monitor #bbp-converter-step-percentage {
     502        bottom: 1px;
     503}
     504
     505#bbp-converter-monitor #bbp-converter-total-percentage {
     506        bottom: 0;
    470507}
    471508
  • trunk/src/includes/admin/assets/js/converter.js

    r6677 r6681  
    1212                settings = $( '#bbp-converter-settings' ),
    1313                password = $( '#_bbp_converter_db_pass' ),
    14                 toggle   = $( '.bbp-db-pass-toggle'     );
     14                toggle   = $( '.bbp-db-pass-toggle'     ),
     15                step_p   = $( '#bbp-converter-step-percentage'  ),
     16                total_p  = $( '#bbp-converter-total-percentage' );
    1517
    1618        /**
    … …  
    156158                // Do the step
    157159                bbp_converter_log( data.progress );
     160                bbp_converter_percentages( data.step_percent, data.total_percent );
    158161                bbp_converter_status( data );
    159162                bbp_converter_wait();
    … …  
    318321                message.prepend( text );
    319322        }
     323
     324        /**
     325         * Prepend some text to the import monitor
     326         *
     327         * @since 2.6.0 bbPress (r6470)
     328         *
     329         * @returns {void}
     330         */
     331        function bbp_converter_percentages( step_percent, total_percent ) {
     332                step_p.width( step_percent + '%' );
     333                total_p.width( total_percent + '%' );
     334        }
    320335} );
  • trunk/src/includes/admin/classes/class-bbp-converter-base.php

    r6679 r6681  
    414414                // We have a $from_tablename, so we want to get some data to convert
    415415                if ( ! empty( $from_tablename ) ) {
     416
     417                        // Update rows
     418                        $this->count_rows_by_table( "{$this->opdb->prefix}{$from_tablename}" );
    416419
    417420                        // Get some data from the old forums
    … …  
    663666                        : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_forum_parent_id' );
    664667
    665                 foreach ( $this->get_results( $query ) as $row ) {
     668                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    666669                        $parent_id = $this->callback_forumid( $row->meta_value );
    667670                        $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_parent = %d WHERE ID = %d LIMIT 1", $parent_id, $row->value_id ) );
    … …  
    683686                        : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'sticky' );
    684687
    685                 foreach ( $this->get_results( $query ) as $row ) {
     688                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    686689                        bbp_stick_topic( $row->value_id );
    687690                        $has_update = true;
    … …  
    702705                        : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_sticky_status_id', 'super-sticky' );
    703706
    704                 foreach ( $this->get_results( $query ) as $row ) {
     707                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    705708                        $super = true;
    706709                        bbp_stick_topic( $row->value_id, $super );
    … …  
    722725                        : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value = %s LIMIT {$start}, {$this->max_rows}", '_bbp_old_closed_status_id', 'closed' );
    723726
    724                 foreach ( $this->get_results( $query ) as $row ) {
     727                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    725728                        bbp_close_topic( $row->value_id );
    726729                        $has_update = true;
    … …  
    741744                        : $this->wpdb->prepare( "SELECT post_id AS value_id, meta_value FROM {$this->wpdb->postmeta} WHERE meta_key = %s AND meta_value > 0 LIMIT {$start}, {$this->max_rows}", '_bbp_old_reply_to_id' );
    742745
    743                 foreach ( $this->get_results( $query ) as $row ) {
     746                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    744747                        $reply_to = $this->callback_reply_to( $row->meta_value );
    745748                        $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->postmeta} SET meta_value = %s WHERE meta_key = %s AND post_id = %d LIMIT 1", $reply_to, '_bbp_reply_to', $row->value_id ) );
    … …  
    777780                }
    778781
    779                 foreach ( $this->get_results( $query ) as $row ) {
     782                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    780783                        $anonymous_topic_author_id = 0;
    781784                        $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_topic_author_id, $row->topic_id ) );
    … …  
    816819                }
    817820
    818                 foreach ( $this->get_results( $query ) as $row ) {
     821                foreach ( $this->count_rows_by_results( $query ) as $row ) {
    819822                        $anonymous_reply_author_id = 0;
    820823                        $this->query( $this->wpdb->prepare( "UPDATE {$this->wpdb->posts} SET post_author = %d WHERE ID = %d LIMIT 1", $anonymous_reply_author_id, $row->reply_id ) );
    … …  
    891894
    892895                if ( ! empty( $converted ) ) {
    893 
    894896                        foreach ( $converted as $value ) {
    895897                                if ( is_serialized( $value['meta_value'] ) ) {
    … …  
    990992        }
    991993
     994        /**
     995         * Update the number of rows in the current step
     996         *
     997         * @since 2.6.0 bbPress (r6637)
     998         *
     999         * @param string $query The literal MySQL query
     1000         * @return bool
     1001         */
     1002        private function count_rows_by_results( $query = '' ) {
     1003                $results = $this->get_results( $query );
     1004
     1005                update_option( '_bbp_converter_rows_in_step', count( $results ) );
     1006
     1007                return $results;
     1008        }
     1009
     1010        /**
     1011         * Update the number of rows in the current step
     1012         *
     1013         * @since 2.6.0 bbPress (r6637)
     1014         *
     1015         * @param string $table_name The literal MySQL query
     1016         * @return bool
     1017         */
     1018        private function count_rows_by_table( $table_name = '' ) {
     1019                $count = (int) $this->opdb->get_var( "SELECT COUNT(*) FROM {$table_name}" );
     1020
     1021                return update_option( '_bbp_converter_rows_in_step', $count );
     1022        }
     1023
    9921024        /** Callbacks *************************************************************/
    9931025
  • trunk/src/includes/admin/classes/class-bbp-converter.php

    r6666 r6681  
    4343         */
    4444        public $max_steps = 17;
     45
     46        /**
     47         * @var int Number of rows in the current step
     48         */
     49        public $rows_in_step = 0;
     50
     51        /**
     52         * @var int Percent complete of current step
     53         */
     54        public $step_percentage = 0;
     55
     56        /**
     57         * @var int Percent complete of all step
     58         */
     59        public $total_percentage = 0;
    4560
    4661        /**
    … …  
    133148                        // UI State
    134149                        'state' => array(
    135                                 'delay'   => (int)  get_option( '_bbp_converter_delay_time', 2 ),
    136                                 'started' => (bool) get_option( '_bbp_converter_step',       0 ),
    137                                 'running' => false,
    138                                 'status'  => false
     150                                'delay'         => (int)  get_option( '_bbp_converter_delay_time', 2 ),
     151                                'started'       => (bool) get_option( '_bbp_converter_step',       0 ),
     152                                'running'       => false,
     153                                'status'        => false,
     154                                'step_percent'  => $this->step_percentage,
     155                                'total_percent' => $this->total_percentage
    139156                        ),
    140157
    … …  
    195212        private function converter_response( $output = '' ) {
    196213
     214                // Sanitize output
     215                $output = wp_kses_data( $output );
     216
    197217                // Maybe prepend the step
    198                 $output = ! empty( $this->step )
    199                         ? sprintf( '<span class="step">%s:</span> %s', $this->step, $output )
     218                $progress = ! empty( $this->step )
     219                        ? sprintf( '<span class="step">%s.</span><span class="output">%s</span><span class="mini-step">%s</span>', $this->step, $output, $this->step_percentage . '%' )
    200220                        : $output;
    201221
    202222                // Output
    203223                wp_send_json_success( array(
    204                         'query'        => get_option( '_bbp_converter_query', '' ),
    205                         'current_step' => $this->step,
    206                         'final_step'   => $this->max_steps,
    207                         'progress'     => $output
     224                        'query'         => get_option( '_bbp_converter_query', '' ),
     225                        'current_step'  => $this->step,
     226                        'final_step'    => $this->max_steps,
     227                        'rows_in_step'  => $this->rows_in_step,
     228                        'step_percent'  => $this->step_percentage,
     229                        'total_percent' => $this->total_percentage,
     230                        'progress'      => $progress
    208231                ) );
    209232        }
    … …  
    232255                // Save step and count so that it can be restarted.
    233256                if ( ! get_option( '_bbp_converter_step' ) || ! empty( $_POST['_bbp_converter_restart'] ) ) {
    234                         $this->step  = 1;
    235                         $this->start = 0;
     257                        $this->step             = 1;
     258                        $this->start            = 0;
     259                        $this->step_percentage  = 0;
     260                        $this->total_percentage = 0;
     261                        $this->rows_in_step     = 0;
    236262                        $this->maybe_update_options();
    237263                }
    … …  
    249275
    250276                        // Step & Start
    251                         '_bbp_converter_step'  => $this->step,
    252                         '_bbp_converter_start' => $this->start,
     277                        '_bbp_converter_step'         => $this->step,
     278                        '_bbp_converter_start'        => $this->start,
     279                        '_bbp_converter_rows_in_step' => $this->rows_in_step,
    253280
    254281                        // Halt
    … …  
    317344
    318345                // Set starting point & rows
    319                 $this->step     = (int) get_option( '_bbp_converter_step',  1   );
    320                 $this->start    = (int) get_option( '_bbp_converter_start', 0   );
    321                 $this->rows     = (int) get_option( '_bbp_converter_rows',  100 );
     346                $this->step         = (int) get_option( '_bbp_converter_step',         1   );
     347                $this->start        = (int) get_option( '_bbp_converter_start',        0   );
     348                $this->rows         = (int) get_option( '_bbp_converter_rows',         100 );
     349                $this->rows_in_step = (int) get_option( '_bbp_converter_rows_in_step', 0   );
    322350
    323351                // Set boundaries
    324                 $this->max      = ( $this->start + $this->rows ) - 1;
     352                $this->max          = ( $this->start + $this->rows ) - 1;
    325353
    326354                // Set platform
    327                 $this->platform = get_option( '_bbp_converter_platform' );
     355                $this->platform     = get_option( '_bbp_converter_platform' );
     356
     357                // Total percentage
     358                $this->total_percentage = round( ( $this->step / $this->max_steps ) * 100, 2 );
     359
     360                // Total mini steps
     361                if ( $this->rows_in_step > 0 ) {
     362                        $total_mini_steps      = ceil( $this->rows_in_step / $this->rows );
     363                        $current_mini_step     = ceil( $this->start        / $this->rows );
     364                        $this->step_percentage = round( ( $current_mini_step / $total_mini_steps ) * 100, 2 );
     365                } else {
     366                        $this->step_percentage = 0;
     367                }
    328368
    329369                // Maybe include the appropriate converter.
    … …  
    355395         */
    356396        private function reset() {
    357                 update_option( '_bbp_converter_step',  0  );
    358                 update_option( '_bbp_converter_start', 0  );
    359                 update_option( '_bbp_converter_query', '' );
     397                update_option( '_bbp_converter_step',         0  );
     398                update_option( '_bbp_converter_start',        0  );
     399                update_option( '_bbp_converter_rows_in_step', 0  );
     400                update_option( '_bbp_converter_query',        '' );
    360401        }
    361402
    … …  
    376417
    377418                // Update step and start at 0
    378                 update_option( '_bbp_converter_step',  $step );
    379                 update_option( '_bbp_converter_start', 0     );
     419                update_option( '_bbp_converter_step',         $step );
     420                update_option( '_bbp_converter_start',        0     );
     421                update_option( '_bbp_converter_rows_in_step', 0     );
    380422        }
    381423
    … …  
    425467                        } else {
    426468                                $this->bump_start();
    427                                 $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     469                                $this->converter_response( sprintf( esc_html__( 'Deleting previously converted data (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step) );
    428470                        }
    429471
    … …  
    451493                        } else {
    452494                                $this->bump_start();
    453                                 $this->converter_response( sprintf(  esc_html__( 'Converting users (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     495                                $this->converter_response( sprintf(  esc_html__( 'Converting users (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    454496                        }
    455497                } else {
    … …  
    474516                        } else {
    475517                                $this->bump_start();
    476                                 $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     518                                $this->converter_response( sprintf( esc_html__( 'Delete default WordPress user passwords (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    477519                        }
    478520                } else {
    … …  
    496538                } else {
    497539                        $this->bump_start();
    498                         $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     540                        $this->converter_response( sprintf( esc_html__( 'Converting forums (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    499541                }
    500542        }
    … …  
    514556                } else {
    515557                        $this->bump_start();
    516                         $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     558                        $this->converter_response( sprintf( esc_html__( 'Calculating forum hierarchy (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    517559                }
    518560        }
    … …  
    532574                } else {
    533575                        $this->bump_start();
    534                         $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     576                        $this->converter_response( sprintf( esc_html__( 'Converting forum subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    535577                }
    536578        }
    … …  
    550592                } else {
    551593                        $this->bump_start();
    552                         $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     594                        $this->converter_response( sprintf( esc_html__( 'Converting topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    553595                }
    554596        }
    … …  
    568610                } else {
    569611                        $this->bump_start();
    570                         $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     612                        $this->converter_response( sprintf( esc_html__( 'Converting anonymous topic authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    571613                }
    572614        }
    … …  
    586628                } else {
    587629                        $this->bump_start();
    588                         $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     630                        $this->converter_response( sprintf( esc_html__( 'Calculating topic stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    589631                }
    590632        }
    … …  
    604646                } else {
    605647                        $this->bump_start();
    606                         $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     648                        $this->converter_response( sprintf( esc_html__( 'Calculating topic super stickies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    607649                }
    608650        }
    … …  
    622664                } else {
    623665                        $this->bump_start();
    624                         $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     666                        $this->converter_response( sprintf( esc_html__( 'Calculating closed topics (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    625667                }
    626668        }
    … …  
    640682                } else {
    641683                        $this->bump_start();
    642                         $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     684                        $this->converter_response( sprintf( esc_html__( 'Converting topic tags (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    643685                }
    644686        }
    … …  
    658700                } else {
    659701                        $this->bump_start();
    660                         $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     702                        $this->converter_response( sprintf( esc_html__( 'Converting topic subscriptions (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    661703                }
    662704        }
    … …  
    676718                } else {
    677719                        $this->bump_start();
    678                         $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     720                        $this->converter_response( sprintf( esc_html__( 'Converting favorites (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    679721                }
    680722        }
    … …  
    694736                } else {
    695737                        $this->bump_start();
    696                         $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     738                        $this->converter_response( sprintf( esc_html__( 'Converting replies (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    697739                }
    698740        }
    … …  
    712754                } else {
    713755                        $this->bump_start();
    714                         $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     756                        $this->converter_response( sprintf( esc_html__( 'Converting anonymous reply authors (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    715757                }
    716758        }
    … …  
    730772                } else {
    731773                        $this->bump_start();
    732                         $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s - %2$s)', 'bbpress' ), $this->start, $this->max ) );
     774                        $this->converter_response( sprintf( esc_html__( 'Calculating threaded replies parents (%1$s through %2$s of %3$s)', 'bbpress' ), $this->start, $this->max, $this->rows_in_step ) );
    733775                }
    734776        }
  • trunk/src/includes/admin/settings.php

    r6678 r6681  
    18061806                                                                <span><?php esc_html_e( 'Import Monitor', 'bbpress' ); ?></span>
    18071807                                                                <span id="bbp-converter-status"><?php echo esc_html( $status_text ); ?></span>
     1808                                                                <span id="bbp-converter-step-percentage" class="bbp-progress-bar"></span>
     1809                                                                <span id="bbp-converter-total-percentage" class="bbp-progress-bar"></span>
    18081810                                                        </h2>
    18091811                                                        <div class="inside">
Note: See TracChangeset for help on using the changeset viewer.