As stated in #1417634 for v1.0, Simplenews is NOT able to send newsletters to multiple subscribers lists, which is something most of people would expect from a newsletter module.

Since this is the only usable module I've found to massive send custom-themed nodes to subscribers lists, but lack one of the most important things, I've decided to do it myself.

However, the code was almost thought to be able to do so, so after a little research, I just had to create a function and modify 3 other functions, and now, Simplenews 7.x-2.x-dev is able to send newsletters to multiple groups/lists.

I'm uploading the patch and commiting the changes to the git repository (I hope I get it right, it's the first time I do so )

Comments

XoRDy’s picture

Issue summary: View changes
StatusFileSize
new6.92 KB
XoRDy’s picture

Category: Bug report » Feature request

Status: Fixed » Closed (fixed)

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

Moravec.To’s picture

It works!
If you apply this patch, you will be able send newslleter to as many categories as you want.
But, if there are same email adresses subscribed to more categories, this will send duplicate emails.

Fix is very simple. Just add

$select->condition('s.snid', db_select('simplenews_mail_spool', 'r')->fields('r', array('snid'))->condition('entity_id', $node->nid, '='), 'NOT IN');

on row 38 in simplenews.mail.inc (modificated function is below)

function simplenews_add_node_to_spool($node) {
  $newsletter_ids=simplenews_issue_newsletter_ids($node);
  foreach ($newsletter_ids as $newsletter_id)
  {
    $newsletter = simplenews_newsletter_load($newsletter_id);
    $handler = simplenews_issue_handler($node);
    $handler_settings = simplenews_issue_handler_settings($node);

    $recipient_handler = simplenews_get_recipient_handler($newsletter, $handler, $handler_settings);
    
    // To send the newsletter, the node id and target email addresses
    // are stored in the spool.
    // Only subscribed recipients are stored in the spool (status = 1).
    $select = $recipient_handler->buildRecipientQuery();
    $select->addExpression('\'node\'', 'entity_type');
    $select->addExpression($node->nid, 'entity_id');
    $select->addExpression(SIMPLENEWS_SUBSCRIPTION_STATUS_SUBSCRIBED, 'status');
    $select->addExpression(REQUEST_TIME, 'timestamp');
    $select->condition('s.snid', db_select('simplenews_mail_spool', 'r')->fields('r', array('snid'))->condition('entity_id', $node->nid, '='), 'NOT IN');

    db_insert('simplenews_mail_spool')
      ->from($select)
      ->execute();
  }

  // Update simplenews newsletter status to send pending.
  simplenews_issue_update_sent_status($node);

  // Notify other modules that a newsletter was just spooled.
  module_invoke_all('simplenews_spooled', $node);
}
neoxavier’s picture

StatusFileSize
new7.57 KB

Hello,

the patch attached basically combining the patch in #1 and the code in #4, I also did some coding-standard fix based on coder module.

I tested it and it work fine for me.

neoxavier’s picture

Status: Closed (fixed) » Needs review

I changed the status to needs review so other people can review patch #5 and close this if it works

annared’s picture

Hi,
is this working with simplenews_roles?

Thanks

PascalAnimateur’s picture

StatusFileSize
new7.31 KB

The overview table in /admin/content/simplenews doesn't display the # of unique subscribers.

I've modified the query in simplenews_count_subscriptions to take this into account.

Here's a revised patch, I will check for compatibility with simplenews_roles later today.

Status: Needs review » Needs work

The last submitted patch, 8: simplenews-7.x-2.x-dev-2153579-8.patch, failed testing.

PascalAnimateur’s picture

@annared : I made a patch for simplenews_roles and it works great ! See my comment on the issue here

daveiano’s picture

What about the 7.x-1.x branch? Release notes of the 7.x-2.x branch says: Do not use this, this is in heavy development mode and probably does not work.

So is it save to switch to 7.x-2.x branch?

PascalAnimateur’s picture

@daveiano : By looking at the code from 1.x, I agree with what's been said in #1417634: Addressing multiple lists regarding the amount of work it would require for that branch.

Concerning the stability of 2.x, although I haven't tested it thoroughly in production environment, my initial tests seem to indicate it is quite stable as it is.

For the record, here's the drush make file excerpt with the patches I'm currently using to have simplenews-2.x with roles synchronisation:

; Simplenews
projects[simplenews][version] = 2.x-dev
; Fix simplenews_rules for 2.x-dev
projects[simplenews][patch][1959790] = https://www.drupal.org/files/issues/simplenews-fix_simplenews_rules-1959790-2.patch
; Sending to multiple lists/groups
projects[simplenews][patch][2153579] = https://www.drupal.org/files/issues/simplenews-7.x-2.x-dev-2153579-8.patch
; Support multilingual newsletters using entity_translation
projects[simplenews][patch][2567145] = https://www.drupal.org/files/issues/simplenews-entity_translation_support-2567145-2.patch

; Simplenews Roles
projects[simplenews_roles][version] = 1.x-dev
; Support 2.x branch
projects[simplenews_roles][patch][2118665] = https://www.drupal.org/files/issues/simplenews_roles-support_simplenews_2x-2118665-2.patch

Hope this helps!

anybody’s picture

Status: Needs work » Needs review

Thank you very much for your work. I think we can finally set this to needs review again and see if the 2 tests still fail and why. Let's get this very important feature commited!

BTW, is there an active simplenews maintainer willing to apply the patch to the dev branch if the problems are fixed?

anybody’s picture

Assigned: XoRDy » Unassigned

Ok, the failing test doesn't seem to be due to this issue. Could you please re-trigger testing (for me it did not seem to work) and set this RTBC if tests succeed?

RTBC from me for #8.