Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gp_translations_imported doesn't pass imported string IDs #1467

Open
iandunn opened this issue Jul 5, 2022 · 1 comment
Open

gp_translations_imported doesn't pass imported string IDs #1467

iandunn opened this issue Jul 5, 2022 · 1 comment
Labels
good first issue [Type] Enhancement A suggestion for improvement.

Comments

@iandunn
Copy link

iandunn commented Jul 5, 2022

Problem

gp_translations_imported only passes the ID of the translation set:

/**
* Fires after translations have been imported to a translation set.
*
* @since 1.0.0
*
* @param int $translation_set The ID of the translation set the import was made into.
*/
do_action( 'gp_translations_imported', $this->id );

I'd like my callback to know which strings were imported, so that I can add activity notifications to a BuddyPress installation.

Desired Solution

It seems like the simplest approach would be for the action to pass an array of imported translation IDs to its callbacks, similar to what gp_translation_set_bulk_action_post does.

e.g.,

$translation = GP::$translation->create( $entry );
+$created_translation_ids[] = $translation->id;

// ...

-do_action( 'gp_translations_imported', $this->id ); 
+do_action( 'gp_translations_imported', $this->id, $created_translation_ids ); 

Other solutions I considered

  • Use gp_translation_created | gp_translation_saved - It's not performant to process them individually, since the processing involves an HTTP request and database write. To avoid that using these actions, I'd have to store each ID in a global/static var, and then run my logic for all of the entries once the process is done.
  • Parse from $_FILES['import-file'] - That requires duplicating a lot of the logic of the import process, and still wouldn't let me know which were imported (where $create = true)
@ocean90
Copy link
Member

ocean90 commented Jul 6, 2022

  • Use gp_translation_created | gp_translation_saved - It's not performant to process them individually, since the processing involves an HTTP request and database write. To avoid that using these actions, I'd have to store each ID in a global/static var, and then run my logic for all of the entries once the process is done.

That's something we already doing in several places like WPorg_GP_Project_Stats or Translation_Sync with the help of the shutdown action.

But sure, we can extend the function to track the IDs of new translations and pass them to the action.

@ocean90 ocean90 added [Type] Enhancement A suggestion for improvement. good first issue labels Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue [Type] Enhancement A suggestion for improvement.
Projects
None yet
Development

No branches or pull requests

2 participants