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