Changeset 11937
- Timestamp:
- 07/05/2022 04:59:28 PM (15 months ago)
- Location:
- sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/profiles.php
r11935 r11937 10 10 11 11 use WordPressdotorg\Profiles as Profiles_API; 12 use GP, GP_Translation ;12 use GP, GP_Translation, GP_Project, GP_Locale, GP_Translation_Set; 13 13 14 14 defined( 'WPINC' ) || die(); … … 23 23 } 24 24 25 add_action( 'gp_translation_created', __NAMESPACE__ . '\add_translation_activity' ); 26 add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_translation_activity', 10, 2 ); 25 add_action( 'gp_translation_created', __NAMESPACE__ . '\add_single_translation_activity' ); 26 add_action( 'gp_translation_saved', __NAMESPACE__ . '\add_single_translation_activity', 10, 2 ); 27 add_action( 'gp_translation_set_bulk_action_post', __NAMESPACE__ . '\add_bulk_translation_activity', 10, 4 ); 27 28 28 29 /** 29 30 * Add a activity when strings are suggested and approved. 30 31 */ 31 function add_translation_activity( GP_Translation $new_translation, GP_Translation $previous_translation = null ) : void { 32 function add_single_translation_activity( GP_Translation $new_translation, GP_Translation $previous_translation = null ) : void { 33 $bulk_request = gp_post( 'bulk', null ); 34 35 // Bulk actions are handled by `add_bulk_translation_activity()`. 36 if ( $bulk_request ) { 37 return; 38 } 39 32 40 $current_user_is_editor = GP::$permission->current_user_can( 33 41 'approve', … … 58 66 Profiles_API\api( $request_body ); 59 67 } 68 69 /** 70 * Add activity when bulk actions are performed. 71 */ 72 function add_bulk_translation_activity( GP_Project $project, GP_Locale $locale, GP_Translation_Set $translation_set, array $bulk ) : void { 73 switch ( $bulk['action'] ) { 74 case 'approve': 75 $type = 'glotpress_translation_approved'; 76 break; 77 78 default: 79 return; 80 } 81 82 $translation_ids = array(); 83 foreach ( $bulk['row-ids'] as $row_id ) { 84 $parts = explode( '-', $row_id ); 85 $translation_ids[] = intval( $parts[1] ?? 0 ); 86 } 87 88 $translations = GP::$translation->find_many( 89 sprintf( 'id IN ( %s )', implode( ',', $translation_ids ) ) 90 ); 91 92 $user_type_counts = array(); 93 foreach ( $translations as $translation ) { 94 // `GP_Route_Translation::_bulk_approve()` tracks which `set_status()` calls succeed, but that information 95 // isn't passed to this callback. Check this just in case any of them failed. 96 if ( 'current' !== $translation->status ) { 97 continue; 98 } 99 100 $user_id = $translation->user_id; 101 102 if ( isset( $user_type_counts[ $user_id ][ $type ] ) ) { 103 $user_type_counts[ $user_id ][ $type ]++; 104 } else { 105 $user_type_counts[ $user_id ][ $type ] = 1; 106 } 107 } 108 109 $activities = array(); 110 foreach ( $user_type_counts as $user_id => $types ) { 111 foreach ( $types as $type => $count ) { 112 $activities[] = array( 113 'component' => 'glotpress', 114 'type' => $type, 115 'user_id' => $user_id, 116 'bump' => $count, 117 ); 118 } 119 } 120 121 $request_body = array( 122 'action' => 'wporg_handle_activity', 123 'component' => 'glotpress', 124 'activities' => $activities, 125 ); 126 127 Profiles_API\api( $request_body ); 128 } -
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-profiles/tests/e2e.php
r11929 r11937 45 45 'status' => 'waiting', 46 46 ) ); 47 GlotPress_Profiles\add_ translation_activity( $translation );47 GlotPress_Profiles\add_single_translation_activity( $translation ); 48 48 49 49 $translation = new GP_Translation( array( … … 51 51 'status' => 'current', 52 52 ) ); 53 GlotPress_Profiles\add_ translation_activity( $translation );53 GlotPress_Profiles\add_single_translation_activity( $translation ); 54 54 55 55 echo "\nThe daily digest count should have been bumped on https://profiles.wordpress.org/$user->user_nicename/ \n";
Note: See TracChangeset
for help on using the changeset viewer.