]> git.mxchange.org Git - friendica.git/commitdiff
[Database 1524] Fix contact-user.remote_self field type from boolean to integer
authorHypolite Petovan <hypolite@mrpetovan.com>
Wed, 26 Jul 2023 05:27:55 +0000 (07:27 +0200)
committerHypolite Petovan <hypolite@mrpetovan.com>
Wed, 2 Aug 2023 19:53:10 +0000 (21:53 +0200)
- Move MIRROR_* constants to LocalRelationship entity
- Convert boolean LocalRelationship->isRemoteSelf field to integer LocalRelationship->remoteSelf

database.sql
src/Contact/LocalRelationship/Entity/LocalRelationship.php
src/Contact/LocalRelationship/Factory/LocalRelationship.php
src/Contact/LocalRelationship/Repository/LocalRelationship.php
src/Model/Contact.php
src/Module/Contact/Profile.php
static/dbstructure.config.php
update.php

index 5af28131a800e2d4aa84bdd822c74acc06b6e270..74b7552c30af00483081603be3de3428d9ba7c19 100644 (file)
@@ -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 '',
index 287768b8c2badc7a97d7741bde64bbcdb434056b..4fc7ae36604572314af7ce55710097878be214ae 100644 (file)
@@ -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;
index 6885d68b241ed83fe4fce96e62cd230ce34df816..54fc86215c05f6fd72fda8fd023e3ac01e8011ff 100644 (file)
@@ -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,
index a80a4f897b55aa52019df47ddb7598e35c01194e..490a84e44d334d04b5d0ceb0edfe978dc766b57c 100644 (file)
@@ -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,
index 17be0b0cfdfc7e335162c5d8f04aeebc9c5349ad..23e1f2cbff2b30b795b309e408a76fdb1c1e22ae 100644 (file)
@@ -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
index 294484a54be2489d08182c2d7703fa1fb9955654..090f7cd86a21c1e4011b3d0e212e9c00261aeb7c 100644 (file)
@@ -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
                        ],
index 09d90e27cdcd28254345311b532b73fdd735623e..970aeb9ccf481f4bbdcc14d737dfc746ec1c1e67 100644 (file)
@@ -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" => ""],
index 14219bcdcb3b7280d8c18159a25ab0e4da3785b2..980ec721ab281db90676eab2cb59e03953c3f730 100644 (file)
@@ -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;
+}