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

coltrane - August 19, 2008 - 04:58

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

coltrane - August 19, 2008 - 05:50
Version:5.x-1.4» 5.x-1.x-dev

Verified this in latest 5 branch.

From simplenews_user():

<?php
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.

#3

Sutharsan - August 21, 2008 - 10:56
Status:active» patch (code needs review)

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.

AttachmentSize
simplenews.297041.patch1.42 KB

#4

coltrane - August 23, 2008 - 20:35

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.

AttachmentSize
simplenews.297041-4.patch1.42 KB

#5

Sutharsan - August 24, 2008 - 09:01
Status:patch (code needs review)» fixed

Thanks. Patch committed.

#6

Anonymous (not verified) - September 11, 2008 - 05:32
Status:fixed» closed

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

 
 

Drupal is a registered trademark of Dries Buytaert.