Making WordPress.org

Changeset 4420


Ignore:
Timestamp:
11/25/2016 06:55:10 AM (10 years ago)
Author:
dd32
Message:

Plugin Directory: Add a cron task to import/update the downloads, rating and ratings meta fields for indexing in Search.
The previous method of pulling the meta keys from a different data-source has proved not to be usable with Jetpack Sync (which we rely upon for Search).

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/plugin-directory
Files:
2 added
1 edited

Legend:

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

    r4419 r4420  
    4141                add_filter( 'single_term_title', array( $this, 'filter_single_term_title' ) );
    4242                add_filter( 'the_content', array( $this, 'filter_rel_nofollow' ) );
     43
     44                // Cron tasks.
     45                add_action( 'admin_init', array( $this, 'register_cron_tasks' ) );
     46                add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Jobs\Meta_Sync', 'cron_trigger' ) );
    4347
    4448                // oEmbed whitlisting.
     
    328332
    329333        /**
     334         * Queue all of our cron tasks.
     335         */
     336        function register_cron_tasks() {
     337                if ( ! wp_next_scheduled ( 'plugin_directory_meta_sync' ) ) {
     338                        wp_schedule_event( time(), 'hourly', 'plugin_directory_meta_sync' );
     339                }
     340        }
     341
     342        /**
    330343         * Register the Shortcodes used within the content.
    331344         */
     
    951964        public function filter_shim_postmeta( $value, $object_id, $meta_key ) {
    952965                switch ( $meta_key ) {
    953                         case 'downloads':
    954                                 $post  = get_post( $object_id );
    955                                 $count = Template::get_downloads_count( $post );
    956                                 $value = array( $count );
    957                                 break;
    958 
    959                         case 'rating':
    960                                 $post = get_post( $object_id );
    961                                 // The WordPress.org global ratings functions
    962                                 if ( ! method_exists( '\WPORG_Ratings', 'get_avg_rating' ) ) {
    963                                         break;
    964                                 }
    965 
    966                                 $rating = \WPORG_Ratings::get_avg_rating( 'plugin', $post->post_name );
    967                                 $value  = array( $rating );
    968                                 break;
    969 
    970                         case 'ratings':
    971                                 $post = get_post( $object_id );
    972                                 if ( ! method_exists( '\WPORG_Ratings', 'get_rating_counts' ) ) {
    973                                         break;
    974                                 }
    975 
    976                                 $ratings = \WPORG_Ratings::get_rating_counts( 'plugin', $post->post_name );
    977                                 $value   = array( $ratings );
    978                                 break;
    979 
    980966                        case 'tested':
    981967                                // For the tested field, we bump up the minor release to the latest compatible minor release.
Note: See TracChangeset for help on using the changeset viewer.