]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/classes/Ostatus_source.php
Normalize execution guards on OStatus php files; mostly helps cut down on annoying...
[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 if (!defined('STATUSNET')) {
21     exit(1);
22 }
23
24 /**
25  * @package OStatusPlugin
26  * @maintainer Brion Vibber <brion@status.net>
27  */
28 class Ostatus_source extends Memcached_DataObject
29 {
30     public $__table = 'ostatus_source';
31
32     public $notice_id; // notice we're referring to
33     public $profile_uri; // uri of the ostatus_profile this came through -- may be a group feed
34     public $method; // push or salmon
35
36     public /*static*/ function staticGet($k, $v=null)
37     {
38         return parent::staticGet(__CLASS__, $k, $v);
39     }
40
41     /**
42      * return table definition for DB_DataObject
43      *
44      * DB_DataObject needs to know something about the table to manipulate
45      * instances. This method provides all the DB_DataObject needs to know.
46      *
47      * @return array array of column definitions
48      */
49     function table()
50     {
51         return array('notice_id' => DB_DATAOBJECT_INT + DB_DATAOBJECT_NOTNULL,
52                      'profile_uri' => DB_DATAOBJECT_STR,
53                      'method' => DB_DATAOBJECT_STR);
54     }
55
56     static function schemaDef()
57     {
58         return array(new ColumnDef('notice_id', 'integer',
59                                    null, false, 'PRI'),
60                      new ColumnDef('profile_uri', 'varchar',
61                                    255, false),
62                      new ColumnDef('method', "ENUM('push','salmon')",
63                                    null, false));
64     }
65
66     /**
67      * return key definitions for DB_DataObject
68      *
69      * DB_DataObject needs to know about keys that the table has; this function
70      * defines them.
71      *
72      * @return array key definitions
73      */
74     function keys()
75     {
76         return array_keys($this->keyTypes());
77     }
78
79     /**
80      * return key definitions for Memcached_DataObject
81      *
82      * Our caching system uses the same key definitions, but uses a different
83      * method to get them.
84      *
85      * @return array key definitions
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 }