Handles issue 6122 - the self contact will be updated when it seems to be invalid

This commit is contained in:
Michael 2018-12-22 20:12:32 +00:00
parent 6f8c9a08a1
commit faa30adf68
2 changed files with 19 additions and 5 deletions

View File

@ -460,7 +460,8 @@ class Contact extends BaseObject
public static function updateSelfFromUserID($uid, $update_avatar = false) public static function updateSelfFromUserID($uid, $update_avatar = false)
{ {
$fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'gender', 'avatar', $fields = ['id', 'name', 'nick', 'location', 'about', 'keywords', 'gender', 'avatar',
'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'nurl']; 'xmpp', 'contact-type', 'forum', 'prv', 'avatar-date', 'url', 'nurl',
'photo', 'thumb', 'micro', 'addr', 'request', 'notify', 'poll', 'confirm', 'poco'];
$self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]); $self = DBA::selectFirst('contact', $fields, ['uid' => $uid, 'self' => true]);
if (!DBA::isResult($self)) { if (!DBA::isResult($self)) {
return; return;
@ -523,15 +524,15 @@ class Contact extends BaseObject
$fields['nurl'] = Strings::normaliseLink($fields['url']); $fields['nurl'] = Strings::normaliseLink($fields['url']);
$fields['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3); $fields['addr'] = $user['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
$fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname']; $fields['request'] = System::baseUrl() . '/dfrn_request/' . $user['nickname'];
$fields['notify'] = System::baseUrl() . '/dfrn_notify/' . $user['nickname']; $fields['notify'] = System::baseUrl() . '/dfrn_notify/' . $user['nickname'];
$fields['poll'] = System::baseUrl() . '/dfrn_poll/' . $user['nickname']; $fields['poll'] = System::baseUrl() . '/dfrn_poll/'. $user['nickname'];
$fields['confirm'] = System::baseUrl() . '/dfrn_confirm/' . $user['nickname']; $fields['confirm'] = System::baseUrl() . '/dfrn_confirm/' . $user['nickname'];
$fields['poco'] = System::baseUrl() . '/poco/' . $user['nickname']; $fields['poco'] = System::baseUrl() . '/poco/' . $user['nickname'];
$update = false; $update = false;
foreach ($fields as $field => $content) { foreach ($fields as $field => $content) {
if (isset($self[$field]) && $self[$field] != $content) { if ($self[$field] != $content) {
$update = true; $update = true;
} }
} }

View File

@ -98,6 +98,19 @@ class User
if (!DBA::isResult($r)) { if (!DBA::isResult($r)) {
return false; return false;
} }
if (empty($r['nickname'])) {
return false;
}
// Check if the returned data is valid, otherwise fix it. See issue #6122
$url = System::baseUrl() . '/profile/' . $r['nickname'];
$addr = $r['nickname'] . '@' . substr(System::baseUrl(), strpos(System::baseUrl(), '://') + 3);
if (($addr != $r['addr']) || ($r['url'] != $url) || ($r['nurl'] != Strings::normaliseLink($r['url']))) {
Contact::updateSelfFromUserID($uid);
}
return $r; return $r;
} }