1
1
Fork 0

Merge pull request #3014 from annando/1612-missing-self-contact

Create missing self contact
This commit is contained in:
Tobias Diekershoff 2016-12-15 18:44:44 +01:00 committed by GitHub
commit e92135a2dc
2 changed files with 57 additions and 22 deletions

View file

@ -12,6 +12,7 @@ if (!file_exists("boot.php") AND (sizeof($_SERVER["argv"]) != 0)) {
require_once("boot.php");
require_once("include/photos.php");
require_once("include/user.php");
function cron_run(&$argv, &$argc){
@ -454,6 +455,16 @@ function cron_repair_diaspora(&$a) {
*/
function cron_repair_database() {
// Sometimes there seem to be issues where the "self" contact vanishes.
// We haven't found the origin of the problem by now.
$r = q("SELECT `uid` FROM `user` WHERE NOT EXISTS (SELECT `uid` FROM `contact` WHERE `contact`.`uid` = `user`.`uid` AND `contact`.`self`)");
if (dbm::is_result($r)) {
foreach ($r AS $user) {
logger('Create missing self contact for user '.$user['uid']);
user_create_self_contact($user['uid']);
}
}
// Set the parent if it wasn't set. (Shouldn't happen - but does sometimes)
// This call is very "cheap" so we can do it at any time without a problem
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");

View file

@ -269,28 +269,9 @@ function create_user($arr) {
intval($newuid));
return $result;
}
$r = q("INSERT INTO `contact` ( `uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`,
`addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness` )
VALUES ( %d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0 ) ",
intval($newuid),
datetime_convert(),
dbesc($username),
dbesc($nickname),
dbesc(z_root() . "/photo/profile/{$newuid}.jpg"),
dbesc(z_root() . "/photo/avatar/{$newuid}.jpg"),
dbesc(z_root() . "/photo/micro/{$newuid}.jpg"),
dbesc(z_root() . "/profile/$nickname"),
dbesc(normalise_link(z_root() . "/profile/$nickname")),
dbesc($nickname . '@' . substr(z_root(), strpos(z_root(),'://') + 3 )),
dbesc(z_root() . "/dfrn_request/$nickname"),
dbesc(z_root() . "/dfrn_notify/$nickname"),
dbesc(z_root() . "/dfrn_poll/$nickname"),
dbesc(z_root() . "/dfrn_confirm/$nickname"),
dbesc(z_root() . "/poco/$nickname"),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert())
);
// Create the self contact
user_create_self_contact($newuid);
// Create a group with no members. This allows somebody to use it
// right away as a default group for new contacts.
@ -377,6 +358,49 @@ function create_user($arr) {
}
/**
* @brief create the "self" contact from data from the user table
*
* @param integer $uid
*/
function user_create_self_contact($uid) {
// Only create the entry if it doesn't exist yet
$r = q("SELECT `id` FROM `contact` WHERE `uid` = %d AND `self`", intval($uid));
if (dbm::is_result($r)) {
return;
}
$r = q("SELECT `uid`, `username`, `nickname` FROM `user` WHERE `uid` = %d", intval($uid));
if (!dbm::is_result($r)) {
return;
}
$user = $r[0];
q("INSERT INTO `contact` (`uid`, `created`, `self`, `name`, `nick`, `photo`, `thumb`, `micro`, `blocked`, `pending`, `url`, `nurl`,
`addr`, `request`, `notify`, `poll`, `confirm`, `poco`, `name-date`, `uri-date`, `avatar-date`, `closeness`)
VALUES (%d, '%s', 1, '%s', '%s', '%s', '%s', '%s', 0, 0, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%s', 0)",
intval($user['uid']),
datetime_convert(),
dbesc($user['username']),
dbesc($user['nickname']),
dbesc(z_root()."/photo/profile/".$user['uid'].".jpg"),
dbesc(z_root()."/photo/avatar/".$user['uid'].".jpg"),
dbesc(z_root()."/photo/micro/".$user['uid'].".jpg"),
dbesc(z_root()."/profile/".$user['nickname']),
dbesc(normalise_link(z_root()."/profile/".$user['nickname'])),
dbesc($user['nickname'].'@'.substr(z_root(), strpos(z_root(),'://') + 3)),
dbesc(z_root()."/dfrn_request/".$user['nickname']),
dbesc(z_root()."/dfrn_notify/".$user['nickname']),
dbesc(z_root()."/dfrn_poll/".$user['nickname']),
dbesc(z_root()."/dfrn_confirm/".$user['nickname']),
dbesc(z_root()."/poco/".$user['nickname']),
dbesc(datetime_convert()),
dbesc(datetime_convert()),
dbesc(datetime_convert())
);
}
/**
* @brief send registration confiŕmation with the intormation that reg is pending