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.
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | simplenews-snid-sort.patch | 732 bytes | mrfelton |
| #2 | simplenews.374253.patch | 1.02 KB | sutharsan |
Comments
Comment #1
sutharsan commentedChanging the if clause and the order of subscribe and unsubscribe will probably do. Good thinking! I will make a patch shortly.
Comment #2
sutharsan commentedThe attached patch should solve it, please test and report.
Comment #3
mrfelton commentedThis isn't quite right.. arsort() return a boolean. See revised patch - it works for me.
Comment #4
sutharsan commentedThanks for testing. Patch committed.
Comment #5
sutharsan commented