Merge pull request #10341 from annando/create-public-contact
Ensure that the public contact exists when a user is created
This commit is contained in:
commit
4e0e7d7f3d
1 changed files with 18 additions and 7 deletions
|
@ -566,18 +566,13 @@ class Contact
|
||||||
*/
|
*/
|
||||||
public static function createSelfFromUserId($uid)
|
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'],
|
$user = DBA::selectFirst('user', ['uid', 'username', 'nickname', 'pubkey', 'prvkey'],
|
||||||
['uid' => $uid, 'account_expired' => false]);
|
['uid' => $uid, 'account_expired' => false]);
|
||||||
if (!DBA::isResult($user)) {
|
if (!DBA::isResult($user)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$return = DBA::insert('contact', [
|
$contact = [
|
||||||
'uid' => $user['uid'],
|
'uid' => $user['uid'],
|
||||||
'created' => DateTimeFormat::utcNow(),
|
'created' => DateTimeFormat::utcNow(),
|
||||||
'self' => 1,
|
'self' => 1,
|
||||||
|
@ -602,7 +597,23 @@ class Contact
|
||||||
'uri-date' => DateTimeFormat::utcNow(),
|
'uri-date' => DateTimeFormat::utcNow(),
|
||||||
'avatar-date' => DateTimeFormat::utcNow(),
|
'avatar-date' => DateTimeFormat::utcNow(),
|
||||||
'closeness' => 0
|
'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;
|
return $return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue