1
0
Fork 0

Merge pull request #8861 from annando/fix-empty-network

Fix message "empty network" in gcontact::getid
This commit is contained in:
Hypolite Petovan 2020-07-10 16:08:43 -04:00 committed by GitHub
commit 52b2f67644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 28 deletions

View file

@ -609,8 +609,6 @@ class GContact
*/ */
public static function getId($contact) public static function getId($contact)
{ {
$gcontact_id = 0;
if (empty($contact['network'])) { if (empty($contact['network'])) {
Logger::notice('Empty network', ['url' => $contact['url'], 'callstack' => System::callstack()]); Logger::notice('Empty network', ['url' => $contact['url'], 'callstack' => System::callstack()]);
return false; return false;
@ -630,12 +628,12 @@ class GContact
$contact['url'] = self::cleanContactUrl($contact['url']); $contact['url'] = self::cleanContactUrl($contact['url']);
} }
DBA::lock('gcontact'); $condition = ['nurl' => Strings::normaliseLink($contact['url'])];
$fields = ['id', 'last_contact', 'last_failure', 'network']; $gcontact = DBA::selectFirst('gcontact', ['id'], $condition, ['order' => ['id']]);
$gcnt = DBA::selectFirst('gcontact', $fields, ['nurl' => Strings::normaliseLink($contact['url'])]); if (DBA::isResult($gcontact)) {
if (DBA::isResult($gcnt)) { return $gcontact['id'];
$gcontact_id = $gcnt['id']; }
} else {
$contact['location'] = $contact['location'] ?? ''; $contact['location'] = $contact['location'] ?? '';
$contact['about'] = $contact['about'] ?? ''; $contact['about'] = $contact['about'] ?? '';
$contact['generation'] = $contact['generation'] ?? 0; $contact['generation'] = $contact['generation'] ?? 0;
@ -648,15 +646,14 @@ class GContact
DBA::insert('gcontact', $fields); DBA::insert('gcontact', $fields);
$condition = ['nurl' => Strings::normaliseLink($contact['url'])]; // We intentionally aren't using lastInsertId here. There is a chance for duplicates.
$cnt = DBA::selectFirst('gcontact', ['id', 'network'], $condition, ['order' => ['id']]); $gcontact = DBA::selectFirst('gcontact', ['id'], $condition, ['order' => ['id']]);
if (DBA::isResult($cnt)) { if (!DBA::isResult($gcontact)) {
$gcontact_id = $cnt['id']; Logger::info('GContact creation failed', $fields);
// Shouldn't happen
return 0;
} }
} return $gcontact['id'];
DBA::unlock();
return $gcontact_id;
} }
/** /**

View file

@ -1560,7 +1560,7 @@ class DFRN
if (DBA::isResult($contact_old) && !$onlyfetch) { if (DBA::isResult($contact_old) && !$onlyfetch) {
Logger::log("Check if contact details for contact " . $contact_old["id"] . " (" . $contact_old["nick"] . ") have to be updated.", Logger::DEBUG); Logger::log("Check if contact details for contact " . $contact_old["id"] . " (" . $contact_old["nick"] . ") have to be updated.", Logger::DEBUG);
$poco = ["url" => $contact_old["url"]]; $poco = ["url" => $contact_old["url"], "network" => $contact_old["network"]];
// When was the last change to name or uri? // When was the last change to name or uri?
$name_element = $xpath->query($element . "/atom:name", $context)->item(0); $name_element = $xpath->query($element . "/atom:name", $context)->item(0);