I'm trying to write a custom extension to simplenews, but I keep running in to trouble due to the way that my users snid keeps changing. This happens in simplenews_subscription_manager_form_submit():

function simplenews_subscription_manager_form_submit($form, &$form_state) {
  
  switch ($form_state['values']['op']) {
    case t('Update'):
      foreach ($form_state['values']['newsletters'] as $tid => $checked) {
        if ($checked) {
          simplenews_subscribe_user($form_state['values']['mail'], $tid, FALSE);
        }
        else {
          simplenews_unsubscribe_user($form_state['values']['mail'], $tid, FALSE);
        }
      }

As it loops over the newsletters, it either unsubscribes or subscribes each one. If at some point in the loop, the last of a users subscriptions are removed, then their subscription account will be deleted. Then, later on in this loop, if one of the items is checked, a new subscription account is created and the user ends up with a new snid. I guess you could fix this by sorting the array first and processing the subscription requests before unsubscription requests.

Comments

sutharsan’s picture

Assigned: Unassigned » sutharsan

Changing the if clause and the order of subscribe and unsubscribe will probably do. Good thinking! I will make a patch shortly.

sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new1.02 KB

The attached patch should solve it, please test and report.

mrfelton’s picture

StatusFileSize
new732 bytes

This isn't quite right.. arsort() return a boolean. See revised patch - it works for me.

sutharsan’s picture

Status: Needs review » Fixed

Thanks for testing. Patch committed.

sutharsan’s picture

Assigned: sutharsan » Unassigned

Status: Fixed » Closed (fixed)

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