now that http://drupal.org/node/179772 is committed, the mail code needs to be adjusted to find the new location of issue attachments.

CommentFileSizeAuthor
#4 ifac_mail_inc.patch7.31 KBdww
#3 mail.inc__0.patch6.97 KBhunmonk
#1 mail.inc_.patch6.34 KBhunmonk

Comments

hunmonk’s picture

Status: Active » Needs review
StatusFileSize
new6.34 KB

the logic for when to send out the mailing code needed some reworking in order to make it behave sanely.

basically, we have to initiate the sending of emails _after_ everything has been saved to the database on an insert/update, because if we don't we're battling all kinds of weird problems with the file data being current/consistent/correct in the node/comment objects.

so i elected to move the actual sending logic to hook_exit(). the implementation is light, and it solves all the numerous consistencies mentioned above.

tested this pretty thoroughly, and it's working well.

dww’s picture

Status: Needs review » Needs work

Code mostly looks good visually. I didn't test it at all, so if anyone else can independently verify, that'd be nice. ;) This seems like a reasonable improvement overall. However, a few things:

A) I'd prefer some more comments about why hook_exit() is being used like this directly in the code, not just in this issue. At the very least under the "Implementation of hook_exit()." in that phpdoc comment. The "Mark the node for email notification" comment in nodeapi is nice, but perhaps right there you could also include something like "Mark the node for email notification during hook_exit(), so that all issue and file data is in a consistent state before we generate the email" (or something).

B) The comment on the return value from project_issue_set_mail_notify() is a little misleading. It's not really a list of nids, it's an associate array, where the keys are the nids and the values are all 1 (which has implications for how you use the array, as you see in project_issue_exit(). Perhaps the values of the returned array should be $nid, too, so when you loop over it, you can avoid the as $nid => $value (where you ignore the $value itself). You're doing it this way to avoid duplicates, it seems. However, how is it possible to get duplicates here? Does this array ever contain more than 1 value? Why? None of this is clear from looking at the code, nor the comments. Seems to me like during a given page load cycle where hook_exit is getting called, you could only ever either create a new issue or add a single new comment on a given issue. Either way, there's only 1 nid that needs notification emails, right? Why can't project_issue_set_mail_notify() just operate on a single $nid and return that directly as an int? Maybe there's a good reason, in which case, it should be explained in the comments in the code. Or, all of this code can be simplified.

Thanks,
-Derek

hunmonk’s picture

Status: Needs work » Needs review
StatusFileSize
new6.97 KB

i've made the comments more clear, and passed $nid as the value in the array as well.

also, i've moved to a NULL/!isset() structure, which i think is better usage here -- and, in a fit of defensive programming, the static value is now cleared after it's used.

dww’s picture

StatusFileSize
new7.31 KB

The only lingering problems I found were some cosmetic formatting issues with various comments. Fixed in attached patch. I still haven't tested this, so if you could do a little more testing to make sure none of your recent changes break anything, feel free to commit. Thanks!

hunmonk’s picture

Status: Needs review » Fixed

tested the code thoroughly again, and it works perfectly. committed to HEAD. thanks for the review!

Anonymous’s picture

Status: Fixed » Closed (fixed)

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