From 10cb52bc00c90d872ff753eb1e75bca6a8d5bd1b Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 11 Sep 2021 12:43:46 +0000 Subject: [PATCH] Only add user contacts, alternate way to fetch public contact id --- src/Model/Contact/User.php | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Model/Contact/User.php b/src/Model/Contact/User.php index a23cd3a55a..7542130d91 100644 --- a/src/Model/Contact/User.php +++ b/src/Model/Contact/User.php @@ -45,7 +45,12 @@ class User */ public static function insertForContactArray(array $contact) { - if (!isset($contact['uid']) || (empty($contact['uri-id']) && empty($contact['url']))) { + if (empty($contact['uid'])) { + // We don't create entries for the public user - by now + return false; + } + + if (empty($contact['uri-id']) && empty($contact['url'])) { Logger::info('Missing contact details', ['contact' => $contact, 'callstack' => System::callstack(20)]); return false; } @@ -55,7 +60,9 @@ class User } $pcontact = Contact::selectFirst(['id'], ['uri-id' => $contact['uri-id'], 'uid' => 0]); - if (!DBA::isResult($pcontact)) { + if (!empty($contact['uri-id']) && DBA::isResult($pcontact)) { + $pcid = $pcontact['id']; + } elseif (empty($contact['url']) || !($pcid = Contact::getIdForURL($contact['url']))) { Logger::info('Public contact for user not found', ['uri-id' => $contact['uri-id'], 'uid' => $contact['uid']]); return false; } @@ -67,13 +74,13 @@ class User } $fields = DBStructure::getFieldsForTable('user-contact', $fields); - $fields['cid'] = $pcontact['id']; + $fields['cid'] = $pcid; $fields['uid'] = $contact['uid']; $fields['uri-id'] = $contact['uri-id']; - $ret = DBA::insert('user-contact', $fields, Database::INSERT_IGNORE); + $ret = DBA::insert('user-contact', $fields, Database::INSERT_UPDATE); - Logger::info('Inserted user contact', ['uid' => $contact['uid'], 'cid' => $pcontact['id'], 'uri-id' => $contact['uri-id'], 'ret' => $ret]); + Logger::info('Inserted user contact', ['uid' => $contact['uid'], 'cid' => $pcid, 'uri-id' => $contact['uri-id'], 'ret' => $ret]); return $ret; } @@ -103,7 +110,7 @@ class User if (!empty($update_fields)) { $contacts = DBA::select('contact', ['uri-id', 'uid'], $condition); while ($row = DBA::fetch($contacts)) { - if (empty($row['uri-id'])) { + if (empty($row['uri-id']) || empty($contact['uid'])) { continue; } $ret = DBA::update('user-contact', $update_fields, ['uri-id' => $row['uri-id'], 'uid' => $row['uid']]);