WordPress.org

Making WordPress.org

Ticket #3169: 3169.diff

File 3169.diff, 2.7 KB (added by noisysocks, 2 years ago)
  • wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php

    diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-manager.php
    index f8f1a1f4..13f82633 100644
    class Manager { 
    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_translation_sync', array( __NAMESPACE__ . '\Translation_Sync', 'cron_trigger' ) );
    2324
    2425                // A cronjob to check cronjobs
    2526                add_action( 'plugin_directory_check_cronjobs',   array( $this, 'register_cron_tasks' ) );
    class Manager { 
    238239                if ( ! wp_next_scheduled ( 'plugin_directory_check_cronjobs' ) ) {
    239240                        wp_schedule_event( time() + 60, 'every_120s', 'plugin_directory_check_cronjobs' );
    240241                }
     242                if ( ! wp_next_scheduled ( 'plugin_directory_translation_sync' ) ) {
     243                        wp_schedule_event( time() + 60, 'daily', 'plugin_directory_translation_sync' );
     244                }
    241245        }
    242246
    243247        /**
  • new file wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-translation-sync.php

    diff --git wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-translation-sync.php wordpress.org/public_html/wp-content/plugins/plugin-directory/jobs/class-translation-sync.php
    new file mode 100644
    index 00000000..507d4b7d
    - +  
     1<?php
     2namespace WordPressdotorg\Plugin_Directory\Jobs;
     3
     4use WordPressdotorg\Plugin_Directory;
     5
     6/**
     7 * Sync plugin translations from glotpress to each plugin's postmeta. This is
     8 * intended to be run every day.
     9 *
     10 * @package WordPressdotorg\Plugin_Directory\Jobs
     11 */
     12class Translation_Sync {
     13        /**
     14         * Cron trigger that syncs plugin translations from glotpress to each plugin's
     15         * postmeta.
     16         */
     17        public static function cron_trigger() {
     18                $args = array(
     19                        'post_type' => 'plugin',
     20                        'posts_per_page' => 100,
     21                        'offset' => 0,
     22                );
     23
     24                $directory = Plugin_Directory\Plugin_Directory::instance();
     25
     26                while ( $posts = get_posts( $args ) ) {
     27                        foreach ( $posts as $post ) {
     28                                $directory->sync_all_translations_to_meta( $post->ID );
     29                        }
     30
     31                        // Make sure the cache doesn't exhaust memory
     32                        global $wp_object_cache;
     33                        if ( is_object( $wp_object_cache ) ) {
     34                                $wp_object_cache->cache = array();
     35                                $wp_object_cache->stats = array();
     36                        }
     37
     38                        $args['offset'] += $args['posts_per_page'];
     39                }
     40        }
     41}