Avoid update of non native contacts, fix most warnings

This commit is contained in:
Michael 2019-04-09 11:28:45 +00:00
parent 00071abf51
commit d58147413f

View file

@ -1241,11 +1241,11 @@ class Contact extends BaseObject
/// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following /// @todo Verify if we can't use Contact::getDetailsByUrl instead of the following
// We first try the nurl (http://server.tld/nick), most common case // We first try the nurl (http://server.tld/nick), most common case
$contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false]); $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], ['nurl' => Strings::normaliseLink($url), 'uid' => $uid, 'deleted' => false]);
// Then the addr (nick@server.tld) // Then the addr (nick@server.tld)
if (!DBA::isResult($contact)) { if (!DBA::isResult($contact)) {
$contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], ['addr' => $url, 'uid' => $uid, 'deleted' => false]); $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], ['addr' => $url, 'uid' => $uid, 'deleted' => false]);
} }
// Then the alias (which could be anything) // Then the alias (which could be anything)
@ -1253,7 +1253,7 @@ class Contact extends BaseObject
// The link could be provided as http although we stored it as https // The link could be provided as http although we stored it as https
$ssl_url = str_replace('http://', 'https://', $url); $ssl_url = str_replace('http://', 'https://', $url);
$condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid]; $condition = ['`alias` IN (?, ?, ?) AND `uid` = ? AND NOT `deleted`', $url, Strings::normaliseLink($url), $ssl_url, $uid];
$contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated'], $condition); $contact = DBA::selectFirst('contact', ['id', 'avatar', 'updated', 'network'], $condition);
} }
if (DBA::isResult($contact)) { if (DBA::isResult($contact)) {
@ -1268,7 +1268,7 @@ class Contact extends BaseObject
} }
// Update the contact in the background if needed but it is called by the frontend // Update the contact in the background if needed but it is called by the frontend
if ($update_contact && $no_update) { if ($update_contact && $no_update && in_array($contact['network'], Protocol::NATIVE_SUPPORT)) {
Worker::add(PRIORITY_LOW, "UpdateContact", $contact_id); Worker::add(PRIORITY_LOW, "UpdateContact", $contact_id);
} }
@ -1324,26 +1324,26 @@ class Contact extends BaseObject
$fields = [ $fields = [
'uid' => $uid, 'uid' => $uid,
'created' => DateTimeFormat::utcNow(), 'created' => DateTimeFormat::utcNow(),
'url' => $data["url"], 'url' => $data['url'],
'nurl' => Strings::normaliseLink($data["url"]), 'nurl' => Strings::normaliseLink($data['url']),
'addr' => $data["addr"], 'addr' => defaults($data, 'addr', ''),
'alias' => $data["alias"], 'alias' => defaults($data, 'alias', ''),
'notify' => $data["notify"], 'notify' => defaults($data, 'notify', ''),
'poll' => $data["poll"], 'poll' => defaults($data, 'poll', ''),
'name' => $data["name"], 'name' => defaults($data, 'name', ''),
'nick' => $data["nick"], 'nick' => defaults($data, 'nick', ''),
'photo' => $data["photo"], 'photo' => defaults($data, 'photo', ''),
'keywords' => $data["keywords"], 'keywords' => defaults($data, 'keywords', ''),
'location' => $data["location"], 'location' => defaults($data, 'location', ''),
'about' => $data["about"], 'about' => defaults($data, 'about', ''),
'network' => $data["network"], 'network' => $data['network'],
'pubkey' => $data["pubkey"], 'pubkey' => defaults($data, 'pubkey', ''),
'rel' => self::SHARING, 'rel' => self::SHARING,
'priority' => $data["priority"], 'priority' => defaults($data, 'priority', 0),
'batch' => $data["batch"], 'batch' => defaults($data, 'batch', ''),
'request' => $data["request"], 'request' => defaults($data, 'request', ''),
'confirm' => $data["confirm"], 'confirm' => defaults($data, 'confirm', ''),
'poco' => $data["poco"], 'poco' => defaults($data, 'poco', ''),
'name-date' => DateTimeFormat::utcNow(), 'name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(), 'uri-date' => DateTimeFormat::utcNow(),
'avatar-date' => DateTimeFormat::utcNow(), 'avatar-date' => DateTimeFormat::utcNow(),
@ -1373,13 +1373,13 @@ class Contact extends BaseObject
$gcontact = DBA::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => Strings::normaliseLink($data["url"])]); $gcontact = DBA::selectFirst('gcontact', ['location', 'about', 'keywords', 'gender'], ['nurl' => Strings::normaliseLink($data["url"])]);
if (DBA::isResult($gcontact)) { if (DBA::isResult($gcontact)) {
// Only use the information when the probing hadn't fetched these values // Only use the information when the probing hadn't fetched these values
if ($data['keywords'] != '') { if (!empty($data['keywords'])) {
unset($gcontact['keywords']); unset($gcontact['keywords']);
} }
if ($data['location'] != '') { if (!empty($data['location'])) {
unset($gcontact['location']); unset($gcontact['location']);
} }
if ($data['about'] != '') { if (!empty($data['about'])) {
unset($gcontact['about']); unset($gcontact['about']);
} }
DBA::update('contact', $gcontact, ['id' => $contact_id]); DBA::update('contact', $gcontact, ['id' => $contact_id]);
@ -1410,30 +1410,30 @@ class Contact extends BaseObject
'name' => $data['name'], 'name' => $data['name'],
'nick' => $data['nick']]; 'nick' => $data['nick']];
if ($data['keywords'] != '') { if (!empty($data['keywords'])) {
$updated['keywords'] = $data['keywords']; $updated['keywords'] = $data['keywords'];
} }
if ($data['location'] != '') { if (!empty($data['location'])) {
$updated['location'] = $data['location']; $updated['location'] = $data['location'];
} }
// Update the technical stuff as well - if filled // Update the technical stuff as well - if filled
if ($data['notify'] != '') { if (!empty($data['notify'])) {
$updated['notify'] = $data['notify']; $updated['notify'] = $data['notify'];
} }
if ($data['poll'] != '') { if (!empty($data['poll'])) {
$updated['poll'] = $data['poll']; $updated['poll'] = $data['poll'];
} }
if ($data['batch'] != '') { if (!empty($data['batch'])) {
$updated['batch'] = $data['batch']; $updated['batch'] = $data['batch'];
} }
if ($data['request'] != '') { if (!empty($data['request'])) {
$updated['request'] = $data['request']; $updated['request'] = $data['request'];
} }
if ($data['confirm'] != '') { if (!empty($data['confirm'])) {
$updated['confirm'] = $data['confirm']; $updated['confirm'] = $data['confirm'];
} }
if ($data['poco'] != '') { if (!empty($data['poco'])) {
$updated['poco'] = $data['poco']; $updated['poco'] = $data['poco'];
} }
@ -1726,7 +1726,11 @@ class Contact extends BaseObject
$ret = Probe::uri($contact['url'], $network, $uid, !$force); $ret = Probe::uri($contact['url'], $network, $uid, !$force);
// If Probe::uri fails the network code will be different (mostly "feed" or "unkn") // If Probe::uri fails the network code will be different (mostly "feed" or "unkn")
if ((in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM])) && ($ret['network'] != $contact['network'])) { if (in_array($ret['network'], [Protocol::FEED, Protocol::PHANTOM]) && ($ret['network'] != $contact['network'])) {
return false;
}
if (!in_array($ret['network'], Protocol::NATIVE_SUPPORT)) {
return false; return false;
} }