Changeset 11041
- Timestamp:
- 06/20/2021 04:35:22 PM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-plugin-directory/inc/cli/class-sync-plugin-translations.php
r8937 r11041 53 53 $set_slug = isset( $assoc_args['set'] ) ? $assoc_args['set'] : 'default'; 54 54 55 55 56 $translation_set_src = GP::$translation_set->by_project_id_slug_and_locale( $project_src->id, $set_slug, $locale->slug ); 56 57 if ( ! $translation_set_src ) { … … 60 61 $translation_set_dest = GP::$translation_set->by_project_id_slug_and_locale( $project_dest->id, $set_slug, $locale->slug ); 61 62 if ( ! $translation_set_dest ) { 62 WP_CLI::error( ' Sourcetranslation set not found!' );63 WP_CLI::error( 'Destination translation set not found!' ); 63 64 } 64 65 … … 69 70 } 70 71 71 $current_translations = new Translations();72 $ user_id_map = [];72 $current_translations = new Translations(); 73 $current_translations_map = []; 73 74 foreach ( $current_translations_list as $translation ) { 74 75 $current_translations->add_entry( $translation ); 75 $user_id_map[ $translation->key() ] = $translation->user_id; 76 $current_translations_map[ $translation->key() ] = [ 77 'user_id' => $translation->user_id, 78 'status' => $translation->translation_status, 79 'warnings' => $translation->warnings, 80 ]; 81 76 82 } 77 83 unset( $current_translations_list ); 78 84 79 add_ action( 'gp_translation_created', function( $translation ) use ( $user_id_map ) {80 $original = GP::$original->get( $ translation->original_id);85 add_filter( 'gp_translation_prepare_for_save', function( $args, $translation ) use ( $current_translations_map ) { 86 $original = GP::$original->get( $args['original_id'] ); 81 87 if ( ! $original ) { 82 return ;88 return $args; 83 89 } 84 90 … … 89 95 ] ); 90 96 $key = $translation_entry->key(); 91 if ( isset( $user_id_map[ $key ] ) && $user_id_map[ $key ] !== $translation->user_id ) { 92 $translation->update( [ 'user_id' => $user_id_map[ $key ] ] ); 97 98 if ( ! isset( $current_translations_map[ $key ] ) ) { 99 return $args; 93 100 } 94 } ); 101 102 $current_translation = $current_translations_map[ $key ]; 103 104 $args['user_id'] = $current_translation['user_id']; 105 $args['status'] = $current_translation['status']; 106 $args['warnings'] = $current_translation['warnings']; 107 108 return $args; 109 }, 50, 2 ); 110 111 // GP_Translation_Set::import() calls `$translation->set_status()` which may reset the status set above. 112 add_filter( 'gp_translation_set_import_status', function( $status, $entry ) use ( $current_translations_map ) { 113 if ( ! isset( $current_translations_map[ $entry->key() ] ) ) { 114 return $status; 115 } 116 117 $current_translation = $current_translations_map[ $entry->key() ]; 118 119 return $current_translation['status']; 120 }, 50, 2 ); 95 121 96 122 $synced = $translation_set_dest->import( $current_translations );
Note: See TracChangeset
for help on using the changeset viewer.