mirror of
https://github.com/friendica/friendica
synced 2024-12-22 18:40:17 +00:00
[Database version 1500] Remove obsolete table fcontact
This commit is contained in:
parent
ce69026964
commit
818cdf83ca
10 changed files with 16 additions and 326 deletions
35
database.sql
35
database.sql
|
@ -1,6 +1,6 @@
|
|||
-- ------------------------------------------
|
||||
-- Friendica 2022.12-dev (Giant Rhubarb)
|
||||
-- DB_UPDATE_VERSION 1499
|
||||
-- DB_UPDATE_VERSION 1500
|
||||
-- ------------------------------------------
|
||||
|
||||
|
||||
|
@ -667,39 +667,6 @@ CREATE TABLE IF NOT EXISTS `event` (
|
|||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Events';
|
||||
|
||||
--
|
||||
-- TABLE fcontact
|
||||
--
|
||||
CREATE TABLE IF NOT EXISTS `fcontact` (
|
||||
`id` int unsigned NOT NULL auto_increment COMMENT 'sequential ID',
|
||||
`guid` varbinary(255) NOT NULL DEFAULT '' COMMENT 'unique id',
|
||||
`url` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`uri-id` int unsigned COMMENT 'Id of the item-uri table entry that contains the fcontact url',
|
||||
`name` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`photo` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`request` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`nick` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`addr` varchar(255) NOT NULL DEFAULT '' COMMENT '',
|
||||
`batch` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`notify` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`poll` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`confirm` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`priority` tinyint unsigned NOT NULL DEFAULT 0 COMMENT '',
|
||||
`network` char(4) NOT NULL DEFAULT '' COMMENT '',
|
||||
`alias` varbinary(383) NOT NULL DEFAULT '' COMMENT '',
|
||||
`pubkey` text COMMENT '',
|
||||
`created` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||
`updated` datetime NOT NULL DEFAULT '0001-01-01 00:00:00' COMMENT '',
|
||||
`interacting_count` int unsigned DEFAULT 0 COMMENT 'Number of contacts this contact interactes with',
|
||||
`interacted_count` int unsigned DEFAULT 0 COMMENT 'Number of contacts that interacted with this contact',
|
||||
`post_count` int unsigned DEFAULT 0 COMMENT 'Number of posts and comments',
|
||||
PRIMARY KEY(`id`),
|
||||
INDEX `addr` (`addr`(32)),
|
||||
UNIQUE INDEX `url` (`url`(190)),
|
||||
UNIQUE INDEX `uri-id` (`uri-id`),
|
||||
FOREIGN KEY (`uri-id`) REFERENCES `item-uri` (`id`) ON UPDATE RESTRICT ON DELETE CASCADE
|
||||
) DEFAULT COLLATE utf8mb4_general_ci COMMENT='Diaspora compatible contacts - used in the Diaspora implementation';
|
||||
|
||||
--
|
||||
-- TABLE fetch-entry
|
||||
--
|
||||
|
|
|
@ -27,7 +27,6 @@ Database Tables
|
|||
| [diaspora-interaction](help/database/db_diaspora-interaction) | Signed Diaspora Interaction |
|
||||
| [endpoint](help/database/db_endpoint) | ActivityPub endpoints - used in the ActivityPub implementation |
|
||||
| [event](help/database/db_event) | Events |
|
||||
| [fcontact](help/database/db_fcontact) | Diaspora compatible contacts - used in the Diaspora implementation |
|
||||
| [fetch-entry](help/database/db_fetch-entry) | |
|
||||
| [fetched-activity](help/database/db_fetched-activity) | Id of fetched activities |
|
||||
| [fsuggest](help/database/db_fsuggest) | friend suggestion stuff |
|
||||
|
|
|
@ -1,51 +0,0 @@
|
|||
Table fcontact
|
||||
===========
|
||||
|
||||
Diaspora compatible contacts - used in the Diaspora implementation
|
||||
|
||||
Fields
|
||||
------
|
||||
|
||||
| Field | Description | Type | Null | Key | Default | Extra |
|
||||
| ----------------- | ------------------------------------------------------------- | ---------------- | ---- | --- | ------------------- | -------------- |
|
||||
| id | sequential ID | int unsigned | NO | PRI | NULL | auto_increment |
|
||||
| guid | unique id | varbinary(255) | NO | | | |
|
||||
| url | | varbinary(383) | NO | | | |
|
||||
| uri-id | Id of the item-uri table entry that contains the fcontact url | int unsigned | YES | | NULL | |
|
||||
| name | | varchar(255) | NO | | | |
|
||||
| photo | | varbinary(383) | NO | | | |
|
||||
| request | | varbinary(383) | NO | | | |
|
||||
| nick | | varchar(255) | NO | | | |
|
||||
| addr | | varchar(255) | NO | | | |
|
||||
| batch | | varbinary(383) | NO | | | |
|
||||
| notify | | varbinary(383) | NO | | | |
|
||||
| poll | | varbinary(383) | NO | | | |
|
||||
| confirm | | varbinary(383) | NO | | | |
|
||||
| priority | | tinyint unsigned | NO | | 0 | |
|
||||
| network | | char(4) | NO | | | |
|
||||
| alias | | varbinary(383) | NO | | | |
|
||||
| pubkey | | text | YES | | NULL | |
|
||||
| created | | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||
| updated | | datetime | NO | | 0001-01-01 00:00:00 | |
|
||||
| interacting_count | Number of contacts this contact interactes with | int unsigned | YES | | 0 | |
|
||||
| interacted_count | Number of contacts that interacted with this contact | int unsigned | YES | | 0 | |
|
||||
| post_count | Number of posts and comments | int unsigned | YES | | 0 | |
|
||||
|
||||
Indexes
|
||||
------------
|
||||
|
||||
| Name | Fields |
|
||||
| ------- | ---------------- |
|
||||
| PRIMARY | id |
|
||||
| addr | addr(32) |
|
||||
| url | UNIQUE, url(190) |
|
||||
| uri-id | UNIQUE, uri-id |
|
||||
|
||||
Foreign Keys
|
||||
------------
|
||||
|
||||
| Field | Target Table | Target Field |
|
||||
|-------|--------------|--------------|
|
||||
| uri-id | [item-uri](help/database/db_item-uri) | id |
|
||||
|
||||
Return to [database documentation](help/database)
|
|
@ -74,7 +74,7 @@ class DBStructure
|
|||
$old_tables = ['fserver', 'gcign', 'gcontact', 'gcontact-relation', 'gfollower' ,'glink', 'item-delivery-data',
|
||||
'item-activity', 'item-content', 'item_id', 'participation', 'poll', 'poll_result', 'queue', 'retriever_rule',
|
||||
'deliverq', 'dsprphotoq', 'ffinder', 'sign', 'spam', 'term', 'user-item', 'thread', 'item', 'challenge',
|
||||
'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation'];
|
||||
'auth_codes', 'tokens', 'clients', 'profile_check', 'host', 'conversation', 'fcontact'];
|
||||
|
||||
$tables = DBA::selectToArray('INFORMATION_SCHEMA.TABLES', ['TABLE_NAME'],
|
||||
['TABLE_SCHEMA' => DBA::databaseName(), 'TABLE_TYPE' => 'BASE TABLE']);
|
||||
|
|
|
@ -899,6 +899,11 @@ class PostUpdate
|
|||
return true;
|
||||
}
|
||||
|
||||
if (!DBStructure::existsTable('fcontact')) {
|
||||
DI::config()->set('system', 'post_update_version', 1425);
|
||||
return true;
|
||||
}
|
||||
|
||||
$condition = ["`uri-id` IS NULL"];
|
||||
Logger::info('Start', ['rest' => DBA::count('fcontact', $condition)]);
|
||||
|
||||
|
|
|
@ -1,161 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Model;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Core\Protocol;
|
||||
use Friendica\Core\Worker;
|
||||
use Friendica\Database\DBA;
|
||||
use Friendica\DI;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Network\Probe;
|
||||
use Friendica\Util\DateTimeFormat;
|
||||
use Friendica\Util\Strings;
|
||||
|
||||
class FContact
|
||||
{
|
||||
/**
|
||||
* Fetches data for a given handle
|
||||
*
|
||||
* @param string $handle The handle
|
||||
* @param boolean $update true = always update, false = never update, null = update when not found or outdated
|
||||
*
|
||||
* @return array the queried data
|
||||
* @throws \Friendica\Network\HTTPException\InternalServerErrorException
|
||||
* @throws \ImagickException
|
||||
*/
|
||||
public static function getByURL(string $handle, $update = null): array
|
||||
{
|
||||
Logger::debug('Fetch fcontact', ['handle' => $handle, 'update' => $update]);
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'addr' => $handle]);
|
||||
if (!DBA::isResult($person)) {
|
||||
$urls = [$handle, str_replace('http://', 'https://', $handle), Strings::normaliseLink($handle)];
|
||||
$person = DBA::selectFirst('fcontact', [], ['network' => Protocol::DIASPORA, 'url' => $urls]);
|
||||
}
|
||||
|
||||
if (DBA::isResult($person)) {
|
||||
Logger::debug('In cache', ['handle' => $handle]);
|
||||
|
||||
if (is_null($update)) {
|
||||
$update = empty($person['guid']) || empty($person['uri-id']) || ($person['created'] <= DBA::NULL_DATETIME);
|
||||
if (GServer::getNextUpdateDate(true, $person['created'], $person['updated'], false) < DateTimeFormat::utcNow()) {
|
||||
Logger::debug('Start background update', ['handle' => $handle]);
|
||||
Worker::add(['priority' => Worker::PRIORITY_LOW, 'dont_fork' => true], 'UpdateFContact', $handle);
|
||||
}
|
||||
}
|
||||
} elseif (is_null($update)) {
|
||||
$update = true;
|
||||
} else {
|
||||
$person = [];
|
||||
}
|
||||
|
||||
if ($update) {
|
||||
Logger::info('create or refresh', ['handle' => $handle]);
|
||||
$data = Probe::uri($handle, Protocol::DIASPORA);
|
||||
|
||||
// Note that Friendica contacts will return a "Diaspora person"
|
||||
// if Diaspora connectivity is enabled on their server
|
||||
if ($data['network'] ?? '' === Protocol::DIASPORA) {
|
||||
self::updateFromProbeArray($data);
|
||||
|
||||
$person = self::getByURL($handle, false);
|
||||
}
|
||||
}
|
||||
|
||||
return $person;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the fcontact table
|
||||
*
|
||||
* @param array $arr The fcontact data
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function updateFromProbeArray(array $arr)
|
||||
{
|
||||
$uriid = ItemURI::insert(['uri' => $arr['url'], 'guid' => $arr['guid']]);
|
||||
|
||||
$fcontact = DBA::selectFirst('fcontact', ['created'], ['url' => $arr['url'], 'network' => $arr['network']]);
|
||||
$contact = Contact::getByUriId($uriid, ['id', 'created']);
|
||||
$apcontact = APContact::getByURL($arr['url'], false);
|
||||
if (!empty($apcontact)) {
|
||||
$interacted = $apcontact['following_count'];
|
||||
$interacting = $apcontact['followers_count'];
|
||||
$posts = $apcontact['statuses_count'];
|
||||
} elseif (!empty($contact['id'])) {
|
||||
$last_interaction = DateTimeFormat::utc('now - 180 days');
|
||||
|
||||
$interacted = DBA::count('contact-relation', ["`cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$interacting = DBA::count('contact-relation', ["`relation-cid` = ? AND NOT `follows` AND `last-interaction` > ?", $contact['id'], $last_interaction]);
|
||||
$posts = DBA::count('post', ['author-id' => $contact['id'], 'gravity' => [Item::GRAVITY_PARENT, Item::GRAVITY_COMMENT]]);
|
||||
}
|
||||
|
||||
$fields = [
|
||||
'name' => $arr['name'],
|
||||
'photo' => $arr['photo'],
|
||||
'request' => $arr['request'],
|
||||
'nick' => $arr['nick'],
|
||||
'addr' => strtolower($arr['addr']),
|
||||
'guid' => $arr['guid'],
|
||||
'batch' => $arr['batch'],
|
||||
'notify' => $arr['notify'],
|
||||
'poll' => $arr['poll'],
|
||||
'confirm' => $arr['confirm'],
|
||||
'alias' => $arr['alias'],
|
||||
'pubkey' => $arr['pubkey'],
|
||||
'uri-id' => $uriid,
|
||||
'interacting_count' => $interacting ?? 0,
|
||||
'interacted_count' => $interacted ?? 0,
|
||||
'post_count' => $posts ?? 0,
|
||||
'updated' => DateTimeFormat::utcNow(),
|
||||
];
|
||||
|
||||
if (empty($fcontact['created'])) {
|
||||
$fields['created'] = $fields['updated'];
|
||||
} elseif (!empty($contact['created']) && ($fcontact['created'] <= DBA::NULL_DATETIME)) {
|
||||
$fields['created'] = $contact['created'];
|
||||
}
|
||||
|
||||
$fields = DI::dbaDefinition()->truncateFieldsForTable('fcontact', $fields);
|
||||
DBA::update('fcontact', $fields, ['url' => $arr['url'], 'network' => $arr['network']], true);
|
||||
}
|
||||
|
||||
/**
|
||||
* get a url (scheme://domain.tld/u/user) from a given Diaspora*
|
||||
* fcontact guid
|
||||
*
|
||||
* @param string $fcontact_guid Hexadecimal string guid
|
||||
* @return string|null the contact url or null
|
||||
* @throws \Exception
|
||||
*/
|
||||
public static function getUrlByGuid(string $fcontact_guid)
|
||||
{
|
||||
Logger::info('fcontact', ['guid' => $fcontact_guid]);
|
||||
|
||||
$fcontact = DBA::selectFirst('fcontact', ['url'], ["`url` != ? AND `network` = ? AND `guid` = ?", '', Protocol::DIASPORA, $fcontact_guid]);
|
||||
if (DBA::isResult($fcontact)) {
|
||||
return $fcontact['url'];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -34,7 +34,6 @@ use Friendica\DI;
|
|||
use Friendica\Model\Contact;
|
||||
use Friendica\Model\Conversation;
|
||||
use Friendica\Model\Event;
|
||||
use Friendica\Model\FContact;
|
||||
use Friendica\Model\GServer;
|
||||
use Friendica\Model\Item;
|
||||
use Friendica\Model\ItemURI;
|
||||
|
|
|
@ -1,41 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2022, the Friendica project
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Friendica\Worker;
|
||||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Model\FContact;
|
||||
|
||||
class UpdateFContact
|
||||
{
|
||||
/**
|
||||
* Update fcontact data via probe
|
||||
*
|
||||
* @param string $handle Contact handle
|
||||
* @return void
|
||||
*/
|
||||
public static function execute(string $handle)
|
||||
{
|
||||
$success = FContact::getByURL($handle, true);
|
||||
|
||||
Logger::info('Updated from probe', ['handle' => $handle, 'success' => $success]);
|
||||
}
|
||||
}
|
|
@ -55,7 +55,7 @@
|
|||
use Friendica\Database\DBA;
|
||||
|
||||
if (!defined('DB_UPDATE_VERSION')) {
|
||||
define('DB_UPDATE_VERSION', 1498);
|
||||
define('DB_UPDATE_VERSION', 1500);
|
||||
}
|
||||
|
||||
return [
|
||||
|
@ -723,39 +723,6 @@ return [
|
|||
"uri-id" => ["uri-id"],
|
||||
]
|
||||
],
|
||||
"fcontact" => [
|
||||
"comment" => "Diaspora compatible contacts - used in the Diaspora implementation",
|
||||
"fields" => [
|
||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
|
||||
"guid" => ["type" => "varbinary(255)", "not null" => "1", "default" => "", "comment" => "unique id"],
|
||||
"url" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the fcontact url"],
|
||||
"name" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"photo" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"request" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"nick" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"addr" => ["type" => "varchar(255)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"batch" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"notify" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"poll" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"confirm" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"priority" => ["type" => "tinyint unsigned", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
"network" => ["type" => "char(4)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"alias" => ["type" => "varbinary(383)", "not null" => "1", "default" => "", "comment" => ""],
|
||||
"pubkey" => ["type" => "text", "comment" => ""],
|
||||
"created" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
"updated" => ["type" => "datetime", "not null" => "1", "default" => DBA::NULL_DATETIME, "comment" => ""],
|
||||
"interacting_count" => ["type" => "int unsigned", "default" => 0, "comment" => "Number of contacts this contact interactes with"],
|
||||
"interacted_count" => ["type" => "int unsigned", "default" => 0, "comment" => "Number of contacts that interacted with this contact"],
|
||||
"post_count" => ["type" => "int unsigned", "default" => 0, "comment" => "Number of posts and comments"],
|
||||
],
|
||||
"indexes" => [
|
||||
"PRIMARY" => ["id"],
|
||||
"addr" => ["addr(32)"],
|
||||
"url" => ["UNIQUE", "url(190)"],
|
||||
"uri-id" => ["UNIQUE", "uri-id"],
|
||||
]
|
||||
],
|
||||
"fetch-entry" => [
|
||||
"comment" => "",
|
||||
"fields" => [
|
||||
|
@ -903,7 +870,7 @@ return [
|
|||
"fields" => [
|
||||
"id" => ["type" => "int unsigned", "not null" => "1", "extra" => "auto_increment", "primary" => "1", "comment" => "sequential ID"],
|
||||
"uid" => ["type" => "mediumint unsigned", "not null" => "1", "default" => "0", "foreign" => ["user" => "uid"], "comment" => "User id"],
|
||||
"fid" => ["type" => "int unsigned", "relation" => ["fcontact" => "id"], "comment" => "deprecated"],
|
||||
"fid" => ["type" => "int unsigned", "comment" => "deprecated"],
|
||||
"contact-id" => ["type" => "int unsigned", "not null" => "1", "default" => "0", "foreign" => ["contact" => "id"], "comment" => ""],
|
||||
"suggest-cid" => ["type" => "int unsigned", "foreign" => ["contact" => "id"], "comment" => "Suggested contact"],
|
||||
"knowyou" => ["type" => "boolean", "not null" => "1", "default" => "0", "comment" => ""],
|
||||
|
|
|
@ -974,7 +974,7 @@ function update_1429()
|
|||
return Update::FAILED;
|
||||
}
|
||||
|
||||
if (!DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
|
||||
if (DBStructure::existsTable('fcontact') && !DBA::e("UPDATE `fcontact` SET `uri-id` = null WHERE NOT `uri-id` IS NULL")) {
|
||||
return Update::FAILED;
|
||||
}
|
||||
|
||||
|
@ -1013,6 +1013,10 @@ function update_1438()
|
|||
|
||||
function update_1439()
|
||||
{
|
||||
if (!DBStructure::existsTable('fcontact')) {
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
||||
$intros = DBA::select('intro', ['id', 'fid'], ["NOT `fid` IS NULL AND `fid` != ?", 0]);
|
||||
while ($intro = DBA::fetch($intros)) {
|
||||
$fcontact = DBA::selectFirst('fcontact', ['url'], ['id' => $intro['fid']]);
|
||||
|
@ -1024,6 +1028,8 @@ function update_1439()
|
|||
}
|
||||
}
|
||||
DBA::close($intros);
|
||||
|
||||
return Update::SUCCESS;
|
||||
}
|
||||
|
||||
function update_1440()
|
||||
|
|
Loading…
Reference in a new issue