Making WordPress.org


Ignore:
Timestamp:
03/06/2024 06:19:50 AM (2 years ago)
Author:
dd32
Message:

Plugin Directory: Support Threads: When a plugin has no threads in the last two months, reset the threads in the last 2 months meta values to 0.

Fixes #7506.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-plugin-support-resolved.php

    r9284 r13287  
    3232                $wpdb->set_blog_id( WPORG_SUPPORT_FORUMS_BLOGID );
    3333                // phpcs:ignore WordPress.VIP.DirectDatabaseQuery
    34                 $results = $wpdb->get_results( $wpdb->prepare( "SELECT t.slug as plugin_slug, meta_value as resolved, count(*) as topic_count
    35 FROM {$wpdb->posts} p
    36         JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id AND pm.meta_key = 'topic_resolved')
    37         JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)
    38         JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'topic-plugin')
    39         JOIN {$wpdb->terms} t ON (tt.term_id = t.term_id)
    40 WHERE
    41         post_type = 'topic' AND
    42         post_status = 'publish' AND
    43         post_parent = (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'forum' AND post_name = 'plugins-and-hacks') AND
    44         post_date >= %s
    45 
    46 GROUP BY t.slug, meta_value", $time_limit ) );
     34                $results = $wpdb->get_results( $wpdb->prepare(
     35                        "SELECT t.slug as plugin_slug, meta_value as resolved, count(*) as topic_count, max(p.post_date) AS most_recent_thread
     36                        FROM {$wpdb->posts} p
     37                                JOIN {$wpdb->postmeta} pm ON (p.ID = pm.post_id AND pm.meta_key = 'topic_resolved')
     38                                JOIN {$wpdb->term_relationships} tr ON (p.ID = tr.object_id)
     39                                JOIN {$wpdb->term_taxonomy} tt ON (tr.term_taxonomy_id = tt.term_taxonomy_id AND tt.taxonomy = 'topic-plugin')
     40                                JOIN {$wpdb->terms} t ON (tt.term_id = t.term_id)
     41                        WHERE
     42                                post_type = 'topic' AND
     43                                post_status = 'publish' AND
     44                                post_parent = (SELECT ID FROM {$wpdb->posts} WHERE post_type = 'forum' AND post_name = 'plugins-and-hacks') AND
     45                                post_date >= %s
     46                       
     47                        GROUP BY t.slug, meta_value",
     48                        $time_limit
     49                ) );
    4750                $wpdb->set_blog_id( WPORG_PLUGIN_DIRECTORY_BLOGID );
    4851
    4952                foreach ( $results as $result ) {
    50                         if ( ! isset( $plugin_stats[ $result->plugin_slug ] ) ) {
    51                                 $plugin_stats[ $result->plugin_slug ] = [
    52                                         'yes' => 0,
    53                                         'no'  => 0,
    54                                         'mu'  => 0,
    55                                 ];
    56                         }
     53                        $plugin_stats[ $result->plugin_slug ] ??= [
     54                                'yes'                => 0,
     55                                'no'                 => 0,
     56                                'mu'                 => 0,
     57                                'most_recent_thread' => 0,
     58                        ];
    5759
    58                         $plugin_stats[ $result->plugin_slug ][ $result->resolved ] = (int) $result->topic_count;
     60                        $plugin_stats[ $result->plugin_slug ][ $result->resolved ]  = (int) $result->topic_count;
     61                        $plugin_stats[ $result->plugin_slug ]['most_recent_thread'] = max(
     62                                strtotime( $result->most_recent_thread ),
     63                                $plugin_stats[ $result->plugin_slug ]['most_recent_thread']
     64                        );
    5965                }
    6066
     
    6874                                update_post_meta( $plugin->ID, 'support_threads', wp_slash( $stats['yes'] + $stats['no'] ) );
    6975                                update_post_meta( $plugin->ID, 'support_threads_resolved', wp_slash( $stats['yes'] ) );
     76                                update_post_meta( $plugin->ID, '_last_support_thread', wp_slash( $stats['most_recent_thread'] ) );
    7077                        }
    7178
    7279                        Manager::clear_memory_heavy_variables();
    7380                }
     81
     82                // Find any plugin whose last support thread was before the above time cutoff and mark it as having no threads.
     83                $plugins = get_posts( [
     84                        'post_type'      => 'plugin',
     85                        'post_status'    => 'publish',
     86                        'posts_per_page' => -1,
     87                        'fields'         => 'ids',
     88                        'meta_query'     => [
     89                                [
     90                                        [
     91                                                'key'     => '_last_support_thread',
     92                                                'compare' => '<',
     93                                                'value'   => strtotime( $time_limit ),
     94                                        ],
     95                                        'relation' => 'OR',
     96                                        [
     97                                                'key'     => '_last_support_thread',
     98                                                'compare' => 'NOT EXISTS',
     99                                        ],
     100                                ],
     101                                [
     102                                        'key'     => 'support_threads',
     103                                        'compare' => '>',
     104                                        'value'   => 0,
     105                                ],
     106                        ],
     107                ] );
     108
     109                foreach ( $plugins as $plugin_id ) {
     110                        update_post_meta( $plugin_id, 'support_threads', 0 );
     111                        update_post_meta( $plugin_id, 'support_threads_resolved', 0 );
     112                }
    74113        }
    75114
Note: See TracChangeset for help on using the changeset viewer.