ForeignLink.php 6.5 KB

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