No gcontact-id anymore (It wasn't really used)

This commit is contained in:
Michael 2018-02-21 05:15:55 +00:00
parent eed35c3e69
commit a59796d1d4
7 changed files with 12 additions and 95 deletions

View File

@ -445,7 +445,6 @@ CREATE TABLE IF NOT EXISTS `item` (
`uri` varchar(255) NOT NULL DEFAULT '' COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`gcontact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`type` varchar(20) NOT NULL DEFAULT '' COMMENT '',
`wall` boolean NOT NULL DEFAULT '0' COMMENT '',
`gravity` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
@ -948,7 +947,6 @@ CREATE TABLE IF NOT EXISTS `thread` (
`iid` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`uid` mediumint unsigned NOT NULL DEFAULT 0 COMMENT 'User id',
`contact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`gcontact-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`owner-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`author-id` int unsigned NOT NULL DEFAULT 0 COMMENT '',
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',

View File

@ -439,7 +439,6 @@ These Fields are not added below (yet). They are here to for bug search.
`item`.`forum_mode`,
`item`.`mention`,
`item`.`global`,
`item`.`gcontact-id`,
`item`.`shadow`,
*/

View File

@ -24,7 +24,6 @@ use Friendica\Core\System;
use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use Friendica\Model\Item;
use Friendica\Protocol\Diaspora;
use Friendica\Protocol\Email;
@ -632,8 +631,6 @@ function item_post(App $a) {
$datarray['postopts'] = $postopts;
$datarray['origin'] = $origin;
$datarray['moderated'] = false;
$datarray['gcontact-id'] = GContact::getId(["url" => $datarray['author-link'], "network" => $datarray['network'],
"photo" => $datarray['author-avatar'], "name" => $datarray['author-name']]);
$datarray['object'] = $object;
/*

View File

@ -1122,7 +1122,6 @@ class DBStructure
"uri" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"gcontact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
"type" => ["type" => "varchar(20)", "not null" => "1", "default" => "", "comment" => ""],
"wall" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
"gravity" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
@ -1649,7 +1648,6 @@ class DBStructure
"iid" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "primary" => "1", "relation" => ["item" => "id"], "comment" => ""],
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "relation" => ["user" => "uid"], "comment" => "User id"],
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"gcontact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["gcontact" => "id"], "comment" => ""],
"owner-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"author-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "relation" => ["contact" => "id"], "comment" => ""],
"created" => ["type" => "datetime", "not null" => "1", "default" => NULL_DATE, "comment" => ""],

View File

@ -7,7 +7,6 @@ namespace Friendica\Database;
use Friendica\Core\Config;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\GContact;
use dba;
require_once 'include/dba.php';
@ -22,9 +21,6 @@ class PostUpdate
*/
public static function update()
{
if (!self::update1192()) {
return;
}
if (!self::update1194()) {
return;
}
@ -36,61 +32,6 @@ class PostUpdate
}
}
/**
* @brief set the gcontact-id in all item entries
*
* This job has to be started multiple times until all entries are set.
* It isn't started in the update function since it would consume too much time and can be done in the background.
*
* @return bool "true" when the job is done
*/
private static function update1192()
{
// Was the script completed?
if (Config::get("system", "post_update_version") >= 1192) {
return true;
}
// Check if the first step is done (Setting "gcontact-id" in the item table)
$r = dba::select('item', ['author-link', 'author-name', 'author-avatar', 'uid', 'network'], ['gcontact-id' => 0], ['limit' => 1000]);
if (!$r) {
// Are there unfinished entries in the thread table?
$r = q("SELECT COUNT(*) AS `total` FROM `thread`
INNER JOIN `item` ON `item`.`id` =`thread`.`iid`
WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
if ($r && ($r[0]["total"] == 0)) {
Config::set("system", "post_update_version", 1192);
return true;
}
// Update the thread table from the item table
q("UPDATE `thread` INNER JOIN `item` ON `item`.`id`=`thread`.`iid`
SET `thread`.`gcontact-id` = `item`.`gcontact-id`
WHERE `thread`.`gcontact-id` = 0 AND
(`thread`.`uid` IN (SELECT `uid` from `user`) OR `thread`.`uid` = 0)");
return false;
}
$item_arr = [];
foreach ($r as $item) {
$index = $item["author-link"]."-".$item["uid"];
$item_arr[$index] = ["author-link" => $item["author-link"],
"uid" => $item["uid"],
"network" => $item["network"]];
}
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
foreach ($item_arr as $item) {
$gcontact_id = GContact::getId(["url" => $item['author-link'], "network" => $item['network'],
"photo" => $item['author-avatar'], "name" => $item['author-name']]);
dba::update('item', ['gcontact-id' => $gcontact_id], ['uid' => $item['uid'], 'author-link' => $item['author-link'], 'gcontact-id' => 0]);
}
return false;
}
/**
* @brief Updates the "global" field in the item table
*
@ -219,7 +160,7 @@ class PostUpdate
"uid" => $item["uid"]];
}
// Set the "gcontact-id" in the item table and add a new gcontact entry if needed
// Set the "author-id" and "owner-id" in the item table and add a new public contact entry if needed
foreach ($item_arr as $item) {
$author_id = Contact::getIdForURL($item["author-link"], 0);
$owner_id = Contact::getIdForURL($item["owner-link"], 0);

View File

@ -16,7 +16,6 @@ use Friendica\Core\Worker;
use Friendica\Database\DBM;
use Friendica\Model\Contact;
use Friendica\Model\Conversation;
use Friendica\Model\GContact;
use Friendica\Model\Group;
use Friendica\Model\Term;
use Friendica\Object\Image;
@ -475,7 +474,7 @@ class Item extends BaseObject
if ($arr["contact-id"] == 0) {
/*
* First we are looking for a suitable contact that matches with the author of the post
* This is done only for comments (See below explanation at "gcontact-id")
* This is done only for comments
*/
if ($arr['parent-uri'] != $arr['uri']) {
$arr["contact-id"] = Contact::getIdForURL($arr['author-link'], $uid);
@ -498,21 +497,6 @@ class Item extends BaseObject
logger("Contact-id was missing for post ".$arr["guid"]." from user id ".$uid." - now set to ".$arr["contact-id"], LOGGER_DEBUG);
}
if (!x($arr, "gcontact-id")) {
/*
* The gcontact should mostly behave like the contact. But is is supposed to be global for the system.
* This means that wall posts, repeated posts, etc. should have the gcontact id of the owner.
* On comments the author is the better choice.
*/
if ($arr['parent-uri'] === $arr['uri']) {
$arr["gcontact-id"] = GContact::getId(["url" => $arr['owner-link'], "network" => $arr['network'],
"photo" => $arr['owner-avatar'], "name" => $arr['owner-name']]);
} else {
$arr["gcontact-id"] = GContact::getId(["url" => $arr['author-link'], "network" => $arr['network'],
"photo" => $arr['author-avatar'], "name" => $arr['author-name']]);
}
}
if ($arr["author-id"] == 0) {
$arr["author-id"] = Contact::getIdForURL($arr["author-link"], 0);
}
@ -1942,7 +1926,7 @@ EOT;
private static function addThread($itemid, $onlyshadow = false)
{
$items = q("SELECT `uid`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`,
`moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
`moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`,
`deleted`, `origin`, `forum_mode`, `mention`, `network`, `author-id`, `owner-id`
FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
@ -1962,7 +1946,7 @@ EOT;
private static function updateThread($itemid, $setmention = false)
{
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`, `gcontact-id`,
$items = q("SELECT `uid`, `guid`, `title`, `body`, `created`, `edited`, `commented`, `received`, `changed`, `wall`, `private`, `pubmail`, `moderated`, `visible`, `spam`, `starred`, `bookmark`, `contact-id`,
`deleted`, `origin`, `forum_mode`, `network`, `rendered-html`, `rendered-hash` FROM `item` WHERE `id` = %d AND (`parent` = %d OR `parent` = 0) LIMIT 1", intval($itemid), intval($itemid));
if (!DBM::is_result($items)) {

View File

@ -903,23 +903,23 @@ class Diaspora
}
/**
* @brief get a handle (user@domain.tld) from a given contact id or gcontact id
* @brief get a handle (user@domain.tld) from a given contact id
*
* @param int $contact_id The id in the contact table
* @param int $gcontact_id The id in the gcontact table
* @param int $pcontact_id The id in the contact table (Used for the public contact)
*
* @return string the handle
*/
public static function handleFromContact($contact_id, $gcontact_id = 0)
public static function handleFromContact($contact_id, $pcontact_id = 0)
{
$handle = false;
logger("contact id is ".$contact_id." - gcontact id is ".$gcontact_id, LOGGER_DEBUG);
logger("contact id is ".$contact_id." - pcontact id is ".$pcontact_id, LOGGER_DEBUG);
if ($gcontact_id != 0) {
if ($pcontact_id != 0) {
$r = q(
"SELECT `addr` FROM `gcontact` WHERE `id` = %d AND `addr` != ''",
intval($gcontact_id)
"SELECT `addr` FROM `contact` WHERE `id` = %d AND `addr` != ''",
intval($pcontact_id)
);
if (DBM::is_result($r)) {
@ -4009,7 +4009,7 @@ class Diaspora
*/
public static function sendRetraction($item, $owner, $contact, $public_batch = false, $relay = false)
{
$itemaddr = self::handleFromContact($item["contact-id"], $item["gcontact-id"]);
$itemaddr = self::handleFromContact($item["contact-id"], $item["author-id"]);
$msg_type = "retraction";