mirror of
https://github.com/friendica/friendica
synced 2024-12-23 10:00:20 +00:00
Issue 4997: Avoid database duplicates
This commit is contained in:
parent
09a2c1d76b
commit
6d4f3e8ee2
2 changed files with 14 additions and 63 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue