From b170dd765d411eff599fb908c4b05982c9460220 Mon Sep 17 00:00:00 2001 From: Michael Date: Fri, 10 Sep 2021 20:53:10 +0000 Subject: [PATCH] Insert and update some more fields --- database.sql | 5 +++++ doc/database/db_user-contact.md | 21 +++++++++++++-------- src/Model/Contact/User.php | 18 +++++++++++------- static/dbstructure.config.php | 7 ++++++- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/database.sql b/database.sql index dd04a0e352..adbd5046a1 100644 --- a/database.sql +++ b/database.sql @@ -1516,6 +1516,11 @@ CREATE TABLE IF NOT EXISTS `user-contact` ( `blocked` boolean COMMENT 'Contact is completely blocked for this user', `ignored` boolean COMMENT 'Posts from this contact are ignored', `collapsed` boolean COMMENT 'Posts from this contact are collapsed', + `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact', + `info` mediumtext COMMENT '', + `notify_new_posts` boolean COMMENT '', + `fetch_further_information` tinyint unsigned COMMENT '', + `ffi_keyword_denylist` text COMMENT '', 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 467ee86d90..aa74516f17 100644 --- a/doc/database/db_user-contact.md +++ b/doc/database/db_user-contact.md @@ -6,14 +6,19 @@ User specific public contact data Fields ------ -| Field | Description | Type | Null | Key | Default | Extra | -| --------- | ------------------------------------------------------------ | ------------------ | ---- | --- | ------- | ----- | -| cid | Contact id of the linked public contact | int unsigned | NO | PRI | 0 | | -| uid | User id | mediumint unsigned | NO | PRI | 0 | | -| uri-id | Id of the item-uri table entry that contains the contact url | int unsigned | YES | | NULL | | -| blocked | Contact is completely blocked for this user | boolean | YES | | NULL | | -| ignored | Posts from this contact are ignored | boolean | YES | | NULL | | -| collapsed | Posts from this contact are collapsed | boolean | YES | | NULL | | +| Field | Description | Type | Null | Key | Default | Extra | +| ------------------------- | ------------------------------------------------------------ | ------------------ | ---- | --- | ------- | ----- | +| cid | Contact id of the linked public contact | int unsigned | NO | PRI | 0 | | +| uid | User id | mediumint unsigned | NO | PRI | 0 | | +| uri-id | Id of the item-uri table entry that contains the contact url | int unsigned | YES | | NULL | | +| blocked | Contact is completely blocked for this user | boolean | YES | | NULL | | +| ignored | Posts from this contact are ignored | boolean | YES | | NULL | | +| collapsed | Posts from this contact are collapsed | boolean | YES | | NULL | | +| rel | The kind of the relation between the user and the contact | tinyint unsigned | YES | | NULL | | +| info | | mediumtext | YES | | NULL | | +| notify_new_posts | | boolean | YES | | NULL | | +| fetch_further_information | | tinyint unsigned | YES | | NULL | | +| ffi_keyword_denylist | | text | YES | | NULL | | Indexes ------------ diff --git a/src/Model/Contact/User.php b/src/Model/Contact/User.php index e46af5191f..bf6fa8a947 100644 --- a/src/Model/Contact/User.php +++ b/src/Model/Contact/User.php @@ -22,6 +22,7 @@ namespace Friendica\Model\Contact; use Exception; +use Friendica\Collection\Api\Mastodon\Fields; use Friendica\Core\Logger; use Friendica\Core\System; use Friendica\Database\Database; @@ -59,13 +60,16 @@ class User return false; } - $fields = [ - 'cid' => $pcontact['id'], - 'uid' => $contact['uid'], - 'uri-id' => $contact['uri-id'], - 'blocked' => $contact['blocked'] ?? false, - 'ignored' => $contact['readonly'] ?? false, - ]; + $fields = $contact; + + if (isset($fields['readonly'])) { + $fields['ignored'] = $fields['readonly']; + } + + $fields = DBStructure::getFieldsForTable('user-contact', $fields); + $fields['cid'] = $pcontact['id']; + $fields['uid'] = $contact['uid']; + $fields['uri-id'] = $contact['uri-id']; $ret = DBA::insert('user-contact', $fields, Database::INSERT_IGNORE); diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index fd6c4c798f..b501ea4df5 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -1534,7 +1534,12 @@ return [ "uri-id" => ["type" => "int unsigned", "foreign" => ["item-uri" => "id"], "comment" => "Id of the item-uri table entry that contains the contact url"], "blocked" => ["type" => "boolean", "comment" => "Contact is completely blocked for this user"], "ignored" => ["type" => "boolean", "comment" => "Posts from this contact are ignored"], - "collapsed" => ["type" => "boolean", "comment" => "Posts from this contact are collapsed"] + "collapsed" => ["type" => "boolean", "comment" => "Posts from this contact are collapsed"], + "rel" => ["type" => "tinyint unsigned", "comment" => "The kind of the relation between the user and the contact"], + "info" => ["type" => "mediumtext", "comment" => ""], + "notify_new_posts" => ["type" => "boolean", "comment" => ""], + "fetch_further_information" => ["type" => "tinyint unsigned", "comment" => ""], + "ffi_keyword_denylist" => ["type" => "text", "comment" => ""], ], "indexes" => [ "PRIMARY" => ["uid", "cid"],