From 4d92915846a7cb2f50a12390dd2c7d7764dae57e Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Tue, 30 Jun 2020 18:26:03 +0000 Subject: [PATCH] [MODULE] Move 'foreign' entities from core to a module --- modules/Bridge/Entity/ForeignLink.php | 205 ++++++++++++++++++ modules/Bridge/Entity/ForeignService.php | 122 +++++++++++ modules/Bridge/Entity/ForeignSubscription.php | 116 ++++++++++ modules/Bridge/Entity/ForeignUser.php | 138 ++++++++++++ 4 files changed, 581 insertions(+) create mode 100644 modules/Bridge/Entity/ForeignLink.php create mode 100644 modules/Bridge/Entity/ForeignService.php create mode 100644 modules/Bridge/Entity/ForeignSubscription.php create mode 100644 modules/Bridge/Entity/ForeignUser.php diff --git a/modules/Bridge/Entity/ForeignLink.php b/modules/Bridge/Entity/ForeignLink.php new file mode 100644 index 0000000000..652813b8fe --- /dev/null +++ b/modules/Bridge/Entity/ForeignLink.php @@ -0,0 +1,205 @@ +. +// }}} + +namespace Module\Entity; + +use DateTimeInterface; + +/** + * Entity for user's foreign profile + * + * @category DB + * @package GNUsocial + * + * @author Zach Copley + * @copyright 2010 StatusNet Inc. + * @author Mikael Nordfeldth + * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class ForeignLink +{ + // {{{ Autocode + + private int $user_id; + private int $foreign_id; + private int $service; + private ?string $credentials; + private int $noticesync; + private int $friendsync; + private int $profilesync; + private ?DateTimeInterface $last_noticesync; + private ?DateTimeInterface $last_friendsync; + private DateTimeInterface $created; + private DateTimeInterface $modified; + + public function setUserId(int $user_id): self + { + $this->user_id = $user_id; + return $this; + } + + public function getUserId(): int + { + return $this->user_id; + } + + public function setForeignId(int $foreign_id): self + { + $this->foreign_id = $foreign_id; + return $this; + } + + public function getForeignId(): int + { + return $this->foreign_id; + } + + public function setService(int $service): self + { + $this->service = $service; + return $this; + } + + public function getService(): int + { + return $this->service; + } + + public function setCredentials(?string $credentials): self + { + $this->credentials = $credentials; + return $this; + } + + public function getCredentials(): ?string + { + return $this->credentials; + } + + public function setNoticesync(int $noticesync): self + { + $this->noticesync = $noticesync; + return $this; + } + + public function getNoticesync(): int + { + return $this->noticesync; + } + + public function setFriendsync(int $friendsync): self + { + $this->friendsync = $friendsync; + return $this; + } + + public function getFriendsync(): int + { + return $this->friendsync; + } + + public function setProfilesync(int $profilesync): self + { + $this->profilesync = $profilesync; + return $this; + } + + public function getProfilesync(): int + { + return $this->profilesync; + } + + public function setLastNoticesync(?DateTimeInterface $last_noticesync): self + { + $this->last_noticesync = $last_noticesync; + return $this; + } + + public function getLastNoticesync(): ?DateTimeInterface + { + return $this->last_noticesync; + } + + public function setLastFriendsync(?DateTimeInterface $last_friendsync): self + { + $this->last_friendsync = $last_friendsync; + return $this; + } + + public function getLastFriendsync(): ?DateTimeInterface + { + return $this->last_friendsync; + } + + public function setCreated(DateTimeInterface $created): self + { + $this->created = $created; + return $this; + } + + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + public function setModified(DateTimeInterface $modified): self + { + $this->modified = $modified; + return $this; + } + + public function getModified(): DateTimeInterface + { + return $this->modified; + } + + // }}} Autocode + + public static function schemaDef(): array + { + return [ + 'name' => 'foreign_link', + 'fields' => [ + 'user_id' => ['type' => 'int', 'not null' => true, 'description' => 'link to user on this system, if exists'], + 'foreign_id' => ['type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'link to user on foreign service, if exists'], + 'service' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to service'], + 'credentials' => ['type' => 'varchar', 'length' => 191, 'description' => 'authc credentials, typically a password'], + 'noticesync' => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'notice synchronization, bit 1 = sync outgoing, bit 2 = sync incoming, bit 3 = filter local replies'], + 'friendsync' => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'], + 'profilesync' => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'], + 'last_noticesync' => ['type' => 'datetime', 'description' => 'last time notices were imported'], + 'last_friendsync' => ['type' => 'datetime', 'description' => 'last time friends were imported'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], + ], + 'primary key' => ['user_id', 'foreign_id', 'service'], + 'foreign keys' => [ + 'foreign_link_user_id_fkey' => ['user', ['user_id' => 'id']], + 'foreign_link_foreign_id_fkey' => ['foreign_user', ['foreign_id' => 'id', 'service' => 'service']], + 'foreign_link_service_fkey' => ['foreign_service', ['service' => 'id']], + ], + 'indexes' => [ + 'foreign_user_user_id_idx' => ['user_id'], + ], + ]; + } +} diff --git a/modules/Bridge/Entity/ForeignService.php b/modules/Bridge/Entity/ForeignService.php new file mode 100644 index 0000000000..b81ff65720 --- /dev/null +++ b/modules/Bridge/Entity/ForeignService.php @@ -0,0 +1,122 @@ +. +// }}} + +namespace Module\Entity; + +use DateTimeInterface; + +/** + * Entity for foreign services + * + * @category DB + * @package GNUsocial + * + * @author Zach Copley + * @copyright 2010 StatusNet Inc. + * @author Mikael Nordfeldth + * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class ForeignService +{ + // {{{ Autocode + + private int $id; + private string $name; + private ?string $description; + private DateTimeInterface $created; + private DateTimeInterface $modified; + + public function setId(int $id): self + { + $this->id = $id; + return $this; + } + + public function getId(): int + { + return $this->id; + } + + public function setName(string $name): self + { + $this->name = $name; + return $this; + } + + public function getName(): string + { + return $this->name; + } + + public function setDescription(?string $description): self + { + $this->description = $description; + return $this; + } + + public function getDescription(): ?string + { + return $this->description; + } + + public function setCreated(DateTimeInterface $created): self + { + $this->created = $created; + return $this; + } + + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + public function setModified(DateTimeInterface $modified): self + { + $this->modified = $modified; + return $this; + } + + public function getModified(): DateTimeInterface + { + return $this->modified; + } + + // }}} Autocode + + public static function schemaDef(): array + { + return [ + 'name' => 'foreign_service', + 'fields' => [ + 'id' => ['type' => 'int', 'not null' => true, 'description' => 'numeric key for service'], + 'name' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'name of the service'], + 'description' => ['type' => 'varchar', 'length' => 191, 'description' => 'description'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], + ], + 'primary key' => ['id'], + 'unique keys' => [ + 'foreign_service_name_key' => ['name'], + ], + ]; + } +} diff --git a/modules/Bridge/Entity/ForeignSubscription.php b/modules/Bridge/Entity/ForeignSubscription.php new file mode 100644 index 0000000000..ec01106dc9 --- /dev/null +++ b/modules/Bridge/Entity/ForeignSubscription.php @@ -0,0 +1,116 @@ +. +// }}} + +namespace Module\Entity; + +use DateTimeInterface; + +/** + * Entity for user's foreign subscriptions + * + * @category DB + * @package GNUsocial + * + * @author Zach Copley + * @copyright 2010 StatusNet Inc. + * @author Mikael Nordfeldth + * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class ForeignSubscription +{ + // {{{ Autocode + + private int $service; + private int $subscriber; + private int $subscribed; + private DateTimeInterface $created; + + public function setService(int $service): self + { + $this->service = $service; + return $this; + } + + public function getService(): int + { + return $this->service; + } + + public function setSubscriber(int $subscriber): self + { + $this->subscriber = $subscriber; + return $this; + } + + public function getSubscriber(): int + { + return $this->subscriber; + } + + public function setSubscribed(int $subscribed): self + { + $this->subscribed = $subscribed; + return $this; + } + + public function getSubscribed(): int + { + return $this->subscribed; + } + + public function setCreated(DateTimeInterface $created): self + { + $this->created = $created; + return $this; + } + + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + // }}} Autocode + + public static function schemaDef(): array + { + return [ + 'name' => 'foreign_subscription', + + 'fields' => [ + 'service' => ['type' => 'int', 'not null' => true, 'description' => 'service where relationship happens'], + 'subscriber' => ['type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'subscriber on foreign service'], + 'subscribed' => ['type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'subscribed user'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'], + ], + 'primary key' => ['service', 'subscriber', 'subscribed'], + 'foreign keys' => [ + 'foreign_subscription_service_fkey' => ['foreign_service', ['service' => 'id']], + 'foreign_subscription_subscriber_fkey' => ['foreign_user', ['subscriber' => 'id', 'service' => 'service']], + 'foreign_subscription_subscribed_fkey' => ['foreign_user', ['subscribed' => 'id', 'service' => 'service']], + ], + 'indexes' => [ + 'foreign_subscription_subscriber_idx' => ['service', 'subscriber'], + 'foreign_subscription_subscribed_idx' => ['service', 'subscribed'], + ], + ]; + } +} diff --git a/modules/Bridge/Entity/ForeignUser.php b/modules/Bridge/Entity/ForeignUser.php new file mode 100644 index 0000000000..5f32fa18d5 --- /dev/null +++ b/modules/Bridge/Entity/ForeignUser.php @@ -0,0 +1,138 @@ +. +// }}} + +namespace Module\Entity; + +use DateTimeInterface; + +/** + * Entity for Foreign Users + * + * @category DB + * @package GNUsocial + * + * @author Zach Copley + * @copyright 2010 StatusNet Inc. + * @author Mikael Nordfeldth + * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ +class ForeignUser +{ + // {{{ Autocode + + private int $id; + private int $service; + private string $uri; + private ?string $nickname; + private DateTimeInterface $created; + private DateTimeInterface $modified; + + public function setId(int $id): self + { + $this->id = $id; + return $this; + } + + public function getId(): int + { + return $this->id; + } + + public function setService(int $service): self + { + $this->service = $service; + return $this; + } + + public function getService(): int + { + return $this->service; + } + + public function setUri(string $uri): self + { + $this->uri = $uri; + return $this; + } + + public function getUri(): string + { + return $this->uri; + } + + public function setNickname(?string $nickname): self + { + $this->nickname = $nickname; + return $this; + } + + public function getNickname(): ?string + { + return $this->nickname; + } + + public function setCreated(DateTimeInterface $created): self + { + $this->created = $created; + return $this; + } + + public function getCreated(): DateTimeInterface + { + return $this->created; + } + + public function setModified(DateTimeInterface $modified): self + { + $this->modified = $modified; + return $this; + } + + public function getModified(): DateTimeInterface + { + return $this->modified; + } + + // }}} Autocode + + public static function schemaDef(): array + { + return [ + 'name' => 'foreign_user', + 'fields' => [ + 'id' => ['type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'], + 'service' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to service'], + 'uri' => ['type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'identifying URI'], + 'nickname' => ['type' => 'varchar', 'length' => 191, 'description' => 'nickname on foreign service'], + 'created' => ['type' => 'datetime', 'not null' => true, 'default' => '0000-00-00 00:00:00', 'description' => 'date this record was created'], + 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'], + ], + 'primary key' => ['id', 'service'], + 'foreign keys' => [ + 'foreign_user_service_fkey' => ['foreign_service', ['service' => 'id']], + ], + 'unique keys' => [ + 'foreign_user_uri_key' => ['uri'], + ], + ]; + } +}