From 2df14fab3b444a4d8c1c39f55cbdb7bbd964d5b7 Mon Sep 17 00:00:00 2001 From: Michael Date: Sun, 30 May 2021 12:04:26 +0000 Subject: [PATCH] Ensure that the public contact exists when a user is created --- src/Model/Contact.php | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/src/Model/Contact.php b/src/Model/Contact.php index aa6f4c75c..cd4e608ea 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -566,18 +566,13 @@ class Contact */ public static function createSelfFromUserId($uid) { - // Only create the entry if it doesn't exist yet - if (DBA::exists('contact', ['uid' => $uid, 'self' => true])) { - return true; - } - $user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'pubkey', 'prvkey'], ['uid' => $uid, 'account_expired' => false]); if (!DBA::isResult($user)) { return false; } - $return = DBA::insert('contact', [ + $contact = [ 'uid' => $user['uid'], 'created' => DateTimeFormat::utcNow(), 'self' => 1, @@ -602,7 +597,23 @@ class Contact 'uri-date' => DateTimeFormat::utcNow(), 'avatar-date' => DateTimeFormat::utcNow(), 'closeness' => 0 - ]); + ]; + + $return = true; + + // Only create the entry if it doesn't exist yet + if (!DBA::exists('contact', ['uid' => $uid, 'self' => true])) { + $return = DBA::insert('contact', $contact); + } + + // Create the public contact + if (!DBA::exists('contact', ['nurl' => $contact['nurl'], 'uid' => 0])) { + $contact['self'] = false; + $contact['uid'] = 0; + $contact['prvkey'] = null; + + DBA::insert('contact', $contact, Database::INSERT_IGNORE); + } return $return; }