From 2926282f8d84b088d810e15a5ea593d6f86cbdad Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 13 Sep 2021 14:20:20 +0000 Subject: [PATCH] More fields added to "user-contact" --- database.sql | 2 ++ doc/database/db_user-contact.md | 2 ++ src/Model/Contact/User.php | 49 +++++++++++++++++---------------- static/dbstructure.config.php | 2 ++ 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/database.sql b/database.sql index 02b01e25c6..ed66cbb8ac 100644 --- a/database.sql +++ b/database.sql @@ -1526,6 +1526,8 @@ CREATE TABLE IF NOT EXISTS `user-contact` ( `subhub` boolean COMMENT '', `hub-verify` varchar(255) COMMENT '', `protocol` char(4) COMMENT 'Protocol of the contact', + `rating` tinyint COMMENT 'Automatically detected feed poll frequency', + `priority` tinyint unsigned COMMENT 'Feed poll priority', PRIMARY KEY(`uid`,`cid`), INDEX `cid` (`cid`), UNIQUE INDEX `uri-id_uid` (`uri-id`,`uid`), diff --git a/doc/database/db_user-contact.md b/doc/database/db_user-contact.md index 6726ac710d..5dab0c4bd6 100644 --- a/doc/database/db_user-contact.md +++ b/doc/database/db_user-contact.md @@ -24,6 +24,8 @@ Fields | subhub | | boolean | YES | | NULL | | | hub-verify | | varchar(255) | YES | | NULL | | | protocol | Protocol of the contact | char(4) | YES | | NULL | | +| rating | Automatically detected feed poll frequency | tinyint | YES | | NULL | | +| priority | Feed poll priority | tinyint unsigned | YES | | NULL | | Indexes ------------ diff --git a/src/Model/Contact/User.php b/src/Model/Contact/User.php index 85399951c8..eb0b5af096 100644 --- a/src/Model/Contact/User.php +++ b/src/Model/Contact/User.php @@ -66,17 +66,7 @@ class User return false; } - $fields = $contact; - - if (isset($fields['readonly'])) { - $fields['ignored'] = $fields['readonly']; - } - - if (!empty($fields['self'])) { - $fields['rel'] = Contact::SELF; - } - - $fields = DBStructure::getFieldsForTable('user-contact', $fields); + $fields = self::preparedFields($contact); $fields['cid'] = $pcid; $fields['uid'] = $contact['uid']; $fields['uri-id'] = $contact['uri-id']; @@ -101,19 +91,7 @@ class User { DBA::transaction(); - unset($fields['uid']); - unset($fields['cid']); - unset($fields['uri-id']); - - if (isset($fields['readonly'])) { - $fields['ignored'] = $fields['readonly']; - } - - if (!empty($fields['self'])) { - $fields['rel'] = Contact::SELF; - } - - $update_fields = DBStructure::getFieldsForTable('user-contact', $fields); + $update_fields = self::preparedFields($fields); if (!empty($update_fields)) { $contacts = DBA::select('contact', ['uri-id', 'uid'], $condition); while ($row = DBA::fetch($contacts)) { @@ -129,6 +107,29 @@ class User DBA::commit(); } + /** + * Prepare field data for update/insert + * + * @param array $fields + * @return array prepared fields + */ + private static function preparedFields(array $fields): array + { + unset($fields['uid']); + unset($fields['cid']); + unset($fields['uri-id']); + + if (isset($fields['readonly'])) { + $fields['ignored'] = $fields['readonly']; + } + + if (!empty($fields['self'])) { + $fields['rel'] = Contact::SELF; + } + + return DBStructure::getFieldsForTable('user-contact', $fields); + } + /** * Block contact id for user id * diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index b94df41cea..ef97c54f60 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1548,6 +1548,8 @@ return [ "subhub" => ["type" => "boolean", "comment" => ""], "hub-verify" => ["type" => "varchar(255)", "comment" => ""], "protocol" => ["type" => "char(4)", "comment" => "Protocol of the contact"], + "rating" => ["type" => "tinyint", "comment" => "Automatically detected feed poll frequency"], + "priority" => ["type" => "tinyint unsigned", "comment" => "Feed poll priority"], ], "indexes" => [ "PRIMARY" => ["uid", "cid"],