Skip to:
Content

BuddyPress.org

Changeset 5528


Ignore:
Timestamp:
12/12/2011 10:42:54 PM (14 years ago)
Author:
djpaul
Message:

Handle errors better with activity admin; don't bail out, keep on truckin'. Fixes #3845

Location:
trunk/bp-activity
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/bp-activity/admin/css/admin.css

    r5498 r5528  
    1 #wp-bp-activities-wrap{padding:5px 0;}#bp-activities{height:120px;}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0;}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center;}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center;}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top;}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px;}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0;}#bp_activity_action h3,#bp_activity_content h3{cursor:auto;}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white;}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px;}#bp_activity_link input{width:99%;}#bp-activities-primaryid{margin-bottom:1em;}
     1#wp-bp-activities-wrap{padding:5px 0;}#bp-activities{height:120px;}#bp-replyhead{font-size:1em;line-height:1.4em;margin:0;}#bp-replysubmit{margin:0;padding:0 0 3px;text-align:center;}#bp-replysubmit .error{color:red;line-height:21px;text-align:center;vertical-align:center;}#bp-replysubmit img.waiting{float:right;padding:4px 10px 0;vertical-align:top;}#bp-activities-form .column-response img{float:left;margin-right:10px;margin-top:1px;}.activity-errors{list-style-type:disc;margin-left:2em;}#bp_activity_action div.inside,#bp_activity_content div.inside{line-height:0;}#bp_activity_action h3,#bp_activity_content h3{cursor:auto;}#bp_activity_action td.mceIframeContainer,#bp_activity_content td.mceIframeContainer{background-color:white;}#post-body #bp-activities-action_resize,#post-body #bp-activities-content_resize{position:inherit;margin-top:-2px;}#bp_activity_link input{width:99%;}#bp-activities-primaryid{margin-bottom:1em;}
  • trunk/bp-activity/admin/css/admin.dev.css

    r5498 r5528  
    3131    margin-top: 1px;
    3232}
     33.activity-errors {
     34    list-style-type: disc;
     35    margin-left: 2em;
     36}
    3337
    3438#bp_activity_action div.inside,
  • trunk/bp-activity/bp-activity-admin.php

    r5513 r5528  
    282282        $deleted = $spammed = $unspammed = 0;
    283283
    284         // Store any error that occurs when updating the database item
    285         $error = 0;
     284        // Store any errors that occurs when updating the database items
     285        $errors = array();
    286286
    287287        // "We'd like to shoot the monster, could you move, please?"
     
    293293            // Get the activity from the database
    294294            $activity = new BP_Activity_Activity( $activity_id );
    295             if ( empty( $activity->component ) )
     295            if ( empty( $activity->component ) ) {
     296                $errors[] = $activity_id;
    296297                continue;
     298            }
    297299
    298300            switch ( $doaction ) {
     
    311313
    312314                    // Check for any error during activity save
    313                     if ( ! $result ) {
    314                         $error = $activity->id;
    315                         break;
    316                     }
    317 
    318                     $unspammed++;
     315                    if ( ! $result )
     316                        $errors[] = $activity->id;
     317                    else
     318                        $unspammed++;
    319319                    break;
    320320
     
    324324
    325325                    // Check for any error during activity save
    326                     if ( ! $result ) {
    327                         $error = $activity->id;
    328                         break;
    329                     }
    330 
    331                     $spammed++;
     326                    if ( ! $result )
     327                        $errors[] = $activity->id;
     328                    else
     329                        $spammed++;
    332330                    break;
    333331
     
    336334            }
    337335
    338             // If an error occured, don't bother looking at the other activities. Bail out of the foreach.
    339             if ( $error )
    340                 break;
    341 
    342336            // Release memory
    343337            unset( $activity );
     
    345339
    346340        // Call actions for plugins to do something before we redirect
    347         do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $error ), $redirect_to, $activity_ids );
     341        do_action( 'bp_activity_admin_action_after', array( $spammed, $unspammed, $deleted, $errors ), $redirect_to, $activity_ids );
    348342
    349343        // Add arguments to the redirect URL so that on page reload, we can easily display what we've just done.
     
    358352
    359353        // If an error occured, pass back the activity ID that failed
    360         if ( $error )
    361             $redirect_to = add_query_arg( 'error', (int) $error, $redirect_to );
     354        if ( ! empty( $errors ) )
     355            $redirect_to = add_query_arg( 'error', implode ( ',', array_map( 'absint', $errors ) ), $redirect_to );
    362356
    363357        // Redirect
     
    769763    // If the user has just made a change to an activity item, build status messages
    770764    if ( ! empty( $_REQUEST['deleted'] ) || ! empty( $_REQUEST['spammed'] ) || ! empty( $_REQUEST['unspammed'] ) || ! empty( $_REQUEST['error'] ) || ! empty( $_REQUEST['updated'] ) ) {
    771         $deleted   = !empty( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
    772         $error     = !empty( $_REQUEST['error']     ) ? (int) $_REQUEST['error']     : 0;
    773         $spammed   = !empty( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
    774         $unspammed = !empty( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
    775         $updated   = !empty( $_REQUEST['updated']   ) ? (int) $_REQUEST['updated']   : 0;
     765        $deleted   = ! empty( $_REQUEST['deleted']   ) ? (int) $_REQUEST['deleted']   : 0;
     766        $errors    = ! empty( $_REQUEST['error']     ) ? $_REQUEST['error']           : '';
     767        $spammed   = ! empty( $_REQUEST['spammed']   ) ? (int) $_REQUEST['spammed']   : 0;
     768        $unspammed = ! empty( $_REQUEST['unspammed'] ) ? (int) $_REQUEST['unspammed'] : 0;
     769        $updated   = ! empty( $_REQUEST['updated']   ) ? (int) $_REQUEST['updated']   : 0;
     770
     771        $errors = array_map( 'absint', explode( ',', $errors ) );
    776772
    777773        if ( $deleted > 0 )
    778774            $messages[] = sprintf( _n( '%s activity was permanently deleted.', '%s activities were permanently deleted.', $deleted, 'buddypress' ), number_format_i18n( $deleted ) );
    779775
    780         if ( $error > 0 )
    781             $messages[] = sprintf( __( 'An error occurred when updating Activity ID #%s.', 'buddypress' ), number_format_i18n( $error ) );
     776        if ( ! empty( $errors ) ) {
     777            if ( 1 == count( $errors ) ) {
     778                $error_msg = __( 'An error occurred when updating activity ID #%s.', 'buddypress' );
     779
     780            } else {
     781                $error_msg  = __( 'Errors occurred when updating activity IDs:', 'buddypress' );
     782                $error_msg .= '<ul class="activity-errors">';
     783
     784                // Display each error as a list item
     785                foreach ( $errors as $error ) {
     786                    // Translators: This is a bulleted list of item IDs
     787                    $error_msg .= '<li>' . sprintf( __( '#%s', 'buddypress' ), number_format_i18n( $error ) ) . '</li>';
     788                }
     789
     790                $error_msg  .= '</ul>';
     791                $messages[] = $error_msg;
     792            }
     793        }
    782794
    783795        if ( $spammed > 0 )
    784             $messages[] = sprintf( _n( '%s activity marked as spam.', '%s activities marked as spam.', $spammed, 'buddypress' ), number_format_i18n( $spammed ) );
     796            $messages[] = sprintf( _n( '%s activity has been marked as spam.', '%s activities have been marked as spam.', $spammed, 'buddypress' ), number_format_i18n( $spammed ) );
    785797
    786798        if ( $unspammed > 0 )
    787             $messages[] = sprintf( _n( '%s activity restored from the spam.', '%s activities restored from the spam.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
     799            $messages[] = sprintf( _n( '%s activity has been restored from the spam.', '%s activities have been restored from the spam.', $unspammed, 'buddypress' ), number_format_i18n( $unspammed ) );
    788800
    789801        if ( $updated > 0 )
     
    814826        <?php // If the user has just made a change to an activity item, display the status messages ?>
    815827        <?php if ( !empty( $messages ) ) : ?>
    816             <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['error'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
     828            <div id="moderated" class="<?php echo ( ! empty( $_REQUEST['errors'] ) ) ? 'error' : 'updated'; ?>"><p><?php echo implode( "<br/>\n", $messages ); ?></p></div>
    817829        <?php endif; ?>
    818830
Note: See TracChangeset for help on using the changeset viewer.