Making WordPress.org

Ticket #3434: 3434.diff

File 3434.diff, 3.2 KB (added by obenland, 9 years ago)
  • class-manager.php

     
    2020                add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Meta_Sync', 'cron_trigger' ) );
    2121                add_action( 'plugin_directory_svn_sync', array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) );
    2222                add_action( 'plugin_directory_update_api_check', array( __NAMESPACE__ . '\API_Update_Updater', 'cron_trigger' ) );
     23                add_action( 'plugin_directory_plugin_support_resolved', array( __NAMESPACE__ . '\Plugin_Support_Resolved', 'cron_trigger' ) );
    2324
    2425                // A cronjob to check cronjobs
    2526                add_action( 'plugin_directory_check_cronjobs', array( $this, 'register_cron_tasks' ) );
  • class-plugin-support-resolved.php

     
     1<?php
     2/**
     3 * Updates stats on resolved and unresolved support requests.
     4 *
     5 * @package WordPressdotorg\Plugin_Directory\Jobs
     6 */
     7
     8namespace WordPressdotorg\Plugin_Directory\Jobs;
     9
     10use WordPressdotorg\Plugin_Directory\Plugin_Directory;
     11
     12/**
     13 * Class Plugin_Support_Resolved
     14 *
     15 * @package WordPressdotorg\Plugin_Directory\Jobs
     16 */
     17class Plugin_Support_Resolved {
     18
     19        /**
     20         * The cron trigger for the import job.
     21         *
     22         * @static
     23         * @global wpdb $wpdb WordPress database class.
     24         */
     25        public static function cron_trigger() {
     26                global $wpdb;
     27
     28                // Support resolutions are on a 2 month rolling period.
     29                $time_limit   = date( 'Y-m-d 00:00:00', strtotime( '-2 months' ) );
     30                $plugin_stats = [];
     31
     32                $wpdb->set_blog_id( 419 );
     33                // 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
     35FROM {$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)
     40WHERE
     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
     46GROUP BY t.slug, meta_value", $time_limit ) );
     47                $wpdb->set_blog_id( 367 );
     48
     49                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                        }
     57
     58                        $plugin_stats[ $result->plugin_slug ][ $result->resolved ] = (int) $result->topic_count;
     59                }
     60
     61                foreach ( $plugin_stats as $plugin_slug => $stats ) {
     62                        $plugin = Plugin_Directory::get_plugin_post( $plugin_slug );
     63                        if ( ! $plugin || 'publish' !== $plugin->post_status ) {
     64                                continue;
     65                        }
     66
     67                        update_post_meta( $plugin->ID, 'support_threads', wp_slash( $stats ? $stats['yes'] + $stats['no'] : 0 ) );
     68                        update_post_meta( $plugin->ID, 'support_threads_resolved', wp_slash( $stats ? $stats['yes'] : 0 ) );
     69                }
     70        }
     71}