$fields['gsid'] = GServer::getID($fields['baseurl'], true);
}
+ $fields['uri-id'] = ItemURI::getIdByURI($fields['url']);
+
if (empty($fields['created'])) {
$fields['created'] = DateTimeFormat::utcNow();
}
return 0;
}
- $contact = self::getByURL($url, false, ['id', 'network'], $uid);
+ $contact = self::getByURL($url, false, ['id', 'network', 'uri-id'], $uid);
if (!empty($contact)) {
$contact_id = $contact["id"];
- if (empty($update)) {
+ if (empty($update) && (!empty($contact['uri-id']) || is_bool($update))) {
Logger::debug('Contact found', ['url' => $url, 'uid' => $uid, 'update' => $update, 'cid' => $contact_id]);
return $contact_id;
}
{
if (Strings::normaliseLink($new_url) != Strings::normaliseLink($old_url)) {
Logger::notice('New URL differs from old URL', ['old' => $old_url, 'new' => $new_url]);
- // @todo It is to decide what to do when the URL is changed
+ return;
}
if (!DBA::update('contact', $fields, ['id' => $id])) {
// These fields aren't updated by this routine:
// 'xmpp', 'sensitive'
- $fields = ['uid', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
+ $fields = ['uid', 'uri-id', 'avatar', 'header', 'name', 'nick', 'location', 'keywords', 'about', 'subscribe',
'manually-approve', 'unsearchable', 'url', 'addr', 'batch', 'notify', 'poll', 'request', 'confirm', 'poco',
'network', 'alias', 'baseurl', 'gsid', 'forum', 'prv', 'contact-type', 'pubkey', 'last-item'];
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
$uid = $contact['uid'];
unset($contact['uid']);
+ $uriid = $contact['uri-id'];
+ unset($contact['uri-id']);
+
$pubkey = $contact['pubkey'];
unset($contact['pubkey']);
return false;
}
+ if (Strings::normaliseLink($ret['url']) != Strings::normaliseLink($contact['url'])) {
+ $cid = self::getIdForURL($ret['url']);
+ if (!empty($cid) && ($cid != $id)) {
+ Logger::notice('URL of contact changed.', ['id' => $id, 'new_id' => $cid, 'old' => $contact['url'], 'new' => $ret['url']]);
+ return self::updateFromProbeArray($cid, $ret);
+ }
+ }
+
if (isset($ret['hide']) && is_bool($ret['hide'])) {
$ret['unsearchable'] = $ret['hide'];
}
}
$update = false;
+ $guid = $ret['guid'] ?? '';
// make sure to not overwrite existing values with blank entries except some technical fields
$keep = ['batch', 'notify', 'poll', 'request', 'confirm', 'poco', 'baseurl'];
unset($ret['last-item']);
}
+ if (empty($uriid)) {
+ $update = true;
+ }
+
if (!empty($ret['photo']) && ($ret['network'] != Protocol::FEED)) {
self::updateAvatar($id, $ret['photo'], $update);
}
return true;
}
- $ret['nurl'] = Strings::normaliseLink($ret['url']);
+ if (empty($guid)) {
+ $ret['uri-id'] = ItemURI::getIdByURI($ret['url']);
+ } else {
+ $ret['uri-id'] = ItemURI::insert(['uri' => $ret['url'], 'guid' => $guid]);
+ }
+
+ $ret['nurl'] = Strings::normaliseLink($ret['url']);
$ret['updated'] = $updated;
- $ret['failed'] = false;
+ $ret['failed'] = false;
// Only fill the pubkey if it had been empty before. We have to prevent identity theft.
if (empty($pubkey) && !empty($new_pubkey)) {