Currently the only way for an external module to react on subscribe/unsubscribe events is to declare actions and configure them to trigger on subscribe/unsubscribe events (via simplenews_actions module).

It'll be easier and more code efficient if Simplenews defines a hook in simplenews_subscribe_user and simplenews_unsubscribe_user functions. This way custom code can be fired directly without declaring actions.

This is one line fix, but extremely important in order to allow more interaction with external modules. Patch for DRUPAL-6--2 included as attachment.

Please review and comment.

Comments

dankh’s picture

StatusFileSize
new892 bytes
simon georges’s picture

Assigned: Unassigned » simon georges

I'm affecting this to myself, so I think about reviewing it.

Code looks clean & simple enough.

simon georges’s picture

Title: Define hooks on subscribe/unsibscribe user » Define hooks on subscribe/unsubscribe user

Typo in the title ;)

simon georges’s picture

Ok, I've looked at your patch :

  • Wouldn't it make sense to have the hook fired at the same time of the action Trigger (I'd move the line inside the elseif loop just two lines up) ?
  • Or did you make it fired for the confirmation part as well to update external system eventually ?
dankh’s picture

No because the action triggers get fired only if Simplenews Actions module is installed. The invoke hook is independent of Simplenews Actions.

simon georges’s picture

Ok, I see.

@miro_dietiker, @Sutharsan, do you see something preventing this addition (a matter of performance, maybe, or something else I'd be missing) ?

simon georges’s picture

Status: Needs review » Patch (to be ported)

Committed to 6.x-2.x.
Let's see if someone complains ;-)

simon georges’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
pillarsdotnet’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new8.56 KB

Patch for 7.x-1.x

simon georges’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

jonhattan’s picture

Version: 7.x-1.x-dev » 6.x-2.x-dev
Category: feature » bug
Status: Closed (fixed) » Needs review
StatusFileSize
new5.56 KB

Wondering if it's too late to complain :)

The implementation in D6 is unusable: there's no info about the subscription passed through to the hooks. Attached patch mimics the same behaviour as in D7. It also takes care of #4.

btw, actions integration is broken in the same way, although it is not my battle and I've also heard that actions are gone in D7 version in favour of rules.

berdir’s picture

It's never to late to complain if you provide a patch :)

Changes look good to me. The variable rename is unfortunate, but probably necessary. FYI, simplenews_get_subscription() is gone in 7.x in favor of simplenews_subscriber_load_*() functions (they're not entities though, but that will most likely happen for 7.x-2.x)

Yes, actions integration is gone in 7.x and I'm not sad about that ;)

jonhattan’s picture

Yes, I did read 7.x before proceeding with this patch. The variable rename is in concordance with 7.x. It is unfortunate, but isolated in the involved functions.

Is the test bot stalled or just tests for simplenews that doesn't fire?

jonhattan’s picture

Status: Needs review » Needs work

There're some failures with this patch

berdir’s picture

Status: Needs work » Needs review

There are more than just some failures without this patch as well :)

The 6.x tests are completely broken, that's why the testbot postpones testing of your patch until those tests are fixed. Unless you can manually confirm that there are *more* test failures with your patch than without, you can safely ignore them.

I once started backporting the current 7.x-1.x tests to 6.x-2.x but it's quite a bit of work. If you're interested in that, ping me and I can give you what I came up with.

jonhattan’s picture

StatusFileSize
new5.51 KB

Here is a better patch.

I'm not excited about working on tests by now, but I will continue posting patches as bugs hit me.

jonhattan’s picture

StatusFileSize
new5.66 KB

A bug related to this patch found. Confirmation link was bad.

Prehaps I need those tests though. Berdir, please expose those tests to me by the mean you consider more convenient.. mail, issue, git branch...

berdir’s picture

The backport of the tests is now available in #1532122: Backport of the 7.x-1.x tests, your patch should automatically be picked up by the testbot once they are commited and the branch tests pass.

jonhattan’s picture

test passes. I'll try to provide a test to cover this hooks.

thijsvdanker’s picture

Patch in #18 makes perfect sense, and passes the simpletest.. ready for commit?

rmcom’s picture

supporting commit of this patch

rmcom’s picture

Has this patch ever been rolled into the D6 version?

  • Simon Georges committed 4082035 on 8.x-1.x
    #1069570 by pillarsdotnet: Define hooks on subscribe/unsubscribe user