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; 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)), dbesc(normalise_link($url)),
intval($uid)); intval($uid));
if (!$contact) 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($url),
dbesc(normalise_link($url)), dbesc(normalise_link($url)),
intval($uid)); intval($uid));
@ -439,9 +439,7 @@ function get_contact($url, $uid = 0) {
if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA))) if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_OSTATUS, NETWORK_DIASPORA)))
return 0; return 0;
// tempory programming. Can be deleted after 2015-02-07 $url = $data["url"];
if (($data["alias"] == "") AND (normalise_link($data["url"]) != normalise_link($url)))
$data["alias"] = normalise_link($url);
if ($contactid == 0) { if ($contactid == 0) {
q("INSERT INTO `contact` (`uid`, `created`, `url`, `nurl`, `addr`, `alias`, `notify`, `poll`, 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"]) 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"])), dbesc(normalise_link($data["url"])),
intval($uid)); intval($uid));
if (!$contact) if (!$contact)
@ -479,6 +477,11 @@ function get_contact($url, $uid = 0) {
$contactid = $contact[0]["id"]; $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"); require_once("Photo.php");
$photos = import_profile_photo($data["photo"],$uid,$contactid); $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"); 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 /// @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 thread entries without item
/// - remove sign entries without item /// - remove sign entries without item
/// - remove children when parent got lost /// - remove children when parent got lost