Making WordPress.org

Changeset 13107


Ignore:
Timestamp:
01/15/2024 02:40:00 AM (15 months ago)
Author:
dd32
Message:

Plugin Directory: Bin: Bounced Emails: If all plugins associated with the account are already closed, just close the Helpscout ticket. The plugin probably had other bounces that have already closed the plugins.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/bin/bounced-emails.php

    r12762 r13107  
    6161if ( 'live' == OPERATION_MODE ) {
    6262    echo "Running in live mode. Changes will be made.\nProceeding in 10s...\n";
     63    sleep( 10 );
    6364} else {
    64     echo "Running in dry-run mode. No changes will be made. Pass --doit parameter to make changes.\nProceeding in 10s...\n";
    65 }
    66 sleep( 10 );
     65    echo "Running in dry-run mode. No changes will be made. Pass --doit parameter to make changes.\n";
     66}
     67
    6768
    6869// Load the HelpScout API helper methods.
     
    161162    'closed'         => 0,
    162163    'revoked-commit' => 0,
     164    'hs-closed'      => 0,
    163165];
    164166
     
    174176*/
    175177];
     178$just_close_it = []; // The HS tickets to just close.
    176179
    177180foreach ( get_bounces()->_embedded->conversations as $bounce ) {
     
    191194        },
    192195        $slugs
     196    );
     197
     198    $closed_plugins = array_filter(
     199        $plugins,
     200        function( $plugin ) {
     201            return 'closed' === get_post_status( $plugin ) || 'disabled' === get_post_status( $plugin );
     202        }
    193203    );
    194204
     
    219229    );
    220230
    221     if ( ! $email || ! $user || ! $slugs || ! $plugins ) {
     231    if ( ! $email || ! $user || ! $slugs || ( ! $plugins && ! $closed_plugins ) ) {
    222232        echo "\tNo user or plugins found.\n";
    223233        $stats['error']++;
     
    231241    echo "\tSingular committer (or owns): " . implode( ', ', wp_list_pluck( $single_committer_plugins, 'post_name' ) ) . "\n";
    232242    echo "\tJust a committer: " . implode( ', ', wp_list_pluck( $multiple_committer_plugins, 'post_name' ) ) . "\n";
     243    echo "\tClosed plugins: " . implode( ', ', wp_list_pluck( $closed_plugins, 'post_name' ) ) . "\n";
    233244
    234245    echo "\tBounce Message:\n\t\t> " . ( str_replace( "\n", "\n\t\t> ", $bounce_message ) ?: 'Unable to determine bounce reason' ) . "\n";
     
    239250        $actions_to_take[ $plugin->ID ]['id'][]  = $bounce->id;
    240251        $actions_to_take[ $plugin->ID ]['users'][ $user->ID ] = $bounce_message;
     252    }
     253
     254    if ( ! $plugins && $closed_plugins ) {
     255        $just_close_it[] = $bounce->id;
    241256    }
    242257
     
    394409}
    395410
     411// Close those HS tickets.
     412foreach ( $just_close_it as $hs_id ) {
     413    $stats['hs-closed']++;
     414
     415    echo "Marking https://secure.helpscout.net/conversation/{$hs_id} as closed as all plugins are closed.\n";
     416
     417    if ( 'live' == OPERATION_MODE ) {
     418        HelpScout::instance()->api(
     419            '/v2/conversations/' . $hs_id,
     420            [
     421                'op'    => 'replace',
     422                'path'  => '/status',
     423                'value' => 'closed',
     424            ],
     425            'PATCH'
     426        );
     427    }
     428}
     429
    396430echo "\nAll Done! Stats:\n";
    397431var_dump( $stats );
Note: See TracChangeset for help on using the changeset viewer.