ForeignLink.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. <?php
  2. declare(strict_types = 1);
  3. // {{{ License
  4. // This file is part of GNU social - https://www.gnu.org/software/social
  5. //
  6. // GNU social is free software: you can redistribute it and/or modify
  7. // it under the terms of the GNU Affero General Public License as published by
  8. // the Free Software Foundation, either version 3 of the License, or
  9. // (at your option) any later version.
  10. //
  11. // GNU social is distributed in the hope that it will be useful,
  12. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. // GNU Affero General Public License for more details.
  15. //
  16. // You should have received a copy of the GNU Affero General Public License
  17. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  18. // }}}
  19. namespace Component\Bridge\Entity;
  20. use DateTimeInterface;
  21. /**
  22. * Entity for user's foreign profile
  23. *
  24. * @category DB
  25. * @package GNUsocial
  26. *
  27. * @author Zach Copley <zach@status.net>
  28. * @copyright 2010 StatusNet Inc.
  29. * @author Mikael Nordfeldth <mmn@hethane.se>
  30. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org
  31. * @author Hugo Sales <hugo@hsal.es>
  32. * @copyright 2020-2021 Free Software Foundation, Inc http://www.fsf.org
  33. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  34. */
  35. class ForeignLink
  36. {
  37. // {{{ Autocode
  38. // @codeCoverageIgnoreStart
  39. private int $user_id;
  40. private int $foreign_id;
  41. private int $service;
  42. private ?string $credentials = null;
  43. private int $noticesync = 1;
  44. private int $friendsync = 2;
  45. private int $profilesync = 1;
  46. private ?DateTimeInterface $last_noticesync = null;
  47. private ?DateTimeInterface $last_friendsync = null;
  48. private DateTimeInterface $created;
  49. private DateTimeInterface $modified;
  50. public function setUserId(int $user_id): self
  51. {
  52. $this->user_id = $user_id;
  53. return $this;
  54. }
  55. public function getUserId(): int
  56. {
  57. return $this->user_id;
  58. }
  59. public function setForeignId(int $foreign_id): self
  60. {
  61. $this->foreign_id = $foreign_id;
  62. return $this;
  63. }
  64. public function getForeignId(): int
  65. {
  66. return $this->foreign_id;
  67. }
  68. public function setService(int $service): self
  69. {
  70. $this->service = $service;
  71. return $this;
  72. }
  73. public function getService(): int
  74. {
  75. return $this->service;
  76. }
  77. public function setCredentials(?string $credentials): self
  78. {
  79. $this->credentials = \is_null($credentials) ? null : mb_substr($credentials, 0, 191);
  80. return $this;
  81. }
  82. public function getCredentials(): ?string
  83. {
  84. return $this->credentials;
  85. }
  86. public function setNoticesync(int $noticesync): self
  87. {
  88. $this->noticesync = $noticesync;
  89. return $this;
  90. }
  91. public function getNoticesync(): int
  92. {
  93. return $this->noticesync;
  94. }
  95. public function setFriendsync(int $friendsync): self
  96. {
  97. $this->friendsync = $friendsync;
  98. return $this;
  99. }
  100. public function getFriendsync(): int
  101. {
  102. return $this->friendsync;
  103. }
  104. public function setProfilesync(int $profilesync): self
  105. {
  106. $this->profilesync = $profilesync;
  107. return $this;
  108. }
  109. public function getProfilesync(): int
  110. {
  111. return $this->profilesync;
  112. }
  113. public function setLastNoticesync(?DateTimeInterface $last_noticesync): self
  114. {
  115. $this->last_noticesync = $last_noticesync;
  116. return $this;
  117. }
  118. public function getLastNoticesync(): ?DateTimeInterface
  119. {
  120. return $this->last_noticesync;
  121. }
  122. public function setLastFriendsync(?DateTimeInterface $last_friendsync): self
  123. {
  124. $this->last_friendsync = $last_friendsync;
  125. return $this;
  126. }
  127. public function getLastFriendsync(): ?DateTimeInterface
  128. {
  129. return $this->last_friendsync;
  130. }
  131. public function setCreated(DateTimeInterface $created): self
  132. {
  133. $this->created = $created;
  134. return $this;
  135. }
  136. public function getCreated(): DateTimeInterface
  137. {
  138. return $this->created;
  139. }
  140. public function setModified(DateTimeInterface $modified): self
  141. {
  142. $this->modified = $modified;
  143. return $this;
  144. }
  145. public function getModified(): DateTimeInterface
  146. {
  147. return $this->modified;
  148. }
  149. // @codeCoverageIgnoreEnd
  150. // }}} Autocode
  151. public static function schemaDef(): array
  152. {
  153. return [
  154. 'name' => 'foreign_link',
  155. 'fields' => [
  156. 'user_id' => ['type' => 'int', 'not null' => true, 'description' => 'link to user on this system, if exists'],
  157. 'foreign_id' => ['type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'link to user on foreign service, if exists'],
  158. 'service' => ['type' => 'int', 'not null' => true, 'description' => 'foreign key to service'],
  159. 'credentials' => ['type' => 'varchar', 'length' => 191, 'description' => 'authc credentials, typically a password'],
  160. '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'],
  161. 'friendsync' => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 2, 'description' => 'friend synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'],
  162. 'profilesync' => ['type' => 'int', 'size' => 'tiny', 'not null' => true, 'default' => 1, 'description' => 'profile synchronization, bit 1 = sync outgoing, bit 2 = sync incoming'],
  163. 'last_noticesync' => ['type' => 'datetime', 'description' => 'last time notices were imported'],
  164. 'last_friendsync' => ['type' => 'datetime', 'description' => 'last time friends were imported'],
  165. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  166. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  167. ],
  168. 'primary key' => ['user_id', 'foreign_id', 'service'],
  169. 'foreign keys' => [
  170. 'foreign_link_user_id_fkey' => ['user', ['user_id' => 'id']],
  171. 'foreign_link_foreign_id_fkey' => ['foreign_user', ['foreign_id' => 'id', 'service' => 'service']],
  172. 'foreign_link_service_fkey' => ['foreign_service', ['service' => 'id']],
  173. ],
  174. 'indexes' => [
  175. 'foreign_user_user_id_idx' => ['user_id'],
  176. ],
  177. ];
  178. }
  179. }