Merge pull request #5018 from annando/issue-4997

Issue 4997: Avoid database duplicates
This commit is contained in:
Hypolite Petovan 2018-05-10 09:53:37 -04:00 committed by GitHub
commit 4d5408f3b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 63 deletions

View File

@ -920,7 +920,7 @@ class Diaspora
// Note that Friendica contacts will return a "Diaspora person"
// if Diaspora connectivity is enabled on their server
if ($r && ($r["network"] === NETWORK_DIASPORA)) {
self::addFContact($r, $update);
self::updateFContact($r);
// Fetch the updated or added contact
$person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
@ -936,70 +936,21 @@ class Diaspora
/**
* @brief Updates the fcontact table
*
* @param array $arr The fcontact data
* @param bool $update Update or insert?
*
* @return string The id of the fcontact entry
* @param array $arr The fcontact data
*/
private static function addFContact($arr, $update = false)
private static function updateFContact($arr)
{
if ($update) {
$r = q(
"UPDATE `fcontact` SET
`name` = '%s',
`photo` = '%s',
`request` = '%s',
`nick` = '%s',
`addr` = '%s',
`guid` = '%s',
`batch` = '%s',
`notify` = '%s',
`poll` = '%s',
`confirm` = '%s',
`alias` = '%s',
`pubkey` = '%s',
`updated` = '%s'
WHERE `url` = '%s' AND `network` = '%s'",
dbesc($arr["name"]),
dbesc($arr["photo"]),
dbesc($arr["request"]),
dbesc($arr["nick"]),
dbesc(strtolower($arr["addr"])),
dbesc($arr["guid"]),
dbesc($arr["batch"]),
dbesc($arr["notify"]),
dbesc($arr["poll"]),
dbesc($arr["confirm"]),
dbesc($arr["alias"]),
dbesc($arr["pubkey"]),
dbesc(DateTimeFormat::utcNow()),
dbesc($arr["url"]),
dbesc($arr["network"])
);
} else {
$r = q(
"INSERT INTO `fcontact` (`url`,`name`,`photo`,`request`,`nick`,`addr`, `guid`,
`batch`, `notify`,`poll`,`confirm`,`network`,`alias`,`pubkey`,`updated`)
VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",
dbesc($arr["url"]),
dbesc($arr["name"]),
dbesc($arr["photo"]),
dbesc($arr["request"]),
dbesc($arr["nick"]),
dbesc($arr["addr"]),
dbesc($arr["guid"]),
dbesc($arr["batch"]),
dbesc($arr["notify"]),
dbesc($arr["poll"]),
dbesc($arr["confirm"]),
dbesc($arr["network"]),
dbesc($arr["alias"]),
dbesc($arr["pubkey"]),
dbesc(DateTimeFormat::utcNow())
);
}
$fields = ['name' => $arr["name"], 'photo' => $arr["photo"],
'request' => $arr["request"], 'nick' => $arr["nick"],
'addr' => strtolower($arr["addr"]), 'guid' => $arr["guid"],
'batch' => $arr["batch"], 'notify' => $arr["notify"],
'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
'updated' => DateTimeFormat::utcNow()];
return $r;
$condition = ['url' => $arr["url"], 'network' => $arr["network"]];
dba::update('fcontact', $fields, $condition, true);
}
/**

View File

@ -1427,7 +1427,7 @@ class PortableContact
}
foreach ($tags as $tag) {
dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag]);
dba::insert('gserver-tag', ['gserver-id' => $gserver['id'], 'tag' => $tag], true);
}
}