[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
This commit is contained in:
Hypolite Petovan 2023-07-26 07:27:55 +02:00
parent d0a2357fbd
commit 33b8680dfd
8 changed files with 41 additions and 17 deletions

View file

@ -1,6 +1,6 @@
-- ------------------------------------------ -- ------------------------------------------
-- Friendica 2023.09-dev (Giant Rhubarb) -- 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', `rel` tinyint unsigned COMMENT 'The kind of the relation between the user and the contact',
`info` mediumtext COMMENT '', `info` mediumtext COMMENT '',
`notify_new_posts` boolean 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', `fetch_further_information` tinyint unsigned COMMENT '0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both',
`ffi_keyword_denylist` text COMMENT '', `ffi_keyword_denylist` text COMMENT '',
`subhub` boolean COMMENT '', `subhub` boolean COMMENT '',

View file

@ -36,7 +36,7 @@ use Friendica\Model\Contact;
* @property-read int $rel * @property-read int $rel
* @property-read string $info * @property-read string $info
* @property-read bool $notifyNewPosts * @property-read bool $notifyNewPosts
* @property-read bool $isRemoteSelf * @property-read int $remoteSelf
* @property-read int $fetchFurtherInformation * @property-read int $fetchFurtherInformation
* @property-read string $ffiKeywordDenylist * @property-read string $ffiKeywordDenylist
* @property-read bool $subhub * @property-read bool $subhub
@ -53,6 +53,10 @@ class LocalRelationship extends \Friendica\BaseEntity
const FFI_KEYWORD = 3; const FFI_KEYWORD = 3;
const FFI_BOTH = 2; const FFI_BOTH = 2;
const MIRROR_DEACTIVATED = 0;
const MIRROR_OWN_POST = 2;
const MIRROR_NATIVE_RESHARE = 3;
/** @var int */ /** @var int */
protected $userId; protected $userId;
/** @var int */ /** @var int */
@ -73,9 +77,8 @@ class LocalRelationship extends \Friendica\BaseEntity
protected $info; protected $info;
/** @var bool */ /** @var bool */
protected $notifyNewPosts; protected $notifyNewPosts;
/** @var bool */ /** @var int One of MIRROR_* */
protected $isRemoteSelf; protected $remoteSelf;
/** @var int */
/** @var int One of FFI_* */ /** @var int One of FFI_* */
protected $fetchFurtherInformation; protected $fetchFurtherInformation;
/** @var string */ /** @var string */
@ -91,7 +94,7 @@ class LocalRelationship extends \Friendica\BaseEntity
/** @var int */ /** @var int */
protected $priority; 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->userId = $userId;
$this->contactId = $contactId; $this->contactId = $contactId;
@ -103,7 +106,7 @@ class LocalRelationship extends \Friendica\BaseEntity
$this->rel = $rel; $this->rel = $rel;
$this->info = $info; $this->info = $info;
$this->notifyNewPosts = $notifyNewPosts; $this->notifyNewPosts = $notifyNewPosts;
$this->isRemoteSelf = $isRemoteSelf; $this->remoteSelf = $remoteSelf;
$this->fetchFurtherInformation = $fetchFurtherInformation; $this->fetchFurtherInformation = $fetchFurtherInformation;
$this->ffiKeywordDenylist = $ffiKeywordDenylist; $this->ffiKeywordDenylist = $ffiKeywordDenylist;
$this->subhub = $subhub; $this->subhub = $subhub;

View file

@ -45,7 +45,7 @@ class LocalRelationship extends BaseFactory implements ICanCreateFromTableRow
$row['rel'] ?? Contact::NOTHING, $row['rel'] ?? Contact::NOTHING,
$row['info'] ?? '', $row['info'] ?? '',
$row['notify_new_posts'] ?? false, $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['fetch_further_information'] ?? Entity\LocalRelationship::FFI_NONE,
$row['ffi_keyword_denylist'] ?? '', $row['ffi_keyword_denylist'] ?? '',
$row['subhub'] ?? false, $row['subhub'] ?? false,

View file

@ -100,7 +100,7 @@ class LocalRelationship extends \Friendica\BaseRepository
'rel' => $localRelationship->rel, 'rel' => $localRelationship->rel,
'info' => $localRelationship->info, 'info' => $localRelationship->info,
'notify_new_posts' => $localRelationship->notifyNewPosts, 'notify_new_posts' => $localRelationship->notifyNewPosts,
'remote_self' => $localRelationship->isRemoteSelf, 'remote_self' => $localRelationship->remoteSelf,
'fetch_further_information' => $localRelationship->fetchFurtherInformation, 'fetch_further_information' => $localRelationship->fetchFurtherInformation,
'ffi_keyword_denylist' => $localRelationship->ffiKeywordDenylist, 'ffi_keyword_denylist' => $localRelationship->ffiKeywordDenylist,
'subhub' => $localRelationship->subhub, 'subhub' => $localRelationship->subhub,

View file

@ -23,6 +23,7 @@ namespace Friendica\Model;
use Friendica\Contact\Avatar; use Friendica\Contact\Avatar;
use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException; use Friendica\Contact\Introduction\Exception\IntroductionNotFoundException;
use Friendica\Contact\LocalRelationship\Entity\LocalRelationship;
use Friendica\Content\Conversation as ConversationContent; use Friendica\Content\Conversation as ConversationContent;
use Friendica\Content\Pager; use Friendica\Content\Pager;
use Friendica\Content\Text\HTML; use Friendica\Content\Text\HTML;
@ -111,10 +112,14 @@ class Contact
* @} * @}
*/ */
const MIRROR_DEACTIVATED = 0; /** @deprecated Use Entity\LocalRelationship::MIRROR_DEACTIVATED instead */
const MIRROR_FORWARDED = 1; // Deprecated, now does the same like MIRROR_OWN_POST const MIRROR_DEACTIVATED = LocalRelationship::MIRROR_DEACTIVATED;
const MIRROR_OWN_POST = 2; /** @deprecated Now does the same as MIRROR_OWN_POST */
const MIRROR_NATIVE_RESHARE = 3; 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 * @param array $fields Array of selected fields, empty for all

