I am using the Simplenews Roles module on d5. Yes, I know that this module is no longer supported but it's worked perfectly for me. I use it to automatically subscribe users that purchase a certain item.

I am now wanting to setup a basic Mailing List in addition to my subscriptions. If you are familiar with Simplenews Roles, you know that as cron runs it checks the roles of each user and subscribes them or unsubscribes them to certain newsletters based on those roles. Well, this is where the problem comes in. The mailing list is for anonymous users, as you can imagine, each time cron runs it clears the anonymous users from the list.

The module is only 100 lines of code and I think this is the part that needs edited. I want to hard code it so that it just excludes the newsletter. The $tid of the newsletter is "349". Here is the portion of code that I think handles finding the newsletters that need checked.

function simplenews_roles_cron() {
  foreach(variable_get('simplenews_roles_tids_rids', array()) as $tid => $rids) {
  simplenews_roles_update_subscriptions($tid, $rids);
  }
}

My thinking was to just remove 349 from the array. Think this would work?

To give more background, here is the code that follows right after the above portion:

function simplenews_roles_form_alter($form_id, &$form) {
  if ($form_id == 'simplenews_admin_types_form' && !empty($form['tid']['#value'])) {
    $form['#submit']['simplenews_roles_newsletter_submit'] = array();
    $role_newsletters = variable_get('simplenews_roles_tids_rids', array());

    $form['roles'] = array(
      '#type' => 'checkboxes',
      '#title' => t('Automatically subscribe users in the following roles to this newsletter'),
      '#options' => user_roles(TRUE),
      '#default_value' => isset($role_newsletters[$form['tid']['#value']]) ? $role_newsletters[$form['tid']['#value']] : '',
      '#description' => t('This newsletter subscription list will consist of only users in the selected roles. This newsletter subscription is automatically syncronized so any users manually added to this list will be removed if they are not in any of the selected roles.'),
      '#weight' => 10,
    );
  }
}

Comments

joachim’s picture

I'm pretty sure that if you don't set any roles to synchronize, then SNR won't touch that newsletter's subscriptions. At least that's what the UI claims.

interestingaftermath’s picture

Unfortunately that is not the case as far as I can tell. That would make the most sense for my solution though. Any other ideas?

This is really important so I may end up paying someone to fix this PHP for me.

joachim’s picture

Status: Active » Postponed (maintainer needs more info)

Could you output the value of your variable?

Do:

dsm(variable_get('simplenews_roles_tids_rids', array()));

interestingaftermath’s picture

Needless to say, I am a PHP beginner. What would this do?

I imagine it would output the values so that I could make sure I am referencing the correct element?

joachim’s picture

Install devel, enable PHP block.

interestingaftermath’s picture

Are you talking about the Execute PHP block?

joachim’s picture

Yes.

interestingaftermath’s picture

So, do this?

function simplenews_roles_cron() {
  foreach(variable_get('simplenews_roles_tids_rids', array()) as $tid => $rids) {
  simplenews_roles_update_subscriptions($tid, $rids);
  dsm(variable_get('simplenews_roles_tids_rids', array()));
  }
}

and then enable the Execute PHP block? Then what? I'm sorry if I am totally missing something. I am not completely retarded but you're not giving me much to go on. I really appreciate the help though!

joachim’s picture

um, no.

Put JUST this in your php block to get the value:
dsm(variable_get('simplenews_roles_tids_rids', array()));

the aim is to output (dsm) the value of the stored variable simplenews_roles_tids_rids to see why your system is messing up.

or now you have devl installed, just go to the variable editor and find it in the list.

interestingaftermath’s picture

Sorry about that. Here is the result of running the string you gave me in the Execute PHP block. 349 is the newsletter I am trying to exclude.

Array
(
    [24] => Array
        (
            [13] => 13
            [14] => 14
            [15] => 15
            [7] => 0
            [12] => 0
            [2] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [8] => 0
            [10] => 0
            [11] => 0
            [9] => 0
        )

    [25] => Array
        (
            [14] => 14
            [15] => 15
            [7] => 0
            [12] => 0
            [2] => 0
            [13] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [8] => 0
            [10] => 0
            [11] => 0
            [9] => 0
        )

    [26] => Array
        (
            [15] => 15
            [7] => 0
            [12] => 0
            [2] => 0
            [13] => 0
            [14] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [8] => 0
            [10] => 0
            [11] => 0
            [9] => 0
        )

    [237] => Array
        (
            [7] => 7
            [12] => 0
            [2] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [8] => 0
            [10] => 0
            [11] => 0
            [9] => 0
        )

    [349] => Array
        (
            [] => 1
            [7] => 0
            [12] => 0
            [2] => 0
            [13] => 0
            [14] => 0
            [15] => 0
            [3] => 0
            [4] => 0
            [5] => 0
            [6] => 0
            [8] => 0
            [10] => 0
            [11] => 0
            [9] => 0
        )

)
interestingaftermath’s picture

Any ideas? I really need to figure this out to have the newsletter setup tonight.

joachim’s picture

Status: Postponed (maintainer needs more info) » Active

Well it's just gone midnight my time, so it's not gonna happen by the end of your day whatever timezone you're in.
I have a hunch I know what it is, hope to get onto it tomorrow if dayjob stuff allows.

Also, please don't bump an issue just to ask about progress, not after a matter of mere hours.

joachim’s picture

I think I've fixed this.
Please try the dev release once it has been updated by the packaging script and report back :)

You should probably delete the variable first, as my testing showed crud was building up in the array -- use the devel module for that.

interestingaftermath’s picture

Thanks! This release appears to work like a charm. Just to confirm, is this how it now works: If a newsletter has roles selected that are automatically added as subscribers then those newsletters only allow those roles to be subscribed. If no roles are selected than anyone can subscribe?

Thanks so much!

joachim’s picture

Category: support » bug
Status: Active » Fixed

Yup -- selecting roles means they synchonize.
I think you can still sign up manually if the permissions exist, but things will get reset at next cron run.
If no roles are selected, it's as if the module were not installed.

Status: Fixed » Closed (fixed)

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