Merge pull request #5018 from annando/issue-4997
Issue 4997: Avoid database duplicates
This commit is contained in:
commit
4d5408f3b1
|
@ -920,7 +920,7 @@ class Diaspora
|
||||||
// Note that Friendica contacts will return a "Diaspora person"
|
// Note that Friendica contacts will return a "Diaspora person"
|
||||||
// if Diaspora connectivity is enabled on their server
|
// if Diaspora connectivity is enabled on their server
|
||||||
if ($r && ($r["network"] === NETWORK_DIASPORA)) {
|
if ($r && ($r["network"] === NETWORK_DIASPORA)) {
|
||||||
self::addFContact($r, $update);
|
self::updateFContact($r);
|
||||||
|
|
||||||
// Fetch the updated or added contact
|
// Fetch the updated or added contact
|
||||||
$person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
|
$person = dba::selectFirst('fcontact', [], ['network' => NETWORK_DIASPORA, 'addr' => $handle]);
|
||||||
|
@ -937,69 +937,20 @@ class Diaspora
|
||||||
* @brief Updates the fcontact table
|
* @brief Updates the fcontact table
|
||||||
*
|
*
|
||||||
* @param array $arr The fcontact data
|
* @param array $arr The fcontact data
|
||||||
* @param bool $update Update or insert?
|
|
||||||
*
|
|
||||||
* @return string The id of the fcontact entry
|
|
||||||
*/
|
*/
|
||||||
private static function addFContact($arr, $update = false)
|
private static function updateFContact($arr)
|
||||||
{
|
{
|
||||||
if ($update) {
|
$fields = ['name' => $arr["name"], 'photo' => $arr["photo"],
|
||||||
$r = q(
|
'request' => $arr["request"], 'nick' => $arr["nick"],
|
||||||
"UPDATE `fcontact` SET
|
'addr' => strtolower($arr["addr"]), 'guid' => $arr["guid"],
|
||||||
`name` = '%s',
|
'batch' => $arr["batch"], 'notify' => $arr["notify"],
|
||||||
`photo` = '%s',
|
'poll' => $arr["poll"], 'confirm' => $arr["confirm"],
|
||||||
`request` = '%s',
|
'alias' => $arr["alias"], 'pubkey' => $arr["pubkey"],
|
||||||
`nick` = '%s',
|
'updated' => DateTimeFormat::utcNow()];
|
||||||
`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())
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $r;
|
$condition = ['url' => $arr["url"], 'network' => $arr["network"]];
|
||||||
|
|
||||||
|
dba::update('fcontact', $fields, $condition, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1427,7 +1427,7 @@ class PortableContact
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($tags as $tag) {
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue