From 66eab2b44fd5562e50375374ac3f8a8e28d8dada Mon Sep 17 00:00:00 2001 From: Michael Vogel Date: Thu, 29 Aug 2019 07:22:29 +0200 Subject: [PATCH] Don't handle deleted contacts / removed unneeded parameter --- src/Database/PostUpdate.php | 4 ++-- src/Model/Contact.php | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 651766fcfe..2e3af8597b 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -436,8 +436,8 @@ class PostUpdate $contacts = DBA::p("SELECT ANY_VALUE(`id`) AS `id`, ANY_VALUE(`nurl`) AS `nurl` FROM `contact` WHERE EXISTS (SELECT `nurl` FROM `contact` AS `c2` - WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?)) - AND (`network` IN (?, ?, ?) OR (`uid` = ?)) GROUP BY `nurl`, `uid`", + WHERE `c2`.`nurl` = `contact`.`nurl` AND `c2`.`id` != `contact`.`id` AND `c2`.`uid` = `contact`.`uid` AND `c2`.`network` IN (?, ?, ?) AND NOT `deleted`) + AND (`network` IN (?, ?, ?) OR (`uid` = ?)) AND NOT `deleted` GROUP BY `nurl`, `uid`", Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, Protocol::DIASPORA, Protocol::OSTATUS, Protocol::ACTIVITYPUB, 0); diff --git a/src/Model/Contact.php b/src/Model/Contact.php index ca3ac4411b..b0e8ec6133 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -149,14 +149,14 @@ class Contact extends BaseObject public static function insert($param, $on_duplicate_update = false) { $ret = DBA::insert('contact', $param, $on_duplicate_update); - $contact = DBA::selectFirst('contact', ['nurl', 'uid', 'id'], ['id' => DBA::lastInsertId()]); + $contact = DBA::selectFirst('contact', ['nurl', 'uid'], ['id' => DBA::lastInsertId()]); if (!DBA::isResult($contact)) { // Shouldn't happen return $ret; } // Search for duplicated contacts and get rid of them - self::handleDuplicates($contact['nurl'], $contact['uid'], $contact['id']); + self::handleDuplicates($contact['nurl'], $contact['uid']); return $ret; } @@ -1878,7 +1878,7 @@ class Contact extends BaseObject } // Search for duplicated contacts and get rid of them - if (self::handleDuplicates(Strings::normaliseLink($url), $uid, $id) || ($uid != 0)) { + if (self::handleDuplicates(Strings::normaliseLink($url), $uid) || ($uid != 0)) { return; } @@ -1927,13 +1927,13 @@ class Contact extends BaseObject */ public static function handleDuplicateByID($contact_id) { - $contact = DBA::selectFirst('contact', ['nurl', 'uid', 'id'], ['id' => $contact_id]); + $contact = DBA::selectFirst('contact', ['nurl', 'uid'], ['id' => $contact_id, 'deleted' => false]); if (!DBA::isResult($contact)) { return; } // Search for duplicated contacts and get rid of them - self::handleDuplicates($contact['nurl'], $contact['uid'], $contact['id']); + self::handleDuplicates($contact['nurl'], $contact['uid']); return; } @@ -1943,11 +1943,10 @@ class Contact extends BaseObject * * @param string $nurl Normalised contact url * @param integer $uid User id - * @param integer $id Contact id of a duplicate * @return boolean * @throws \Exception */ - private static function handleDuplicates($nurl, $uid, $id) + private static function handleDuplicates($nurl, $uid) { $condition = ['nurl' => $nurl, 'uid' => $uid, 'deleted' => false, 'network' => Protocol::FEDERATED]; $count = DBA::count('contact', $condition); @@ -1962,7 +1961,7 @@ class Contact extends BaseObject } $first = $first_contact['id']; - Logger::info('Found duplicates', ['count' => $count, 'id' => $id, 'first' => $first, 'uid' => $uid, 'nurl' => $nurl]); + Logger::info('Found duplicates', ['count' => $count, 'first' => $first, 'uid' => $uid, 'nurl' => $nurl]); if (($uid != 0 && ($first_contact['network'] == Protocol::DFRN))) { // Don't handle non public DFRN duplicates by now (legacy DFRN is very special because of the key handling) Logger::info('Not handling non public DFRN duplicate', ['uid' => $uid, 'nurl' => $nurl]); -- 2.39.5