]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/OStatus/classes/Ostatus_source.php
utf8mb4 conversion on database with index adjusts
[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 Managed_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     public $created;
36     public $modified;
37
38     public static function schemaDef()
39     {
40         return array(
41             'fields' => array(
42                 'notice_id' => array('type' => 'int', 'not null' => true, 'description' => 'Notice ID relation'),
43                 'profile_uri' => array('type' => 'varchar', 'not null' => true, 'length' => 191, 'description' => 'Profile URI'),
44                 'method' => array('type' => 'enum("push","salmon")', 'not null' => true, 'description' => 'source method'),
45                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
46                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
47             ),
48             'primary key' => array('notice_id'),
49             'foreign keys' => array(
50                'ostatus_source_notice_id_fkey' => array('notice', array('notice_id' => 'id')),
51                // not in profile table yet 'ostatus_source_profile_uri_fkey' => array('profile', array('profile_uri' => 'uri')),
52             ),
53             'indexes' => array(
54                 'ostatus_source_profile_uri_idx' => array('profile_uri'),
55             ),
56         );
57    }
58
59     /**
60      * Save a remote notice source record; this helps indicate how trusted we are.
61      * @param string $method
62      */
63     public static function saveNew(Notice $notice, Ostatus_profile $oprofile, $method)
64     {
65         $osource = new Ostatus_source();
66         $osource->notice_id = $notice->id;
67         $osource->profile_uri = $oprofile->uri;
68         $osource->method = $method;
69         $osource->created = common_sql_now();
70         if ($osource->insert()) {
71            return true;
72         } else {
73             common_log_db_error($osource, 'INSERT', __FILE__);
74             return false;
75         }
76     }
77 }