Merge pull request #2287 from annando/1601-duplicate-contacts

Remove duplicated contacts with uid=0
This commit is contained in:
Tobias Diekershoff 2016-01-25 07:33:55 +01:00
commit 662a9f5b16
2 changed files with 9 additions and 7 deletions

View file

@ -410,12 +410,12 @@ function get_contact($url, $uid = 0) {
return 0;
}
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
dbesc(normalise_link($url)),
intval($uid));
if (!$contact)
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d",
$contact = q("SELECT `id`, `avatar-date` FROM `contact` WHERE `alias` IN ('%s', '%s') AND `uid` = %d ORDER BY `id` LIMIT 1",
dbesc($url),
dbesc(normalise_link($url)),
intval($uid));
@ -439,9 +439,7 @@ function get_contact($url, $uid = 0) {
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
return 0;
// tempory programming. Can be deleted after 2015-02-07
if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
$data["alias"] = normalise_link($url);
$url = $data["url"];
if ($contactid == 0) {
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`,
@ -470,7 +468,7 @@ function get_contact($url, $uid = 0) {
dbesc($data["poco"])
);
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d",
$contact = q("SELECT `id` FROM `contact` WHERE `nurl` = '%s' AND `uid` = %d ORDER BY `id` LIMIT 2",
dbesc(normalise_link($data["url"])),
intval($uid));
if (!$contact)
@ -479,6 +477,11 @@ function get_contact($url, $uid = 0) {
$contactid = $contact[0]["id"];
}
if ((count($contact) > 1) AND ($uid == 0) AND ($contactid != 0) AND ($url != ""))
q("DELETE FROM `contact` WHERE `nurl` = '%s' AND `id` != %d",
dbesc(normalise_link($url)),
intval($contactid));
require_once("Photo.php");
$photos = import_profile_photo($data["photo"],$uid,$contactid);

View file

@ -431,7 +431,6 @@ function cron_repair_database() {
q("UPDATE `item` INNER JOIN `item` AS `parent` ON `parent`.`uri` = `item`.`parent-uri` AND `parent`.`uid` = `item`.`uid` SET `item`.`parent` = `parent`.`id` WHERE `item`.`parent` = 0");
/// @todo
/// - remove duplicated contacts with uid=0 (We could do this at the place where the contacts are stored)
/// - remove thread entries without item
/// - remove sign entries without item
/// - remove children when parent got lost