From a59796d1d48ab96feeefbea6fce0656ebc7373a5 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 21 Feb 2018 05:15:55 +0000 Subject: [PATCH] No gcontact-id anymore (It wasn't really used) --- database.sql | 2 -- include/conversation.php | 1 - mod/item.php | 3 -- src/Database/DBStructure.php | 2 -- src/Database/PostUpdate.php | 61 +----------------------------------- src/Model/Item.php | 22 ++----------- src/Protocol/Diaspora.php | 16 +++++----- 7 files changed, 12 insertions(+), 95 deletions(-) diff --git a/database.sql b/database.sql index 606ac6d814..a1c3e31e41 100644 --- a/database.sql +++ b/database.sql @@ -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 '', diff --git a/include/conversation.php b/include/conversation.php index 1ff1dbf5f4..bc0a758682 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -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`, */ diff --git a/mod/item.php b/mod/item.php index 5489964161..62a56363f4 100644 --- a/mod/item.php +++ b/mod/item.php @@ -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; /* diff --git a/src/Database/DBStructure.php b/src/Database/DBStructure.php index f6ce129e17..0b5eca1ae0 100644 --- a/src/Database/DBStructure.php +++ b/src/Database/DBStructure.php @@ -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" => ""], diff --git a/src/Database/PostUpdate.php b/src/Database/PostUpdate.php index 0b9321b340..9ff3a97876 100644 --- a/src/Database/PostUpdate.php +++ b/src/Database/PostUpdate.php @@ -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); diff --git a/src/Model/Item.php b/src/Model/Item.php index a279b64dad..6999ab4cf9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -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)) { diff --git a/src/Protocol/Diaspora.php b/src/Protocol/Diaspora.php index 65b84f3cd4..f5272f7a94 100644 --- a/src/Protocol/Diaspora.php +++ b/src/Protocol/Diaspora.php @@ -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";