New table for relations between global contacts - will replace glink in the future

This commit is contained in:
Michael 2020-03-06 08:08:49 +00:00
parent 10d866bad9
commit bd77556b49
3 changed files with 39 additions and 3 deletions

View file

@ -1299,10 +1299,25 @@ class GContact
}
if (!empty($followers) || !empty($followings)) {
$gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(($url))]);
$gcid = $gcontact['id'];
if (!empty($followers)) {
// Clear the follower list, since it will be recreated in the next step
DBA::delete('gfollower', ['gcid' => $gcid]);
}
$contacts = array_unique(array_merge($followers, $followings));
Logger::info('Discover AP contacts', ['url' => $url, 'contacts' => count($contacts)]);
foreach ($contacts as $contact) {
if (DBA::exists('gcontact', ['nurl' => Strings::normaliseLink(($contact))])) {
$gcontact = DBA::selectFirst('gcontact', ['id'], ['nurl' => Strings::normaliseLink(($contact))]);
if (DBA::isResult($gcontact)) {
if (in_array($contact, $followers)) {
$fields = ['gcid' => $gcid, 'follower-gcid' => $gcontact['id']];
} elseif (in_array($contact, $followings)) {
$fields = ['gcid' => $gcontact['id'], 'follower-gcid' => $gcid];
}
Logger::info('Set relation between contacts', $fields);
DBA::update('gfollower', $fields, $fields, true);
continue;
}
Logger::info('Discover new AP contact', ['url' => $contact]);