Comments

berdir’s picture

Title: Unify simplenews_get_subscription() and simplenews_subscription_load() and replace the former with load_by_something() functions » Replace the simplenews_get_subscription() with simplenews_subscription_load_by_mail/uid()

Shorten title.

berdir’s picture

Status: Active » Needs review
StatusFileSize
new28.83 KB

This is quite a nice and bigger clean-up than I expected.

There were two big differences between get_subscription() and the subscriber_load_*() functions:

- Only get_subscriptions() also loaded the corresponding subscriptions. Ported this code over to the load function. Except this line "$subscription->language = user_preferred_language($subscription)->language;", which is imho completely wrong (overriding the language for all loaded subscribers with the one for the current user...). For consistency, simplenews_subscriber_delete() now also deletes the subscriptions. Btw, what's supposed to happen when you cancel your/a users account? we disable when he gets disabled but currently do nothing when deleted/canceled.

- get_subscription() returned a dummy, empty subscription object if it didn't find something for the passed in arguments. This behavior was used in exactly two places (multi-signup and subscription page), where it essentially meant authenticated user vs. anon. Replaced with a more direct check. And there were actually multiple checks that explictly checked against this behavior. Removed completely.

So, as a result, the patch drops simplenews_get_subscription() and simplenews_subscriber_defaults() and ports the existing code over to the new simplenews_subscriber_load_by_mail() function.

The result is quite nice I think:

 includes/simplenews.mail.inc         |    7 +-
 includes/simplenews.source.inc       |    2 +-
 includes/simplenews.subscription.inc |   78 +++++++------
 simplenews.module                    |  221 ++++++++++++----------------------
 tests/simplenews.test                |    3 +-
 5 files changed, 125 insertions(+), 186 deletions(-)

And quite bit of the new code is actually documentation...

Status: Needs review » Needs work

The last submitted patch, remove_simplenews_get_subscription.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new31.52 KB

tests!! ;)

- There is actually a place where we need a dummy subscriber object and that is when sending a test mail to a mail address which is not subscribed. Dealt with that.
- Stop trying to generate generate tokens when the necessary data isn't provided.
- Updated for #706904: List of outstanding, unconfirmed, anonymous subscription requests.

berdir’s picture

Oh and another change I forgot to mention.

Renamed simplenews_subscriber*s*_load_multiple() to simplenews_subscriber_load_multiple(). Similar to #1387624: Rename/merge duplicating/confusingly named functions

Status: Needs review » Needs work

The last submitted patch, second_try.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
Issue tags: +Needs tests

Fixed typos.

Would be good to add some tests for the admin subscription form, will do so before commiting this.. That's one of the major code parts that's touched here that is missing test coverage

berdir’s picture

StatusFileSize
new31.16 KB

And now with patch.

Status: Needs review » Needs work

The last submitted patch, third_time_is_a_charm.patch, failed testing.

berdir’s picture

StatusFileSize
new31.22 KB

See patch file name ;)

berdir’s picture

Status: Needs work » Needs review
miro_dietiker’s picture

Looks great, this stuff. Love to have cleaner APIs for that loading thingies.

berdir’s picture

StatusFileSize
new34.58 KB

Added tests for the admin settings form. Found and fixed a bug in simplenews_user_is_subscribed() which didn't check if the subscriber was activated.

Will commit once green.

berdir’s picture

Status: Needs review » Fixed

Commited.

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