View file

@ -394,7 +394,7 @@ class Profile extends BaseModule
'$remote_self' => [ '$remote_self' => [
'remote_self', 'remote_self',
$this->t('Mirror postings from this contact'), $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.'), $this->t('Mark this contact as remote_self, this will cause friendica to repost new entries from this contact.'),
$remote_self_options $remote_self_options
], ],

View file

@ -56,7 +56,7 @@ use Friendica\Database\DBA;
// This file is required several times during the test in DbaDefinition which justifies this condition // This file is required several times during the test in DbaDefinition which justifies this condition
if (!defined('DB_UPDATE_VERSION')) { if (!defined('DB_UPDATE_VERSION')) {
define('DB_UPDATE_VERSION', 1523); define('DB_UPDATE_VERSION', 1524);
} }
return [ return [
@ -1826,7 +1826,7 @@ return [
"rel" => ["type" => "tinyint unsigned", "comment" => "The kind of the relation between the user and the contact"], "rel" => ["type" => "tinyint unsigned", "comment" => "The kind of the relation between the user and the contact"],
"info" => ["type" => "mediumtext", "comment" => ""], "info" => ["type" => "mediumtext", "comment" => ""],
"notify_new_posts" => ["type" => "boolean", "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"], "fetch_further_information" => ["type" => "tinyint unsigned", "comment" => "0 => None, 1 => Fetch information, 3 => Fetch keywords, 2 => Fetch both"],
"ffi_keyword_denylist" => ["type" => "text", "comment" => ""], "ffi_keyword_denylist" => ["type" => "text", "comment" => ""],
"subhub" => ["type" => "boolean", "comment" => ""], "subhub" => ["type" => "boolean", "comment" => ""],

View file

@ -1333,3 +1333,19 @@ function update_1520(): int
return Update::SUCCESS; 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;
}