Making WordPress.org

Changeset 8905


Ignore:
Timestamp:
06/03/2019 03:21:30 AM (5 years ago)
Author:
dd32
Message:

Trac Notifications: Handle API failures in the https://make.wordpress.org/core/components/ UI.

Currently when Trac fails to respond in a reasonable timeframe it generates a PHP Warning and the UI is slightly off.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/trac-notifications/trac-components.php

    r7664 r8905  
    400400
    401401        $followers = $this->api->get_component_followers( $post->post_title );
    402         $followers = "'" . implode( "', '", esc_sql( $followers ) ) . "'";
    403         $followers = $wpdb->get_results( "SELECT user_login, user_nicename, user_email FROM $wpdb->users WHERE user_login IN ($followers)" );
     402        if ( $followers ) {
     403            $followers = "'" . implode( "', '", esc_sql( $followers ) ) . "'";
     404            $followers = $wpdb->get_results( "SELECT user_login, user_nicename, user_email FROM $wpdb->users WHERE user_login IN ($followers)" );
     405        }
    404406        if ( $followers ) {
    405407            echo 'Contributors following this component:';
     
    484486
    485487        $history = $this->api->get_component_history( $component, self::last_x_days );
     488        if ( ! $history ) {
     489            $history = array( 'change' => 0 ); // Incorrect, but allows full page render.
     490        }
     491
    486492        $direction = '';
    487493        if ( $history['change'] > 0 ) {
     
    555561
    556562        $tickets_by_type = $this->api->get_ticket_counts_for_component( $component );
     563        if ( ! $tickets_by_type ) {
     564            $tickets_by_type = array( 'defect (bug)' => 0 ); // Incorrect, but allows page render
     565        }
    557566
    558567        $count = array_sum( $tickets_by_type );
     
    638647        if ( in_array( 'component', $topics ) ) {
    639648            $components = $this->api->get_components();
    640             foreach ( $components as $component ) {
    641                 echo '<option value="component/' . esc_attr( rawurlencode( $component ) ) . '">' . esc_html( $component ) . "</option>";
     649            if ( $components ) {
     650                foreach ( $components as $component ) {
     651                    echo '<option value="component/' . esc_attr( rawurlencode( $component ) ) . '">' . esc_html( $component ) . "</option>";
     652                }
    642653            }
    643654        }
     
    652663        }
    653664
     665        $component = $post->post_title;
     666        $history = $this->api->get_component_history( $component );
     667
     668        if ( ! $history ) {
     669            return;
     670        }
     671
    654672        static $once = true;
    655673        if ( $once ) {
     
    657675            echo '<thead><tr><td>Component</td><td>Tickets</td><td>7 Days</td><td>0&nbsp;Replies</td><td>Maintainers</td></tr></thead>';
    658676        }
    659 
    660         $component = $post->post_title;
    661         $history = $this->api->get_component_history( $component );
    662677
    663678        $arrow = '';
Note: See TracChangeset for help on using the changeset viewer.