Changeset 8937 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-plugin.php
- Timestamp:
- 06/10/2019 02:45:10 PM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-suggestions/inc/class-plugin.php
r8767 r8937 5 5 use GP; 6 6 use GP_Locales; 7 use Text_Diff;8 use WP_Error;9 use WP_Http;10 use WP_Text_Diff_Renderer_inline;11 12 require_once ABSPATH . '/wp-includes/wp-diff.php' ;13 7 14 8 class Plugin { 9 10 const TM_UPDATE_EVENT = 'wporg_translate_tm_update'; 15 11 16 12 /** … … 18 14 */ 19 15 private static $instance; 16 17 /** 18 * @var array 19 */ 20 private $queue = []; 20 21 21 22 /** … … 45 46 add_action( 'gp_pre_tmpl_load', [ $this, 'pre_tmpl_load' ], 10, 2 ); 46 47 add_action( 'wporg_translate_suggestions', [ $this, 'extend_translation_suggestions' ] ); 48 49 if ( 'cli' !== PHP_SAPI ) { 50 add_action( 'gp_translation_created', [ $this, 'translation_updated' ], 3 ); 51 add_action( 'gp_translation_saved', [ $this, 'translation_updated' ], 3 ); 52 53 // DB Writes are delayed until shutdown to bulk-update the stats during imports. 54 add_action( 'shutdown', [ $this, 'schedule_tm_update' ], 3 ); 55 } 56 57 add_action( self::TM_UPDATE_EVENT, [ Translation_Memory_Client::class, 'update' ] ); 58 } 59 60 /** 61 * Adds a translation in queue when a translation was created 62 * or updated. 63 * 64 * @param \GP_Translation $translation Created/updated translation. 65 */ 66 public function translation_updated( $translation ) { 67 if ( ! $translation->user_id || 'current' !== $translation->status ) { 68 return; 69 } 70 71 $this->queue[ $translation->original_id ] = $translation->id; 72 } 73 74 /** 75 * Schedules a single event to update translation memory for new translations. 76 */ 77 public function schedule_tm_update() { 78 remove_action( 'gp_translation_created', [ $this, 'translation_updated' ], 3 ); 79 remove_action( 'gp_translation_saved', [ $this, 'translation_updated' ], 3 ); 80 81 if ( ! $this->queue ) { 82 return; 83 } 84 85 wp_schedule_single_event( time() + 60, self::TM_UPDATE_EVENT, [ 'translations' => $this->queue ] ); 47 86 } 48 87
Note: See TracChangeset
for help on using the changeset viewer.