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 { |
20 | 20 | add_action( 'plugin_directory_meta_sync', array( __NAMESPACE__ . '\Meta_Sync', 'cron_trigger' ) ); |
21 | 21 | add_action( 'plugin_directory_svn_sync', array( __NAMESPACE__ . '\SVN_Watcher', 'cron_trigger' ) ); |
22 | 22 | 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' ) ); |
23 | 24 | |
24 | 25 | // A cronjob to check cronjobs |
25 | 26 | add_action( 'plugin_directory_check_cronjobs', array( $this, 'register_cron_tasks' ) ); |
… |
… |
class Manager { |
238 | 239 | if ( ! wp_next_scheduled ( 'plugin_directory_check_cronjobs' ) ) { |
239 | 240 | wp_schedule_event( time() + 60, 'every_120s', 'plugin_directory_check_cronjobs' ); |
240 | 241 | } |
| 242 | if ( ! wp_next_scheduled ( 'plugin_directory_translation_sync' ) ) { |
| 243 | wp_schedule_event( time() + 60, 'daily', 'plugin_directory_translation_sync' ); |
| 244 | } |
241 | 245 | } |
242 | 246 | |
243 | 247 | /** |
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 |
| 2 | namespace WordPressdotorg\Plugin_Directory\Jobs; |
| 3 | |
| 4 | use 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 | */ |
| 12 | class 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 | } |