ActivitypubObject.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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. /**
  20. * ActivityPub implementation for GNU social
  21. *
  22. * @package GNUsocial
  23. * @category ActivityPub
  24. *
  25. * @author Diogo Peralta Cordeiro <@diogo.site>
  26. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  27. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  28. */
  29. namespace Plugin\ActivityPub\Entity;
  30. use App\Core\DB\DB;
  31. use App\Core\Entity;
  32. use DateTimeInterface;
  33. /**
  34. * Table Definition for activitypub_object
  35. *
  36. * @copyright 2021 Free Software Foundation, Inc http://www.fsf.org
  37. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  38. */
  39. class ActivitypubObject extends Entity
  40. {
  41. // {{{ Autocode
  42. // @codeCoverageIgnoreStart
  43. private string $object_uri;
  44. private string $object_type;
  45. private int $object_id;
  46. private DateTimeInterface $created;
  47. private DateTimeInterface $modified;
  48. public function setObjectUri(string $object_uri): self
  49. {
  50. $this->object_uri = $object_uri;
  51. return $this;
  52. }
  53. public function getObjectUri(): string
  54. {
  55. return $this->object_uri;
  56. }
  57. public function setObjectType(string $object_type): self
  58. {
  59. $this->object_type = mb_substr($object_type, 0, 32);
  60. return $this;
  61. }
  62. public function getObjectType(): string
  63. {
  64. return $this->object_type;
  65. }
  66. public function setObjectId(int $object_id): self
  67. {
  68. $this->object_id = $object_id;
  69. return $this;
  70. }
  71. public function getObjectId(): int
  72. {
  73. return $this->object_id;
  74. }
  75. public function setCreated(DateTimeInterface $created): self
  76. {
  77. $this->created = $created;
  78. return $this;
  79. }
  80. public function getCreated(): DateTimeInterface
  81. {
  82. return $this->created;
  83. }
  84. public function setModified(DateTimeInterface $modified): self
  85. {
  86. $this->modified = $modified;
  87. return $this;
  88. }
  89. public function getModified(): DateTimeInterface
  90. {
  91. return $this->modified;
  92. }
  93. // @codeCoverageIgnoreEnd
  94. // }}} Autocode
  95. public function getObject()
  96. {
  97. return DB::findOneBy($this->getObjectType(), ['id' => $this->getObjectId()]);
  98. }
  99. public static function schemaDef(): array
  100. {
  101. return [
  102. 'name' => 'activitypub_object',
  103. 'fields' => [
  104. 'object_uri' => ['type' => 'text', 'not null' => true, 'description' => 'Object\'s URI'],
  105. 'object_type' => ['type' => 'varchar', 'length' => 32, 'not null' => true, 'description' => 'the name of the table this object refers to'],
  106. 'object_id' => ['type' => 'int', 'not null' => true, 'description' => 'id in the referenced table'],
  107. 'created' => ['type' => 'datetime', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was created'],
  108. 'modified' => ['type' => 'timestamp', 'not null' => true, 'default' => 'CURRENT_TIMESTAMP', 'description' => 'date this record was modified'],
  109. ],
  110. 'primary key' => ['object_uri'],
  111. 'indexes' => [
  112. 'activity_object_uri_idx' => ['object_uri'],
  113. ],
  114. ];
  115. }
  116. }