]> git.mxchange.org Git - quix0rs-gnu-social.git/blob - plugins/TwitterBridge/Twitter_synch_status.php
More info for a proper, fancy-url lighttpd setup
[quix0rs-gnu-social.git] / plugins / TwitterBridge / Twitter_synch_status.php
1 <?php
2 /**
3  * Store last-touched ID for various timelines
4  *
5  * PHP version 5
6  *
7  * @category Data
8  * @package  StatusNet
9  * @author   Evan Prodromou <evan@status.net>
10  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
11  * @link     http://status.net/
12  *
13  * StatusNet - the distributed open-source microblogging tool
14  * Copyright (C) 2010, StatusNet, Inc.
15  *
16  * This program is free software: you can redistribute it and/or modify
17  * it under the terms of the GNU Affero General Public License as published by
18  * the Free Software Foundation, either version 3 of the License, or
19  * (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.     See the
24  * GNU Affero General Public License for more details.
25  *
26  * You should have received a copy of the GNU Affero General Public License
27  * along with this program. If not, see <http://www.gnu.org/licenses/>.
28  */
29
30 if (!defined('STATUSNET')) {
31     exit(1);
32 }
33
34 require_once INSTALLDIR . '/classes/Memcached_DataObject.php';
35
36 /**
37  * Store various timeline data
38  *
39  * We don't want to keep re-fetching the same statuses and direct messages from Twitter.
40  * So, we store the last ID we see from a timeline, and store it. Next time
41  * around, we use that ID in the since_id parameter.
42  *
43  * @category Action
44  * @package  StatusNet
45  * @author   Evan Prodromou <evan@status.net>
46  * @license  http://www.fsf.org/licensing/licenses/agpl.html AGPLv3
47  * @link     http://status.net/
48  *
49  * @see      DB_DataObject
50  */
51 class Twitter_synch_status extends Managed_DataObject
52 {
53     public $__table = 'twitter_synch_status'; // table name
54     public $foreign_id;                      // bigint primary_key not_null
55     public $timeline;                        // varchar(255)  primary_key not_null
56     public $last_id;                         // bigint not_null
57     public $created;                         // datetime()   not_null
58     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
59
60     public static function schemaDef()
61     {
62         return array(
63             'fields' => array(
64                 'foreign_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'Foreign message ID'),
65                 'timeline' => array('type' => 'varchar', 'length' => 255, 'description' => 'timeline name'),
66                 'last_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'last id fetched'),
67                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'),
68                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'),
69             ),
70             'primary key' => array('foreign_id', 'timeline'),
71         );
72     }
73
74     static function getLastId($foreign_id, $timeline)
75     {
76         $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
77                                    'timeline' => $timeline));
78
79         if (empty($tss)) {
80             return null;
81         } else {
82             return $tss->last_id;
83         }
84     }
85
86     static function setLastId($foreign_id, $timeline, $last_id)
87     {
88         $tss = self::pkeyGet(array('foreign_id' => $foreign_id,
89                                    'timeline' => $timeline));
90
91         if (empty($tss)) {
92             $tss = new Twitter_synch_status();
93
94             $tss->foreign_id = $foreign_id;
95             $tss->timeline   = $timeline;
96             $tss->last_id    = $last_id;
97             $tss->created    = common_sql_now();
98             $tss->modified   = $tss->created;
99
100             $tss->insert();
101
102             return true;
103         } else {
104             $orig = clone($tss);
105
106             $tss->last_id  = $last_id;
107             $tss->modified = common_sql_now();
108
109             $tss->update();
110
111             return true;
112         }
113     }
114 }