Foreign_user.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. // This file is part of GNU social - https://www.gnu.org/software/social
  3. //
  4. // GNU social is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU Affero General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // GNU social is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Affero General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU Affero General Public License
  15. // along with GNU social. If not, see <http://www.gnu.org/licenses/>.
  16. /**
  17. * Table Definition for foreign_user
  18. */
  19. defined('GNUSOCIAL') || die();
  20. class Foreign_user extends Managed_DataObject
  21. {
  22. ###START_AUTOCODE
  23. /* the code below is auto generated do not remove the above tag */
  24. public $__table = 'foreign_user'; // table name
  25. public $id; // bigint(8) primary_key not_null
  26. public $service; // int(4) primary_key not_null
  27. public $uri; // varchar(191) unique_key not_null not 255 because utf8mb4 takes more space
  28. public $nickname; // varchar(191) not 255 because utf8mb4 takes more space
  29. public $created; // datetime()
  30. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  31. /* the code above is auto generated do not remove the tag below */
  32. ###END_AUTOCODE
  33. public static function schemaDef()
  34. {
  35. return array(
  36. 'fields' => array(
  37. 'id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'unique numeric key on foreign service'),
  38. 'service' => array('type' => 'int', 'not null' => true, 'description' => 'foreign key to service'),
  39. 'uri' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'identifying URI'),
  40. 'nickname' => array('type' => 'varchar', 'length' => 191, 'description' => 'nickname on foreign service'),
  41. 'created' => array('type' => 'datetime', 'description' => 'date this record was created'),
  42. 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
  43. ),
  44. 'primary key' => array('id', 'service'),
  45. 'foreign keys' => array(
  46. 'foreign_user_service_fkey' => array('foreign_service', array('service' => 'id')),
  47. ),
  48. 'unique keys' => array(
  49. 'foreign_user_uri_key' => array('uri'),
  50. ),
  51. 'indexes' => array(
  52. 'foreign_user_service_idx' => array('service'),
  53. ),
  54. );
  55. }
  56. public static function getForeignUser($id, $service)
  57. {
  58. if (empty($id) || empty($service)) {
  59. throw new ServerException('Empty foreign user id or service for Foreign_user::getForeignUser');
  60. }
  61. $fuser = new Foreign_user();
  62. $fuser->id = $id;
  63. $fuser->service = $service;
  64. $fuser->limit(1);
  65. if (!$fuser->find(true)) {
  66. throw new NoResultException($fuser);
  67. }
  68. return $fuser;
  69. }
  70. public static function getByNickname($nickname, $service)
  71. {
  72. if (empty($nickname) || empty($service)) {
  73. throw new ServerException('Empty nickname or service for Foreign_user::getByNickname');
  74. }
  75. $fuser = new Foreign_user();
  76. $fuser->service = $service;
  77. $fuser->nickname = $nickname;
  78. $fuser->limit(1);
  79. if (!$fuser->find(true)) {
  80. throw new NoResultException($fuser);
  81. }
  82. return $fuser;
  83. }
  84. }