Permalink
Browse files

Fix return value of email_bug_reminder()

The function now returns an array containing only the users to whom the
reminder e-mail was actually sent (i.e. excludes failures, blank e-mails,
etc).

In addition, the return value is now an array of user id's instead of
user names, which indeed makes more sense from an API perspective, as
mentioned by Julian Fitzell in 5ea3d0b,
since the function's only caller is bug_reminder.php which exclusively
relies on user id's.

Fixes #15472
  • Loading branch information...
1 parent 1913149 commit 389b2a65eb7abd317b4cfc4144187ab7e944d435 @dregad dregad committed Feb 7, 2013
Showing with 10 additions and 10 deletions.
  1. +10 −10 core/email_api.php
View
@@ -812,7 +812,7 @@ function email_bug_deleted( $p_bug_id ) {
* @param string $p_subject
* @param string $p_message
* @param array $p_headers
- * @return int
+ * @return int e-mail queue id, or NULL if e-mail was not stored
*/
function email_store( $p_recipient, $p_subject, $p_message, $p_headers = null ) {
$t_recipient = trim( $p_recipient );
@@ -1134,14 +1134,12 @@ function email_append_domain( $p_email ) {
}
/**
- * Send a bug reminder to each of the given user, or to each user if the first parameter is an array
- * return an array of usernames to which the reminder was successfully sent
+ * Send a bug reminder to the given user(s), or to each user if the first parameter is an array
*
- * @todo I'm not sure this shouldn't return an array of user ids... more work for the caller but cleaner from an API point of view.
- * @param array $p_recipients
- * @param int $p_bug_id
- * @param string $p_message
- * @return null
+ * @param int|array $p_recipients user id or list of user ids array to send reminder to
+ * @param int $p_bug_id Issue for which the reminder is sent
+ * @param string $p_message Optional message to add to the e-mail
+ * @return array List of users ids to whom the reminder e-mail was actually sent
*/
function email_bug_reminder( $p_recipients, $p_bug_id, $p_message ) {
if( !is_array( $p_recipients ) ) {
@@ -1162,10 +1160,9 @@ function email_bug_reminder( $p_recipients, $p_bug_id, $p_message ) {
lang_push( user_pref_get_language( $t_recipient, $t_project_id ) );
$t_email = user_get_email( $t_recipient );
- $result[] = user_get_name( $t_recipient );
if( access_has_project_level( config_get( 'show_user_email_threshold' ), $t_project_id, $t_recipient ) ) {
- $t_sender_email = ' <' . current_user_get_field( 'email' ) . '>';
+ $t_sender_email = ' <' . user_get_email( $t_sender_id ) . '>';
} else {
$t_sender_email = '';
}
@@ -1174,6 +1171,9 @@ function email_bug_reminder( $p_recipients, $p_bug_id, $p_message ) {
if( ON == config_get( 'enable_email_notification' ) ) {
$t_id = email_store( $t_email, $t_subject, $t_contents );
+ if( $t_id !== null ) {
+ $result[] = $t_recipient;
+ }
log_event( LOG_EMAIL, "queued reminder email #$t_id for U$t_recipient" );
}

0 comments on commit 389b2a6

Please sign in to comment.