When synchronized deleting user does not remove subscription
coltrane - August 19, 2008 - 04:37
| Project: | Simplenews |
| Version: | 5.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | closed |
Description
With simplenews account synchronization on deleting a user does not remove their record from the table simplenews_subscriptions.

#1
Blocking the account works correctly, the a_status column of their simplenews_subscriptions record is changed to 0 but delete doesn't work correctly. The _simplenews_user_load() in simplenews_get_user_subscription() during the delete op of simplenews_user() is returning an account with uid 0 which keeps the delete sql from affecting the correct rows.
#2
Verified this in latest 5 branch.
From simplenews_user():
<?phpif (variable_get('simplenews_sync_account', FALSE)) {
// Delete subscription and all newsletter subscriptions when account is removed
$subscription = simplenews_get_user_subscription($account->mail);
db_query('DELETE FROM {simplenews_snid_tid} WHERE snid = %d', $subscription->snid);
db_query('DELETE FROM {simplenews_subscriptions} WHERE snid = %d', $subscription->snid);
}
?>
The DELETE FROM table simplenews_subscriptions could be altered to use account->uid but there needs to be a way to delete the record in table simplenews_snid_tid. First a select of it from simplenews_subscriptions would work ... but I think this needs feedback before I roll a patch.
#3
The attached patch should solve this problem.
When deleting a user user_load() can not be used anymore and simplenews_get_user_subscription() requires this function to get the subcriber's snid.
#4
Yes, the patch fixes the problem, thank you very much!
One small thing, though the select sql works I think its proper to use the table alias on the columns being selected. If this select ever became a join it would fail.
$snid = db_result(db_query("SELECT snid FROM {simplenews_subscriptions} s WHERE s.uid = %d", $account->uid));should be
$snid = db_result(db_query("SELECT s.snid FROM {simplenews_subscriptions} s WHERE s.uid = %d", $account->uid));Here's your patch rerolled with it.
#5
Thanks. Patch committed.
#6
Automatically closed -- issue fixed for two weeks with no activity.