RSSCloudSubscription.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 rsscloud_subscription
  18. *
  19. * @category Plugin
  20. * @package GNUsocial
  21. * @author Zach Copley <zach@status.net>
  22. * @copyright 2008, 2009 StatusNet, Inc.
  23. * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later
  24. */
  25. defined('GNUSOCIAL') || die();
  26. class RSSCloudSubscription extends Managed_DataObject
  27. {
  28. public $__table='rsscloud_subscription'; // table name
  29. public $subscribed; // int primary key user id
  30. public $url; // string primary key
  31. public $failures; // int
  32. public $created; // datestamp()
  33. public $modified; // timestamp() not_null default_CURRENT_TIMESTAMP
  34. public static function schemaDef(): array
  35. {
  36. return [
  37. 'fields' => [
  38. 'subscribed' => ['type' => 'int', 'not null' => true],
  39. 'url' => ['type' => 'varchar', 'length' => '191', 'not null' => true],
  40. 'failures' => ['type' => 'int', 'not null' => true, 'default' => 0],
  41. 'created' => ['type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'],
  42. 'modified' => ['type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'],
  43. ],
  44. 'primary key' => ['subscribed', 'url'],
  45. 'foreign keys' => [
  46. 'rsscloud_subscription_subscribed_fkey' => ['user', ['subscribed' => 'id']],
  47. ],
  48. ];
  49. }
  50. public static function getSubscription(
  51. int $subscribed,
  52. string $url
  53. ): ?self {
  54. $sub = new RSSCloudSubscription();
  55. $sub->whereAdd("subscribed = {$subscribed}");
  56. $sub->whereAdd("url = '{$sub->escape($url)}'");
  57. $sub->limit(1);
  58. if ($sub->find()) {
  59. $sub->fetch();
  60. return $sub;
  61. }
  62. return null;
  63. }
  64. }