From c1eea3771feb57d2f56a614b2aab1b335f41a625 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Jan 2017 13:57:03 +0000 Subject: [PATCH 1/2] Bugfix: Sometimes the self contact seems to destroy itself --- include/Contact.php | 8 +++++--- mod/dfrn_request.php | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 15b6813714..362bce1bac 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -60,11 +60,13 @@ function user_remove($uid) { function contact_remove($id) { - $r = q("select uid from contact where id = %d limit 1", + // We want just to make sure that we don't delete our "self" contact + $r = q("SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1", intval($id) ); - if((! dbm::is_result($r)) || (! intval($r[0]['uid']))) + if((! dbm::is_result($r)) || (! intval($r[0]['uid']))) { return; + } $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts'); if($archive) { @@ -571,7 +573,7 @@ function get_contact($url, $uid = 0, $no_update = false) { } if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != "")) - q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d", + q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d AND NOT `self`", dbesc(normalise_link($url)), intval($contactid)); diff --git a/mod/dfrn_request.php b/mod/dfrn_request.php index 6480f2c756..52b5eb9f90 100644 --- a/mod/dfrn_request.php +++ b/mod/dfrn_request.php @@ -301,7 +301,7 @@ function dfrn_request_post(App $a) { if (dbm::is_result($r)) { foreach ($r as $rr) { if(! $rr['rel']) { - q("DELETE FROM `contact` WHERE `id` = %d", + q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); } @@ -326,7 +326,7 @@ function dfrn_request_post(App $a) { if (dbm::is_result($r)) { foreach ($r as $rr) { if(! $rr['rel']) { - q("DELETE FROM `contact` WHERE `id` = %d", + q("DELETE FROM `contact` WHERE `id` = %d AND NOT `self`", intval($rr['cid']) ); } From ac88471e5599bd1217edc47ccb7d208c044c0e11 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 29 Jan 2017 14:00:44 +0000 Subject: [PATCH 2/2] Make the code nicer --- include/Contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index 362bce1bac..32ee0ab95c 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -64,12 +64,12 @@ function contact_remove($id) { $r = q("SELECT `uid` FROM `contact` WHERE `id` = %d AND NOT `self` LIMIT 1", intval($id) ); - if((! dbm::is_result($r)) || (! intval($r[0]['uid']))) { + if (!dbm::is_result($r) || !intval($r[0]['uid'])) { return; } $archive = get_pconfig($r[0]['uid'], 'system','archive_removed_contacts'); - if($archive) { + if ($archive) { q("update contact set `archive` = 1, `network` = 'none', `writable` = 0 where id = %d", intval($id) );