]> git.mxchange.org Git - friendica.git/commitdiff
[Database version 1500] Remove obsolete table fcontact
authorHypolite Petovan <hypolite@mrpetovan.com>
Fri, 11 Nov 2022 01:42:47 +0000 (20:42 -0500)
committerHypolite Petovan <hypolite@mrpetovan.com>
Mon, 5 Dec 2022 05:00:50 +0000 (00:00 -0500)
database.sql
doc/database.md
doc/database/db_fcontact.md [deleted file]
src/Database/DBStructure.php
src/Database/PostUpdate.php
src/Model/FContact.php [deleted file]
src/Protocol/DFRN.php
src/Worker/UpdateFContact.php [deleted file]
static/dbstructure.config.php
update.php

index ae2f8096ba2e95803ea8fce4036caaa2f39b425d..3169bac03ac75bce1cbcb94878d4eea1e487eff0 100644 (file)
@@ -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
 --
index 8d460f772a457549a5451661b4067c9d144eb9fe..9fa438c8d2a6daa14a19b121d95dbe27b79e5055 100644 (file)
@@ -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 |
diff --git a/doc/database/db_fcontact.md b/doc/database/db_fcontact.md
deleted file mode 100644 (file)
index 095c47a..0000000
+++ /dev/null
@@ -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)
index 74bd5b42379fb335ca8f7a9ef7b82b0ab9319810..6e50c9fb2838bc6968df0f2a39555ac6ee9e5b22 100644 (file)
@@ -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']);
index adc88b13e82ec425edc0995724bc3a9bf04ef6bc..e57d92ceb738104e251276dd0b4cd0404bf3ac4c 100644 (file)
@@ -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)]);
 
diff --git a/src/Model/FContact.php b/src/Model/FContact.php
deleted file mode 100644 (file)
index e13dcd4..0000000
+++ /dev/null
@@ -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;
-       }
-}
index 621cc2e3cfac0ed52952fd310c60d0acae0db74f..92f3e8154548aa891a8f9d3797ce9cece8a11f2c 100644 (file)
@@ -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;
diff --git a/src/Worker/UpdateFContact.php b/src/Worker/UpdateFContact.php
deleted file mode 100644 (file)
index 260e071..0000000
+++ /dev/null
@@ -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]);
-       }
-}
index 10ef6dad9155e2c747d91a57caae8b9efac2626f..d5bbed666a172632e758f75b53b32bb7869c7ab5 100644 (file)
@@ -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" => ""],
index 176747057199e26fff2da3d5f41eed1124e19b24..12a3fb74e61800c094512a046aa93431f6e67ee5 100644 (file)
@@ -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()