| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | <?php | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  | // This file is part of GNU social - https://www.gnu.org/software/social
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU Affero General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, either version 3 of the License, or
 | 
					
						
							|  |  |  | // (at your option) any later version.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // GNU social is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU Affero General Public License for more details.
 | 
					
						
							|  |  |  | //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU Affero General Public License
 | 
					
						
							|  |  |  | // along with GNU social.  If not, see <http://www.gnu.org/licenses/>.
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | /** | 
					
						
							|  |  |  |  * Store last-touched ID for various timelines | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |  * @category  Data | 
					
						
							|  |  |  |  * @package   GNUsocial | 
					
						
							|  |  |  |  * @author    Evan Prodromou <evan@status.net> | 
					
						
							|  |  |  |  * @copyright 2010 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  | defined('GNUSOCIAL') || die(); | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | require_once INSTALLDIR . '/classes/Memcached_DataObject.php'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /** | 
					
						
							|  |  |  |  * Store various timeline data | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * We don't want to keep re-fetching the same statuses and direct messages from Twitter. | 
					
						
							|  |  |  |  * So, we store the last ID we see from a timeline, and store it. Next time | 
					
						
							|  |  |  |  * around, we use that ID in the since_id parameter. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |  * @category  Action | 
					
						
							|  |  |  |  * @copyright 2010 StatusNet, Inc. | 
					
						
							|  |  |  |  * @license   https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |  * @see       DB_DataObject | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |  */ | 
					
						
							| 
									
										
										
										
											2013-08-18 12:10:44 +02:00
										 |  |  | class Twitter_synch_status extends Managed_DataObject | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | { | 
					
						
							|  |  |  |     public $__table = 'twitter_synch_status'; // table name
 | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |     public $foreign_id;                      // bigint primary_key not_null
 | 
					
						
							| 
									
										
										
										
											2015-02-12 18:18:55 +01:00
										 |  |  |     public $timeline;                        // varchar(191)  primary_key not_null   not 255 because utf8mb4 takes more space
 | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |     public $last_id;                         // bigint not_null
 | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |     public $created;                         // datetime()   not_null
 | 
					
						
							|  |  |  |     public $modified;                        // timestamp()   not_null default_CURRENT_TIMESTAMP
 | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |     public static function schemaDef() | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |         return array( | 
					
						
							|  |  |  |             'fields' => array( | 
					
						
							|  |  |  |                 'foreign_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'Foreign message ID'), | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |                 'timeline' => array('type' => 'varchar', 'length' => 191, 'not null' => true, 'description' => 'timeline name'), | 
					
						
							| 
									
										
										
										
											2013-08-19 17:08:18 +02:00
										 |  |  |                 'last_id' => array('type' => 'int', 'size' => 'big', 'not null' => true, 'description' => 'last id fetched'), | 
					
						
							|  |  |  |                 'created' => array('type' => 'datetime', 'not null' => true, 'description' => 'date this record was created'), | 
					
						
							|  |  |  |                 'modified' => array('type' => 'timestamp', 'not null' => true, 'description' => 'date this record was modified'), | 
					
						
							|  |  |  |             ), | 
					
						
							|  |  |  |             'primary key' => array('foreign_id', 'timeline'), | 
					
						
							|  |  |  |         ); | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |     public static function getLastId($foreign_id, $timeline) | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-09-07 15:29:36 -04:00
										 |  |  |         $tss = self::pkeyGet(array('foreign_id' => $foreign_id, | 
					
						
							|  |  |  |                                    'timeline' => $timeline)); | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($tss)) { | 
					
						
							|  |  |  |             return null; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             return $tss->last_id; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-09-11 12:27:40 +03:00
										 |  |  |     public static function setLastId($foreign_id, $timeline, $last_id) | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2010-09-07 15:29:36 -04:00
										 |  |  |         $tss = self::pkeyGet(array('foreign_id' => $foreign_id, | 
					
						
							|  |  |  |                                    'timeline' => $timeline)); | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (empty($tss)) { | 
					
						
							|  |  |  |             $tss = new Twitter_synch_status(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-07 10:53:11 -04:00
										 |  |  |             $tss->foreign_id = $foreign_id; | 
					
						
							|  |  |  |             $tss->timeline   = $timeline; | 
					
						
							|  |  |  |             $tss->last_id    = $last_id; | 
					
						
							|  |  |  |             $tss->created    = common_sql_now(); | 
					
						
							|  |  |  |             $tss->modified   = $tss->created; | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $tss->insert(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             $orig = clone($tss); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-07 04:32:01 -04:00
										 |  |  |             $tss->last_id  = $last_id; | 
					
						
							|  |  |  |             $tss->modified = common_sql_now(); | 
					
						
							| 
									
										
										
										
											2010-09-07 04:17:36 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |             $tss->update(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |             return true; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |