Comments

berdir’s picture

StatusFileSize
new70.99 KB

The patch contains lots of minor clean-ups that don't really deserve a separate issue. If something needs more discussion, I can remove it from the patch and open a separate issue...

- Removes many outdated @todo's
- Unifying on 'newsletters' for list of newsletter categories and also unifying on using #tree. This allows to simplify the code and requires some changes in the test code.
- Fixes some @todo's (e.g. by adding missing documentation)
- Moved node tab page/form callbacks to admin.inc
- moved api.php to the top-level folder. This isn't an include file, this is documentation.
- Coding style fixes (e.g. "Implements" instead of "Implementation of")
- Removed a number of functions that aren't used anymore.
- Removed theme functions for newsletter body/footer. There is imho no need to have theme functions *and* templates and it will lead to confusion what is actually used if it's not overriden (I think the theme functions were actually used, not the templates).

Let's see what the testbot has to say.

berdir’s picture

Status: Active » Needs review

Status: Needs review » Needs work

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

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new70.43 KB

Ok, forgot to add the 'template' key to hook_theme() to tell the theme system to use the templates and not look for theme functions.

This one should pass.

berdir’s picture

That was actually based on an outdated version, this one should be better.

berdir’s picture

Status: Needs review » Needs work

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

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new71.94 KB

Re-rolled the patch.

Status: Needs review » Needs work

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

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new71.75 KB

Actually detected a bug in the new code from #841966: include simplenews-newsletter-footer.tpl.php in hidden newsletters that didn't occur due to the duplicated theme functions. Fixed in a separate commit and re-rolled.

Status: Needs review » Needs work

The last submitted patch, re-rolled-after-bugfix-cleanup.patch, failed testing.

berdir’s picture

Status: Needs work » Needs review
StatusFileSize
new72.07 KB

And next try.

miro_dietiker’s picture

Status: Needs review » Reviewed & tested by the community

Perfectly worked for me on top on #374222 ...
With those updates the code is already a lot cleaner.

I think we can commit this, but possibly as a followup:

I don't like these conversions...

./includes/simplenews.admin.inc:1986:      $newsletter = simplenews_newsletter_defaults($node);
./simplenews.module:443:    $newsletter = (object)simplenews_newsletter_defaults($node);
./simplenews.module:456:  $node->simplenews = (object)simplenews_newsletter_defaults($node);
./simplenews.module:463:function simplenews_newsletter_defaults($node = NULL) {
./simplenews.module:490:    $node->simplenews = (object)simplenews_newsletter_defaults($node);
./simplenews.module:558:      $newsletter = (object)simplenews_newsletter_defaults($node);
./simplenews.module:2650:          $newsletter = (object) simplenews_newsletter_defaults($node);
./simplenews.module:2665:    $newsletter = (object)simplenews_newsletter_defaults($node);

And also this i don't like these conversions...

./tests/simplenews.test-401-    $account = (object)array('mail' => $mail);
./tests/simplenews.test:402:    $subscriber = simplenews_get_subscription($account);
./includes/simplenews.subscription.inc-593-  $account = (object) array('snid' => $snid);
./includes/simplenews.subscription.inc:594:  $subscription = simplenews_get_subscription($account);

We possibly should add a specific _get_by_snid and _get_by_mail? Dunno how to handle this... Any core pattern around?

berdir’s picture

About $node->simplenews, I was actually thinking about dropping that that completely and simply relying on simplenews_newsletter_load($node->tid) when we need "newsletter information". Which in most cases is just the tid. So maybe a function like simplenews_get_category($node) or something similar that actually gets it directly from the taxonomy reference field. That would also make it easier to remove the redundant column from the simplenews_newsletter table? I'll open a follow-up once I commited this. Probably tomorrow in the train or so...

Yes, simplenews_get_subscription() is a nasty one. It basically checks three keys (mail, snid, uid) but actually only one of them and strictly in that order, so it's pointless to pass in an account object that has mail and uid set as there always is a mail when there is a uid so uid is never checked for. Re: core patterns, core actually uses something_load_by_something(), e.g. user_load_by_name(), so maybe we should actually add simplenews_subscriber_load_by_mail() and simplenews_subscriber_load_by_uid() (snid is already covered directly...by _load()), make simplenews_subscriber_load() return the same information as get_subscription and drop that one? Currently we have two kinds of subscriber objects which aren't the same thing.. Will open a follow-up for that one as well..

It's always hard in huge issues like this one to stop at some point and don't clean up forever.. there's still a lot of potential for doing so... :)

miro_dietiker’s picture

I think the amount of fixes is fine for this issue.

However for the followup ones, i think we should really commit the clean API functions before beta/stable... It would allow us to have a much cleaner API.

berdir’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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