With simplenews account synchronization on deleting a user does not remove their record from the table simplenews_subscriptions.

Comments

coltrane’s picture

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.

coltrane’s picture

Version: 5.x-1.4 » 5.x-1.x-dev

Verified this in latest 5 branch.

From simplenews_user():

if (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.

sutharsan’s picture

Status: Active » Needs review
StatusFileSize
new1.42 KB

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.

coltrane’s picture

StatusFileSize
new1.42 KB

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.

sutharsan’s picture

Status: Needs review » Fixed

Thanks. Patch committed.

Anonymous’s picture

Status: Fixed » Closed (fixed)

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