New fields in contact table / don't update on probe

This commit is contained in:
Michael 2019-07-04 04:08:55 +00:00
parent 7b0a9ffd89
commit ef5be9668f
9 changed files with 39 additions and 129 deletions

View file

@ -270,10 +270,7 @@ class APContact extends BaseObject
}
// Update the gcontact table
// These two fields don't exist in the gcontact table
unset($contact_fields['forum']);
unset($contact_fields['prv']);
DBA::update('gcontact', $contact_fields, ['nurl' => Strings::normaliseLink($url)]);
GContact::updateFromPublicContactURL($url);
Logger::log('Updated profile for ' . $url, Logger::DEBUG);

View file

@ -1400,6 +1400,7 @@ class Contact extends BaseObject
'request' => defaults($data, 'request', ''),
'confirm' => defaults($data, 'confirm', ''),
'poco' => defaults($data, 'poco', ''),
'baseurl' => defaults($data, 'baseurl', ''),
'name-date' => DateTimeFormat::utcNow(),
'uri-date' => DateTimeFormat::utcNow(),
'avatar-date' => DateTimeFormat::utcNow(),
@ -1453,7 +1454,7 @@ class Contact extends BaseObject
self::updateAvatar($data['photo'], $uid, $contact_id);
}
$fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'pubkey'];
$fields = ['url', 'nurl', 'addr', 'alias', 'name', 'nick', 'keywords', 'location', 'about', 'avatar-date', 'pubkey', 'baseurl'];
$contact = DBA::selectFirst('contact', $fields, ['id' => $contact_id]);
// This condition should always be true
@ -1467,7 +1468,8 @@ class Contact extends BaseObject
'url' => $data['url'],
'nurl' => Strings::normaliseLink($data['url']),
'name' => $data['name'],
'nick' => $data['nick']
'nick' => $data['nick'],
'baseurl' => $data['baseurl']
];
if (!empty($data['keywords'])) {
@ -1820,7 +1822,7 @@ class Contact extends BaseObject
*/
$fields = ['avatar', 'uid', 'name', 'nick', 'url', 'addr', 'batch', 'notify',
'poll', 'request', 'confirm', 'poco', 'network', 'alias'];
'poll', 'request', 'confirm', 'poco', 'network', 'alias', 'baseurl'];
$contact = DBA::selectFirst('contact', $fields, ['id' => $id]);
if (!DBA::isResult($contact)) {
return false;
@ -1849,7 +1851,7 @@ class Contact extends BaseObject
// make sure to not overwrite existing values with blank entries
foreach ($ret as $key => $val) {
if (!isset($contact[$key])) {
if (!array_key_exists($key, $contact)) {
unset($ret[$key]);
} elseif (($contact[$key] != '') && ($val == '')) {
$ret[$key] = $contact[$key];
@ -2082,6 +2084,7 @@ class Contact extends BaseObject
'name' => $ret['name'],
'nick' => $ret['nick'],
'network' => $ret['network'],
'baseurl' => $ret['baseurl'],
'protocol' => $protocol,
'pubkey' => $ret['pubkey'],
'rel' => $new_relation,

View file

@ -873,20 +873,20 @@ class GContact
* @brief Updates the gcontact entry from a given public contact url
*
* @param string $url contact url
* @return void
* @return integer gcontact id
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
public static function updateFromPublicContactURL($url)
{
self::updateFromPublicContact(['nurl' => Strings::normaliseLink($url)]);
return self::updateFromPublicContact(['nurl' => Strings::normaliseLink($url)]);
}
/**
* @brief Helper function for updateFromPublicContactID and updateFromPublicContactURL
*
* @param array $condition contact condition
* @return void
* @return integer gcontact id
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
* @throws \ImagickException
*/
@ -894,19 +894,18 @@ class GContact
{
$fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gender',
'bd', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archive', 'term-date',
'created', 'updated', 'avatar', 'success_update', 'failure_update', 'forum', 'prv'];
'created', 'updated', 'avatar', 'success_update', 'failure_update', 'forum', 'prv',
'baseurl', 'sensitive', 'unsearchable'];
$contact = DBA::selectFirst('contact', $fields, array_merge($condition, ['uid' => 0, 'network' => Protocol::FEDERATED]));
if (!DBA::isResult($contact)) {
return;
return 0;
}
// These fields cannot be updated, since they don't exist in the contact table
// hide, nsfw, server_url
// "connect" does exist, but seems to contain the same as "addr"
$fields = ['name', 'nick', 'url', 'nurl', 'location', 'about', 'keywords', 'gender', 'generation',
'birthday', 'contact-type', 'network', 'addr', 'notify', 'alias', 'archived', 'archive_date',
'created', 'updated', 'photo', 'last_contact', 'last_failure', 'community', 'connect'];
'created', 'updated', 'photo', 'last_contact', 'last_failure', 'community', 'connect',
'server_url', 'nsfw', 'hide', 'id'];
$old_gcontact = DBA::selectFirst('gcontact', $fields, ['nurl' => $contact['nurl']]);
$do_insert = !DBA::isResult($old_gcontact);
@ -917,6 +916,12 @@ class GContact
$gcontact = $contact;
// These fields are having different names but the same content
$gcontact['server_url'] = $gcontact['baseurl'];
unset($gcontact['baseurl']);
$gcontact['nsfw'] = $gcontact['sensitive'];
unset($gcontact['sensitive']);
$gcontact['hide'] = $gcontact['unsearchable'];
unset($gcontact['unsearchable']);
$gcontact['archived'] = $gcontact['archive'];
unset($gcontact['archive']);
$gcontact['archive_date'] = $gcontact['term-date'];
@ -958,8 +963,10 @@ class GContact
if (!$do_insert) {
DBA::update('gcontact', $gcontact, ['nurl' => $contact['nurl']], $old_gcontact);
return $old_gcontact['id'];
} elseif (!$gcontact['archived']) {
DBA::insert('gcontact', $gcontact);
return DBA::lastInsertId();
}
}