Ostatus_source.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /*
  3. * StatusNet - the distributed open-source microblogging tool
  4. * Copyright (C) 2010, StatusNet, Inc.
  5. *
  6. * This program 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. * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. if (!defined('STATUSNET')) {
  20. exit(1);
  21. }
  22. /**
  23. * @package OStatusPlugin
  24. * @maintainer Brion Vibber <brion@status.net>
  25. */
  26. class Ostatus_source extends Managed_DataObject
  27. {
  28. public $__table = 'ostatus_source';
  29. public $notice_id; // notice we're referring to
  30. public $profile_uri; // uri of the ostatus_profile this came through -- may be a group feed
  31. public $method; // push or salmon
  32. public $created;
  33. public $modified;
  34. public static function schemaDef()
  35. {
  36. return array(
  37. 'fields' => array(
  38. 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'Notice ID relation'),
  39. 'profile_uri' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'Profile URI'),
  40. 'method' => array('type' => 'enum("push","salmon")', 'not null' => true, 'description' => 'source method'),
  41. 'created' => array('type' => 'datetime', 'not null' => true, '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('notice_id'),
  45. 'foreign keys' => array(
  46. 'ostatus_source_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
  47. // not in profile table yet 'ostatus_source_profile_uri_fkey' => array('profile', array('profile_uri' => 'uri')),
  48. ),
  49. 'indexes' => array(
  50. 'ostatus_source_profile_uri_idx' => array('profile_uri'),
  51. ),
  52. );
  53. }
  54. /**
  55. * Save a remote notice source record; this helps indicate how trusted we are.
  56. * @param string $method
  57. */
  58. public static function saveNew(Notice $notice, Ostatus_profile $oprofile, $method)
  59. {
  60. $osource = new Ostatus_source();
  61. $osource->notice_id = $notice->id;
  62. $osource->profile_uri = $oprofile->uri;
  63. $osource->method = $method;
  64. $osource->created = common_sql_now();
  65. if ($osource->insert()) {
  66. return true;
  67. } else {
  68. common_log_db_error($osource, 'INSERT', __FILE__);
  69. return false;
  70. }
  71. }
  72. }