From: Hypolite Petovan Date: Wed, 26 Jul 2023 05:27:55 +0000 (+0200) Subject: [Database 1524] Fix contact-user.remote_self field type from boolean to integer X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=33b8680dfda73c31f70215955e73390d1ac73315;p=friendica.git [Database 1524] Fix contact-user.remote_self field type from boolean to integer - Move MIRROR_* constants to LocalRelationship entity - Convert boolean LocalRelationship->isRemoteSelf field to integer LocalRelationship->remoteSelf --- diff --git a/database.sql b/database.sql index 5af28131a8..74b7552c30 100644 --- a/database.sql +++ b/database.sql @@ -1,6 +1,6 @@ -- ------------------------------------------ -- Friendica 2023.09-dev (Giant Rhubarb) --- DB_UPDATE_VERSION 1523 +-- DB_UPDATE_VERSION 1524 -- ------------------------------------------ @@ -1834,7 +1834,7 @@ CREATE TABLE IF NOT EXISTS `user-contact` ( `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact', `info` mediumtext COMMENT '', `notify_new_posts` boolean COMMENT '', - `remote_self` boolean COMMENT '', + `remote_self` tinyint unsigned COMMENT '0 => No mirroring, 1-2 => Mirror as own post, 3 => Mirror as reshare', `fetch_further_information` tinyint unsigned COMMENT '0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both', `ffi_keyword_denylist` text COMMENT '', `subhub` boolean COMMENT '', diff --git a/src/Contact/LocalRelationship/Entity/LocalRelationship.php b/src/Contact/LocalRelationship/Entity/LocalRelationship.php index 287768b8c2..4fc7ae3660 100644 --- a/src/Contact/LocalRelationship/Entity/LocalRelationship.php +++ b/src/Contact/LocalRelationship/Entity/LocalRelationship.php @@ -36,7 +36,7 @@ use Friendica\Model\Contact; * @property-read int $rel * @property-read string $info * @property-read bool $notifyNewPosts - * @property-read bool $isRemoteSelf + * @property-read int $remoteSelf * @property-read int $fetchFurtherInformation * @property-read string $ffiKeywordDenylist * @property-read bool $subhub @@ -53,6 +53,10 @@ class LocalRelationship extends \Friendica\BaseEntity const FFI_KEYWORD = 3; const FFI_BOTH = 2; + const MIRROR_DEACTIVATED = 0; + const MIRROR_OWN_POST = 2; + const MIRROR_NATIVE_RESHARE = 3; + /** @var int */ protected $userId; /** @var int */ @@ -73,9 +77,8 @@ class LocalRelationship extends \Friendica\BaseEntity protected $info; /** @var bool */ protected $notifyNewPosts; - /** @var bool */ - protected $isRemoteSelf; - /** @var int */ + /** @var int One of MIRROR_* */ + protected $remoteSelf; /** @var int One of FFI_* */ protected $fetchFurtherInformation; /** @var string */ @@ -91,7 +94,7 @@ class LocalRelationship extends \Friendica\BaseEntity /** @var int */ protected $priority; - public function __construct(int $userId, int $contactId, bool $blocked = false, bool $ignored = false, bool $collapsed = false, bool $hidden = false, bool $pending = false, int $rel = Contact::NOTHING, string $info = '', bool $notifyNewPosts = false, bool $isRemoteSelf = false, int $fetchFurtherInformation = self::FFI_NONE, string $ffiKeywordDenylist = '', bool $subhub = false, string $hubVerify = '', string $protocol = Protocol::PHANTOM, ?int $rating = null, ?int $priority = null) + public function __construct(int $userId, int $contactId, bool $blocked = false, bool $ignored = false, bool $collapsed = false, bool $hidden = false, bool $pending = false, int $rel = Contact::NOTHING, string $info = '', bool $notifyNewPosts = false, int $remoteSelf = self::MIRROR_DEACTIVATED, int $fetchFurtherInformation = self::FFI_NONE, string $ffiKeywordDenylist = '', bool $subhub = false, string $hubVerify = '', string $protocol = Protocol::PHANTOM, ?int $rating = null, ?int $priority = null) { $this->userId = $userId; $this->contactId = $contactId; @@ -103,7 +106,7 @@ class LocalRelationship extends \Friendica\BaseEntity $this->rel = $rel; $this->info = $info; $this->notifyNewPosts = $notifyNewPosts; - $this->isRemoteSelf = $isRemoteSelf; + $this->remoteSelf = $remoteSelf; $this->fetchFurtherInformation = $fetchFurtherInformation; $this->ffiKeywordDenylist = $ffiKeywordDenylist; $this->subhub = $subhub; diff --git a/src/Contact/LocalRelationship/Factory/LocalRelationship.php b/src/Contact/LocalRelationship/Factory/LocalRelationship.php index 6885d68b24..54fc86215c 100644 --- a/src/Contact/LocalRelationship/Factory/LocalRelationship.php +++ b/src/Contact/LocalRelationship/Factory/LocalRelationship.php @@ -45,7 +45,7 @@ class LocalRelationship extends BaseFactory implements ICanCreateFromTableRow $row['rel'] ?? Contact::NOTHING, $row['info'] ?? '', $row['notify_new_posts'] ?? false, - $row['remote_self'] ?? false, + $row['remote_self'] ?? Entity\LocalRelationship::MIRROR_DEACTIVATED, $row['fetch_further_information'] ?? Entity\LocalRelationship::FFI_NONE, $row['ffi_keyword_denylist'] ?? '', $row['subhub'] ?? false, diff --git a/src/Contact/LocalRelationship/Repository/LocalRelationship.php b/src/Contact/LocalRelationship/Repository/LocalRelationship.php index a80a4f897b..490a84e44d 100644 --- a/src/Contact/LocalRelationship/Repository/LocalRelationship.php +++ b/src/Contact/LocalRelationship/Repository/LocalRelationship.php @@ -100,7 +100,7 @@ class LocalRelationship extends \Friendica\BaseRepository 'rel' => $localRelationship->rel, 'info' => $localRelationship->info, 'notify_new_posts' => $localRelationship->notifyNewPosts, - 'remote_self' => $localRelationship->isRemoteSelf, + 'remote_self' => $localRelationship->remoteSelf, 'fetch_further_information' => $localRelationship->fetchFurtherInformation, 'ffi_keyword_denylist' => $localRelationship->ffiKeywordDenylist, 'subhub' => $localRelationship->subhub, diff --git a/src/Model/Contact.php b/src/Model/Contact.php index 17be0b0cfd..23e1f2cbff 100644 --- a/src/Model/Contact.php +++ b/src/Model/Contact.php @@ -23,6 +23,7 @@ namespace Friendica\Model; use Friendica\Contact\Avatar; use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException; +use Friendica\Contact\LocalRelationship\Entity\LocalRelationship; use Friendica\Content\Conversation as ConversationContent; use Friendica\Content\Pager; use Friendica\Content\Text\HTML; @@ -111,10 +112,14 @@ class Contact * @} */ - const MIRROR_DEACTIVATED = 0; - const MIRROR_FORWARDED = 1; // Deprecated, now does the same like MIRROR_OWN_POST - const MIRROR_OWN_POST = 2; - const MIRROR_NATIVE_RESHARE = 3; + /** @deprecated Use Entity\LocalRelationship::MIRROR_DEACTIVATED instead */ + const MIRROR_DEACTIVATED = LocalRelationship::MIRROR_DEACTIVATED; + /** @deprecated Now does the same as MIRROR_OWN_POST */ + const MIRROR_FORWARDED = 1; + /** @deprecated Use Entity\LocalRelationship::MIRROR_OWN_POST instead */ + const MIRROR_OWN_POST = LocalRelationship::MIRROR_OWN_POST; + /** @deprecated Use Entity\LocalRelationship::MIRROR_NATIVE_RESHARE instead */ + const MIRROR_NATIVE_RESHARE = LocalRelationship::MIRROR_NATIVE_RESHARE; /** * @param array $fields Array of selected fields, empty for all diff --git a/src/Module/Contact/Profile.php b/src/Module/Contact/Profile.php index 294484a54b..090f7cd86a 100644 --- a/src/Module/Contact/Profile.php +++ b/src/Module/Contact/Profile.php @@ -394,7 +394,7 @@ class Profile extends BaseModule '$remote_self' => [ 'remote_self', $this->t('Mirror postings from this contact'), - $localRelationship->isRemoteSelf, + $localRelationship->remoteSelf, $this->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'), $remote_self_options ], diff --git a/static/dbstructure.config.php b/static/dbstructure.config.php index 09d90e27cd..970aeb9ccf 100644 --- a/static/dbstructure.config.php +++ b/static/dbstructure.config.php @@ -56,7 +56,7 @@ use Friendica\Database\DBA; // This file is required several times during the test in DbaDefinition which justifies this condition if (!defined('DB_UPDATE_VERSION')) { - define('DB_UPDATE_VERSION', 1523); + define('DB_UPDATE_VERSION', 1524); } return [ @@ -1826,7 +1826,7 @@ return [ "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" => ""], - "remote_self" => ["type" => "boolean", "comment" => ""], + "remote_self" => ["type" => "tinyint unsigned", "comment" => "0 => No mirroring, 1-2 => Mirror as own post, 3 => Mirror as reshare"], "fetch_further_information" => ["type" => "tinyint unsigned", "comment" => "0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both"], "ffi_keyword_denylist" => ["type" => "text", "comment" => ""], "subhub" => ["type" => "boolean", "comment" => ""], diff --git a/update.php b/update.php index 14219bcdcb..980ec721ab 100644 --- a/update.php +++ b/update.php @@ -1333,3 +1333,19 @@ function update_1520(): int return Update::SUCCESS; } + +/** + * user-contact.remote_self was wrongly declared as boolean, possibly truncating integer values from contact.remote_self + * + * @return int + * @throws Exception + */ +function update_1524(): int +{ + $contacts = DBA::select('contact', ['uid', 'uri-id', 'remote_self'], ["`uid` != ?", 0]); + while ($contact = DBA::fetch($contacts)) { + Contact\User::insertForContactArray($contact); + } + + return Update::SUCCESS; +}