]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/classes/Ostatus_source.php
Merge branch '0.9.x'
[quix0rs-gnu-social.git] / plugins / OStatus / classes / Ostatus_source.php
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
20 /**
21  * @package OStatusPlugin
22  * @maintainer Brion Vibber <brion@status.net>
23  */
24 class Ostatus_source extends Memcached_DataObject
25 {
26     public $__table = 'ostatus_source';
27
28     public $notice_id; // notice we're referring to
29     public $profile_uri; // uri of the ostatus_profile this came through -- may be a group feed
30     public $method; // push or salmon
31
32     public /*static*/ function staticGet($k, $v=null)
33     {
34         return parent::staticGet(__CLASS__, $k, $v);
35     }
36
37     /**
38      * return table definition for DB_DataObject
39      *
40      * DB_DataObject needs to know something about the table to manipulate
41      * instances. This method provides all the DB_DataObject needs to know.
42      *
43      * @return array array of column definitions
44      */
45     function table()
46     {
47         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
48                      'profile_uri' => DB_DATAOBJECT_STR,
49                      'method' => DB_DATAOBJECT_STR);
50     }
51
52     static function schemaDef()
53     {
54         return array(new ColumnDef('notice_id', 'integer',
55                                    null, false, 'PRI'),
56                      new ColumnDef('profile_uri', 'varchar',
57                                    255, false),
58                      new ColumnDef('method', "ENUM('push','salmon')",
59                                    null, false));
60     }
61
62     /**
63      * return key definitions for DB_DataObject
64      *
65      * DB_DataObject needs to know about keys that the table has; this function
66      * defines them.
67      *
68      * @return array key definitions
69      */
70     function keys()
71     {
72         return array_keys($this->keyTypes());
73     }
74
75     /**
76      * return key definitions for Memcached_DataObject
77      *
78      * Our caching system uses the same key definitions, but uses a different
79      * method to get them.
80      *
81      * @return array key definitions
82      */
83     function keyTypes()
84     {
85         return array('notice_id' => 'K');
86     }
87
88     function sequenceKey()
89     {
90         return array(false, false, false);
91     }
92
93     /**
94      * Save a remote notice source record; this helps indicate how trusted we are.
95      * @param string $method
96      */
97     public static function saveNew(Notice $notice, Ostatus_profile $oprofile, $method)
98     {
99         $osource = new Ostatus_source();
100         $osource->notice_id = $notice->id;
101         $osource->profile_uri = $oprofile->uri;
102         $osource->method = $method;
103         if ($osource->insert()) {
104            return true;
105         } else {
106             common_log_db_error($osource, 'INSERT', __FILE__);
107             return false;
108         }
109     }
110 }