Followup from #408870: convert generation of comments to use project_issue followup api...

The current API for programatically adding issue followups is a little weird in a few ways:

A) It depends on the auto followup user being configured, even if the uid for the comment is specified in the $changes array

B) It does a bunch of wonky to switch global $user around to this auto-followup user, when we should be able to just specify changes['uid'].

We should split this up a bit.

Let's add a function like:

function project_issue_add_auto_followup($changes) {
  if ($auto_user = _project_issue_followup_get_user()) {
    $changes['uid'] = $auto_user->uid;
    return project_issue_add_followup($changes);
  }
  else {
    return FALSE;
  }
}

And then project_issue_add_followup() can just use the uid from global $user if it's not already specified in $changes['uid'].

Comments

hunmonk’s picture

Assigned: Unassigned » hunmonk
Status: Active » Needs review
StatusFileSize
new9.39 KB

this should do it, but not tested.

dww’s picture

I rerolled this to fix some things that were a bit wonky:

A) project_issue_add_auto_followup() couldn't make up its mind if it uses the auto-user or not. ;) It should just always use that and not support passing in the uid or name specially. That's why it's a separate function with "auto" in the name. ;) Fixed the function and the PHPdoc comments accordingly.

B) It's weird that project_issue_add_followup() assumes $changes['uid'] is set, while project_issue_add_auto_followup() did not. project_issue_add_followup() should obviously honor $changes['uid'], but if it's not set, it should use global $user. Also, it's generally unsafe programming practice to use "$user" for a local variable for a user object, because if someone adds global $user to the function, you can get security holes, etc. We should always use $account for local user variables that aren't global $user.

C) Both project_issue_add_auto_followup() and project_issue_add_followup() should always return a value.

D) Cleaned up the PHPdoc generally to avoid duplication. project_issue_add_auto_followup() just points to project_issue_add_followup() for most things now.

dww’s picture

p.s. I tested with cron and it works great.

hunmonk’s picture

Status: Needs review » Fixed

code looks good. tested for both issue generation and the install profile, and it works perfectly.

committed to HEAD.

p.s. this also rolls back the UI changes that were made to project_issue_generate, as they are no longer needed.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.