Use an insert to avoid duplicates and for analyzing
This commit is contained in:
parent
5bba0e7d39
commit
9ba3ee13a8
2 changed files with 23 additions and 12 deletions
|
@ -1418,13 +1418,22 @@ class Contact extends BaseObject
|
||||||
|
|
||||||
$condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
|
$condition = ['nurl' => Strings::normaliseLink($data["url"]), 'uid' => $uid, 'deleted' => false];
|
||||||
|
|
||||||
// This does an insert but should most likely prevent duplicates
|
// Before inserting we do check if the entry does exist now.
|
||||||
DBA::update('contact', $fields, $condition, true);
|
|
||||||
|
|
||||||
$contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
|
$contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
|
||||||
if (!DBA::isResult($contact)) {
|
if (!DBA::isResult($contact)) {
|
||||||
// Shouldn't happen
|
Logger::info('Create new contact', $fields);
|
||||||
return 0;
|
|
||||||
|
DBA::insert('contact', $fields);
|
||||||
|
|
||||||
|
// We intentionally aren't using lastInsertId here. There is a chance for duplicates.
|
||||||
|
$contact = DBA::selectFirst('contact', ['id'], $condition, ['order' => ['id']]);
|
||||||
|
if (!DBA::isResult($contact)) {
|
||||||
|
Logger::info('Contact creation failed', $fields);
|
||||||
|
// Shouldn't happen
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Logger::info('Contact had been created before', ['id' => $contact["id"], 'url' => $url, 'contact' => $fields]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact_id = $contact["id"];
|
$contact_id = $contact["id"];
|
||||||
|
|
|
@ -191,15 +191,17 @@ class Diaspora
|
||||||
$fields = array_merge($fields, $network_fields);
|
$fields = array_merge($fields, $network_fields);
|
||||||
|
|
||||||
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url)];
|
$condition = ['uid' => 0, 'nurl' => Strings::normaliseLink($server_url)];
|
||||||
$relay = DBA::selectFirst('contact', ['id'], $condition);
|
$old = DBA::selectFirst('contact', [], $condition);
|
||||||
if (DBA::isResult($relay)) {
|
if (DBA::isResult($old)) {
|
||||||
unset($fields['created']);
|
unset($fields['created']);
|
||||||
$condition = ['id' => $relay['id']];
|
$condition = ['id' => $old['id']];
|
||||||
|
|
||||||
|
Logger::info('Update relay contact', ['fields' => $fields, 'condition' => $condition]);
|
||||||
|
DBA::update('contact', $fields, $condition, $old);
|
||||||
|
} else {
|
||||||
|
Logger::info('Create relay contact', ['fields' => $fields]);
|
||||||
|
DBA::insert('contact', $fields);
|
||||||
}
|
}
|
||||||
|
|
||||||
Logger::info('Set relay contact', ['fields' => $fields, 'condition' => $condition]);
|
|
||||||
|
|
||||||
DBA::update('contact', $fields, $condition, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue